forked from nativefier/nativefier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchangelog
executable file
·51 lines (42 loc) · 1.3 KB
/
changelog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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\`"