-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.sh
executable file
·80 lines (64 loc) · 1.7 KB
/
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
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env bash
set -e
library=$1
lastVersion=''
lastTag=''
libraryPath=''
gitBranch="$(git symbolic-ref --short -q HEAD 2>/dev/null)" ||
gitBranch="(unnamed branch)" # detached HEAD
gitBranch=${gitBranch##refs/heads/}
gitHash="$(git rev-parse --short HEAD 2>/dev/null)"
if [[ "$library" && "$library" != "." ]]; then
libraryPath="$library/"
fi
function getLastVersion() {
lastTag=`git describe --match "${libraryPath}v[0-9].[0-9].[0-9]" --tags 2> /dev/null` || true
if [[ -z "$lastTag" ]]; then
lastTag="${libraryPath}v0.0.0"
fi
lastTag=${lastTag/"$libraryPath"/""}
lastTag=${lastTag:1}
parts=(${lastTag//./ })
partsPatch=(${parts[2]//-/ })
if [[ ${partsPatch[0]} = "0" ]]; then
patch=${partsPatch[0]} | bc
else
patch=${partsPatch[0]}
fi
major=${parts[0]}
minor=${parts[1]}
lastVersion=$libraryPath"v$major.$minor.$patch"
}
## ini untuk checkout -b dari branch develop
branch=(${gitBranch//-/ })
if [[ "$branch" = "develop" ]]; then
major=0
minor=0
patch="2-develop-$gitHash"
elif [[ "$branch" = "master" ]]; then
getLastVersion
case "$2" in
'current')
printf "%s\n" "$lastVersion"
exit 0;;
'patch')
patch=$((patch + 1))
;;
'minor')
minor=$((minor + 1))
patch=0
;;
'major')
major=$((major + 1))
minor=0
patch=0
;;
*)
printf "%s\n" "$lastVersion"
exit 0
esac
else
printf "%s\n" "You are not in the branch that allowed to release!"
exit 0
fi
printf "%s%s.%s.%s\n" "$libraryPath" "v$major" "$minor" "$patch"