forked from opencaesar/metrology-vocabularies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitCreateNextVersionTag.sh
executable file
·102 lines (85 loc) · 2.11 KB
/
gitCreateNextVersionTag.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
usage() {
echo "# Usage: $0 [-prefix <version prefix>] [-M|-m|-p]"
echo "# Current git description: $CURRENT"
echo "# -M: update major version to $NEXT_MAJOR"
echo "# -m: update minor version to $NEXT_MINOR"
echo "# -p: update patch version to $NEXT_PATCH"
exit 255
}
if [ -n "$(git status --porcelain)" ]; then
echo "# There are uncommitted changes!"
exit 255
fi
USAGE=0
test $# -eq 1 || USAGE=1
PREFIX=""
while [[ $# -gt 0 ]]; do
case "$1" in
-M)
NEXT_VERSION="NEXT_MAJOR"
shift
;;
-m)
NEXT_VERSION="NEXT_MINOR"
shift
;;
-p)
NEXT_VERSION="NEXT_PATCH"
shift
;;
-prefix)
shift
if [[ $# -eq 0 ]]; then usage; fi
PREFIX="$1"
shift
;;
*)
echo "# Unrecognized option: $1"
USAGE=1
;;
esac
done
GLOB="${PREFIX}[0-9].[0-9].[0-9]*"
CURRENT=$(git describe --match "$GLOB")
if [[ $? -ne 0 ]]; then
echo "Cannot describe git version matching $GLOB"
exit 255
fi
REPOSITORY=$(git rev-parse --abbrev-ref --symbolic-full-name '@{push}' | sed -e 's|^\(.*\)/.*$|\1|')
if [[ $? -ne 0 ]]; then
echo "Cannot get git repository name"
exit 255
fi
MAJOR0=$(echo $CURRENT | sed -e "s/^$PREFIX\([0-9]*\)\.[0-9]*\.[0-9]*.*$/\1/")
MINOR0=$(echo $CURRENT | sed -e "s/^$PREFIX[0-9]*\.\([0-9]*\)\.[0-9]*.*$/\1/")
PATCH0=$(echo $CURRENT | sed -e "s/^$PREFIX[0-9]*\.[0-9]*\.\([0-9]*\).*$/\1/")
MAJOR1=$(( 1 + $MAJOR0 ))
MINOR1=$(( 1 + $MINOR0 ))
PATCH1=$(( 1 + $PATCH0 ))
NEXT_MAJOR="$PREFIX$MAJOR1.0.0"
NEXT_MINOR="$PREFIX$MAJOR0.$MINOR1.0"
NEXT_PATCH="$PREFIX$MAJOR0.$MINOR0.$PATCH1"
if [[ $USAGE -eq 1 ]]; then usage; fi
NEXT=${!NEXT_VERSION}
echo "# Current git description: $CURRENT"
echo -n "# OK to tag and push : $NEXT (y/n) ? "
read -r -e yn
case ${yn:0:1} in
y|Y )
git tag -s -m"$NEXT" "$NEXT"
if [[ $? -ne 0 ]]; then
echo "Cannot create tag: $NEXT"
exit 255
fi
git push $REPOSITORY HEAD tag $NEXT
if [[ $? -ne 0 ]]; then
echo "Cannot push tag: $NEXT to repository $REPOSITORY"
exit 255
fi
;;
*)
echo "# Aborting"
exit 255
;;
esac