forked from sentriz/gonic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_do_bump_version
executable file
·69 lines (59 loc) · 1.5 KB
/
_do_bump_version
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
#!/usr/bin/env bash
# safety checks
if [[ $# -ne 1 ]]; then
echo "usage: $0 <major|minor|patch>" >&2
exit 1
fi
if [[ "$(git rev-parse --abbrev-ref HEAD)" != 'master' ]]; then
echo "not on the master branch" >&2
exit 1
fi
# get latest and check if clean
git pull
if [[ -n "$(git status --porcelain)" ]]; then
echo "working directory is dirty" >&2
exit 1
fi
# get the current verison from last git tag into array and
# inc the provided part
semver_expression='s/^v([0-9]+)\.([0-9]+)\.([0-9]+).*$/\1 \2 \3/'
version=( $(git describe --tags | sed -E -e "$semver_expression" ) )
case "$1" in
major)
((version[0]++))
version[1]=0
version[2]=0
;;
minor)
((version[1]++))
version[2]=0
;;
patch)
((version[2]++))
;;
*)
echo 'please provide a valid version in increment' >&2
exit 1
esac
new_version="v${version[0]}.${version[1]}.${version[2]}"
# write version to go
mkdir version >/dev/null 2>&1
cat > version/version.go << EOL
// generated by \`_do_bump_version\` script in project root
// $(date)
// DO NOT EDIT
package version
const NAME = "gonic"
const NAME_UPPER = "GONIC"
const NAME_EMBED = "gonicembed"
const VERSION = "$new_version"
EOL
./_do_gen_handler_tests
# create and tag single commit with a change to the version file
git commit --all --file - << EOL
bump to $new_version
generated by \`_do_bump_version\` script in project root
EOL
git tag "$new_version"
echo "commited and tagged"
echo "remember to push tags"