-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathversion.sh
executable file
·78 lines (73 loc) · 2.48 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
# Version should match the following pattern: v<MAJOR_VERSION>.<MINOR_VERSION>.<PATCH_VERSION>rc<RC_VERSION>
CUR_VERSION=$(git describe --tags --abbrev=0)
# SAMPLES
# "v1.0.0rc2"
# "v1.0.0"
# "v0.1.0rc2"
# "v0.1.0"
# "v0.1.1rc2"
# "v0.1.1"
echo "Current version is: ${CUR_VERSION}"
MAJOR_VERSION=$(echo "${CUR_VERSION}" | awk -F'rc' '{print $1}' | awk -F'v' '{print $2}' | awk -F'.' '{print $1}')
MINOR_VERSION=$(echo "${CUR_VERSION}" | awk -F'rc' '{print $1}' | awk -F'v' '{print $2}' | awk -F'.' '{print $2}')
PATCH_VERSION=$(echo "${CUR_VERSION}" | awk -F'rc' '{print $1}' | awk -F'v' '{print $2}' | awk -F'.' '{print $3}')
RC_VERSION=$(echo "${CUR_VERSION}" | awk -F'rc' '{print $2}')
PS3='Please enter your choice: '
options=(
"Added new functionality while breaking the existing code."
"Added new functionality without breaking the existing code."
"Bug fix"
"Stable release")
select opt in "${options[@]}"
do
case $opt in
${options[0]})
if [ $MAJOR_VERSION -ne 0 ] && [ $MINOR_VERSION -eq 0 ] && [ $PATCH_VERSION -eq 0 ] && [ $RC_VERSION ] && [ $RC_VERSION -ne 0 ]
then
RC_VERSION=$((RC_VERSION + 1))
else
MAJOR_VERSION=$((MAJOR_VERSION + 1))
MINOR_VERSION=0
PATCH_VERSION=0
RC_VERSION=1
fi
break
;;
${options[1]})
if [ $MINOR_VERSION -ne 0 ] && [ $PATCH_VERSION -eq 0 ] && [ $RC_VERSION ] && [ $RC_VERSION -ne 0 ]
then
RC_VERSION=$((RC_VERSION + 1))
else
MINOR_VERSION=$((MINOR_VERSION + 1))
PATCH_VERSION=0
RC_VERSION=1
fi
break
;;
${options[2]})
if [ $PATCH_VERSION -ne 0 ] && [ $RC_VERSION ] && [ $RC_VERSION -ne 0 ]
then
RC_VERSION=$((RC_VERSION + 1))
else
PATCH_VERSION=$((PATCH_VERSION + 1))
RC_VERSION=1
fi
break
;;
${options[3]})
if ! [ $RC_VERSION ]
then
echo "Already a stable release." || exit 0
fi
RC_VERSION=0
break
;;
*) echo "Invalid option $REPLY";;
esac
done
if [ -n $RC_VERSION -a $RC_VERSION -ne 0 ]
then
echo "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}rc${RC_VERSION}"
else
echo "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}"
fi