-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit-tag.sh
executable file
·89 lines (76 loc) · 1.86 KB
/
git-tag.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
#!/bin/sh
validate() {
validation=$(echo "$1" | grep -oE '^v?([0-9]+)\.([0-9]+)\.([0-9]+)$')
if [ -z "$validation" ]
then
echo "Warning! Latest tag \"$1\" invalid format: expected vX.X.X or X.X.X"
printf "Enter your next tag manually: "
read -r manual_tag
git_tag "$manual_tag"
exit 0
fi
}
select_menu() {
while true
do
echo "1) $major - major"
echo "2) $minor - minor"
echo "3) $bugfix - bugfix"
printf "Choose tag to apply: "
read -r choice
if [ "$choice" = "1" ]
then
tag=$major
break
fi
if [ "$choice" = "2" ]
then
tag=$minor
break
fi
if [ "$choice" = "3" ]
then
tag=$bugfix
break
fi
done
}
ask_v_versioning() {
echo "Latest tagged version: $tag"
printf "Would you like to add a \"v\" prefix to your next version tag? (y/N) "
read -r answer
if [ "$answer" = "y" ]
then
v="v"
fi
}
git_tag() {
printf "Describe your tag: "
read -r tag_description
if [ "$tag_description" = "" ]
then
tag_description="$1"
fi
git tag -a "$1" -m "$tag_description" && echo "Done! Tag successfuly applied"
}
tag=$(git describe --abbrev=0 --tags 2>/dev/null || echo v0.0.0)
validate "$tag"
v=""
if [ "$(echo "$tag" | cut -c -1)" = "v" ]
then
tag=$(echo "$tag" | cut -c2-)
v="v"
else
ask_v_versioning
fi
# The only way to be sh cross platform between MacOS, Linux...etc
# a.b.c represents a tag version e.g: "1.0.2"
remainder="$tag"
a="${remainder%%.*}"; remainder="${remainder#*.}"
b="${remainder%%.*}"; remainder="${remainder#*.}"
c="${remainder%%.*}"; remainder="${remainder#*.}"
major="$v$((a+1)).0.0"
minor="$v$a.$((b+1)).0"
bugfix="$v$a.$b.$((c+1))"
select_menu
git_tag "$tag"