From a6d8ff8d6a5f697e17fb11e423f0dd1760ed699d Mon Sep 17 00:00:00 2001 From: Jia Hao Goh Date: Sun, 30 Apr 2017 02:39:08 +0800 Subject: [PATCH] Add script to update version and changelog --- docs/release.md | 35 +++++++++++++++++++------------- package.json | 2 +- scripts/changelog | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 15 deletions(-) create mode 100755 scripts/changelog diff --git a/docs/release.md b/docs/release.md index 6ce7111..278daef 100644 --- a/docs/release.md +++ b/docs/release.md @@ -1,27 +1,34 @@ -# Release Notes +# Release -How to release a new version to NPM +Releases are automatically deployed to NPM on Travis, when they are tagged. However, we have to make sure that the version in the `package.json`, and the changelog is updated. -## Releasing +## Dependencies +- [Git Extras](https://github.com/tj/git-extras/blob/master/Installation.md) -Run the following command to get the changelog +## How to Release `$VERSION` +While on `master`, with no uncommitted changes, + +```bash +npm run changelog -- $VERSION ``` -git checkout master -# Get the current version -npm version +This command does 3 things: +1. Update the version in the `package.json` +2. Update the changelog +3. Creates a new commit with the changes -# Add the changelog for the next version -git changelog docs/changelog.md --tag +Now we may want to cleanup the changelog: -# Edit the changelog +```bash vim docs/changelog.md -# Commit it -git add docs/changelog.md -git commit -m "Update changelog for \`v\`" -git push +git commit --amend +``` + +Once we are satisfied, +```bash +git push origin master ``` On [GitHub Releases](https://github.com/jiahaog/nativefier/releases), draft and publish a new release with title `Nativefier vX.X.X`. diff --git a/package.json b/package.json index 04b7f0d..a826629 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "watch": "while true ; do gulp watch ; done", "package-placeholder": "npm run build && node lib/cli.js http://www.bennish.net/web-notifications.html ~/Desktop --overwrite --name notification-test --icon ./test-resources/iconSampleGrey.png --inject ./test-resources/test-injection.js --inject ./test-resources/test-injection.css && open ~/Desktop/notification-test-darwin-x64/notification-test.app", "start-placeholder": "npm run build && electron app", - "release": "gulp release" + "changelog": "./scripts/changelog" }, "bin": { "nativefier": "lib/cli.js" diff --git a/scripts/changelog b/scripts/changelog new file mode 100755 index 0000000..917fecc --- /dev/null +++ b/scripts/changelog @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# +# Updates the changelog and version in the package.json +# Will also create a commit with these changes locally +# Run `git commit --amend` after that if you wish to make changes +# +# Usage: +# ./changelog "7.0.0" +# +# Prerequisites: +# - On master branch +# - No uncommitted changes +# +# Dependencies: +# - git-extras https://github.com/tj/git-extras/blob/master/Installation.md + +set -eo pipefail + +# Checks if we are on the master branch +BRANCH=$(git rev-parse --abbrev-ref HEAD) +if [[ "$BRANCH" != 'master' ]]; then + echo 'ERROR: not on master branch' >&2 + exit 1; +fi + +# Checks if there are uncommitted changes +git diff-index --quiet HEAD -- || (echo 'ERROR: there are uncommitted changes' >&2 && exit 1) + +VERSION="$1" + +# Validates the $VERSION +SEMVER_REGEX='^([0-9]+\.){2}([0-9]+)$' +if ! [[ $VERSION =~ $SEMVER_REGEX ]]; then + echo "ERROR: Version '$VERSION' is invalid " >&2 + exit 1 +fi + +# Change the version in the package.json +cat package.json | jq ".version = \"$VERSION\"" > package.json.tmp + +# Workaround for inplace jq editing +mv package.json.tmp package.json + +# Unset the editor so that git changelog does not open a editor +EDITOR=: +git changelog docs/changelog.md --tag \"$VERSION\" + +# Commit these changes +git add docs/changelog.md +git add package.json +git commit -m "Update changelog for \`v$VERSION\`"