-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion.sh
More file actions
executable file
·67 lines (53 loc) · 1.04 KB
/
version.sh
File metadata and controls
executable file
·67 lines (53 loc) · 1.04 KB
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
#!/usr/bin/env bash
function help {
echo
echo " Usage:"
echo
echo " ./version.sh <major|minor|patch>"
echo
echo " Repository must be clean"
echo
exit
}
function join {
local IFS="$1"; shift; echo "$*"
}
function bump {
local IFS="."
local semver="$1"
local verkey=""
read -ra version <<< "$(git describe --abbrev=0 --tags)"
case $semver in
major)
verkey=0
;;
minor)
verkey=1
;;
patch)
verkey=2
;;
*)
verkey=""
;;
esac
if [ -z "$verkey" ]; then
echo $verkey
exit
fi
next=$((${version[$verkey]} + 1))
version[$verkey]=$next
i=$(($verkey + 1))
while [ $i -lt 3 ]; do
version[$i]=0
i=$(($i + 1))
done
updated=$(join . "${version[@]}")
echo "$updated"
}
version=$(bump $1)
test -z "$(git status --porcelain)" || help
test -z "$version" && help
git tag -a "$version" -m "v$version"
echo "$version"
git push origin master --tags