-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
bump_version.sh
executable file
·70 lines (63 loc) · 1.37 KB
/
bump_version.sh
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
#!/bin/sh
# Don't run on any branch other than `master`.
if [ `git symbolic-ref --short HEAD` != "master" ]; then
printf "ERROR: only run on master branch!\n" 1>&2
exit 3
fi
usage() {
printf "Usage: ./bump_version.sh [-p|-m|-M]\n" 1>&2
printf " -p bump patch (e.g., 1.1.4 -> 1.1.5)\n" 1>&2
printf " -m bump minor (e.g., 1.1.4 -> 1.2.0)\n" 1>&2
printf " -M bump major (e.g., 1.1.4 -> 2.0.0)\n" 1>&2
}
# Parse options.
p=""
m=""
M=""
while getopts 'hpmM' 'OPTION'; do
case "$OPTION" in
h)
usage
exit 0
;;
p)
p="true"
;;
m)
m="true"
;;
M)
M="true"
;;
?)
usage
exit 1
;;
esac
done
shift "$(($OPTIND -1))"
# Get most recent tag, in parts/
read -r major minor patch <<<`git describe --abbrev=0 | tr '.' ' '`;
# Bump.
if [ "$M" == "true" ]; then
major=`expr $major + 1`
minor="0"
patch="0"
else
if [ "$m" == "true" ]; then
minor=`expr $minor + 1`
patch="0"
else
if [ "$p" == "true" ]; then
patch=`expr $patch + 1`
else
usage
exit 2
fi
fi
fi
new_version="$major.$minor.$patch"
printf "\nWriting git annotated tag at version: $new_version\n\n"
git tag -a "$new_version" -m "$new_version"
printf "Don't forget to push tags by adding --follow-tags to your push command, like:\n\n"
printf " git push origin master --follow-tags\n\n"