-
Notifications
You must be signed in to change notification settings - Fork 22
/
bumpversion
executable file
·117 lines (96 loc) · 2.49 KB
/
bumpversion
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/sh
# Bump the package version and release it
set -e
# Set defaults and parse arguments
PART=patch
DRY_RUN=
NO_DIRTY_CHECK=
while test $# -gt 0
do
case "$1" in
patch)
PART=patch
shift
;;
minor)
PART=minor
shift
;;
major)
PART=major
shift
;;
--dry-run)
DRY_RUN=true
shift
;;
--no-dirty-check)
NO_DIRTY_CHECK=true
shift
;;
*)
echo "Usage: $0 [major|minor|patch] [--dry-run] [--no-dirty-check]" >&2
exit 1
;;
esac
done
sedi() {
if [ "$(uname)" = "Linux" ]
then
sed -i "$@"
else
sed -i '' "$@"
fi
}
# check if git is dirty
if [ -z $NO_DIRTY_CHECK ]
then
if !(git diff-index --quiet HEAD --)
then
echo "Index is dirty, commit the changes first." >&2
exit 1
fi
if [ "$(git symbolic-ref --short HEAD)" != "master" ]
then
echo "Versions should only be tagged from master." >&2
exit 1
fi
fi
# find current version
OLD_VERSION=$(cat package.yaml | grep -E '^version' | sed -E 's/.+"(.+)"/\1/')
# find new version
case "$PART" in
patch)
NEW_VERSION=$(echo $OLD_VERSION | awk -F . '{print $1 "." $2 "." ($3 + 1)}')
;;
minor)
NEW_VERSION=$(echo $OLD_VERSION | awk -F . '{print $1 "." ($2 + 1) "." 0}')
;;
major)
NEW_VERSION=$(echo $OLD_VERSION | awk -F . '{print ($1 + 1) "." 0 "." 0}')
;;
*)
echo "Invalid PART value." >&2
exit 1
;;
esac
# update changelog
sedi -E '/^## Unreleased changes/{G;a\
## '$NEW_VERSION'
}' ChangeLog.md
# bump version
sedi -E 's/(version: +)"'$OLD_VERSION'"/\1"'$NEW_VERSION'"/g' package.yaml
sedi -E 's/^ "version": "'$OLD_VERSION'"/ "version": "'$NEW_VERSION'"/g' package.json
sedi -E 's/^ "version": "'$OLD_VERSION'"/ "version": "'$NEW_VERSION'"/g' package-lock.json
sedi -E 's/^ "serverless-haskell": "\^'$OLD_VERSION'"/ "serverless-haskell": "^'$NEW_VERSION'"/g' serverless-haskell.hsfiles
sedi -E 's/^- serverless-haskell-'$OLD_VERSION'/- serverless-haskell-'$NEW_VERSION'/g' serverless-haskell.hsfiles
if [ -z $DRY_RUN ]
then
# commit and tag
MESSAGE="Bump version: $OLD_VERSION → $NEW_VERSION"
git commit -a -m "$MESSAGE"
git tag -a -m "$MESSAGE" v$NEW_VERSION
# push the tag then branch
git push --tags
git push
fi