-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtag-template.sh
executable file
·121 lines (106 loc) · 2.51 KB
/
tag-template.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
# Check the current folder is a git repository
$(git -C $PWD rev-parse)
if [[ $? != 0 ]]; then
exit 1
fi
# Color formatting
RED="\033[0;31m"
GREEN="\033[0;32m"
BLUE="\033[1;34m"
CYAN="\033[0;36m"
RESET="\033[0m"
REGEX_VERSION="^[0-9]*\.[0-9]*\.[0-9]*$"
# Version section
printf "${CYAN}>>> Version number (MAJOR.Minor.patch)?${RESET}\n"
while :; do
read -e version
# When input type is valid loop break
if [[ $version =~ $REGEX_VERSION ]]; then
break
else
printf "${RED}❌ Version format does not correct.${RESET}\n"
fi
done
# Question section
COMMENT_FLAG=''
printf "\n${CYAN}>>> Do you want add comment for tag (y/n)? ${RESET}"
while true; do
read -e yn
case $yn in
[Yy]*)
COMMENT_FLAG='.'
break
;;
[Nn]*) break ;;
esac
done
# Commit message section
header=""
massage=""
if [ ! -z "$COMMENT_FLAG" ]; then
printf "\n${CYAN}>>> Write a short description about this tag.${RESET}\n"
while :; do
read -e input
if [ -z "$input" ]; then
printf "${RED}❌ Header can not be empty.${RESET}\n"
else
header="$input"
break
fi
done
printf "\n${CYAN}>>> What new 🚀 features have been added (optional)?${RESET}\n"
read -e features
if [ ! -z "$features" ]; then
massage="
🚀 Features
${features}
"
fi
printf "\n${CYAN}>>> Which 🐛 bugs have been fixed (optional)?${RESET}\n"
read -e fixes
if [ ! -z "$fixes" ]; then
massage="${massage}
🐛 Fixes
${fixes}
"
fi
printf "\n${CYAN}>>> What 🧪 tests have been added (optional)?${RESET}\n"
read -e tests
if [ ! -z "$tests" ]; then
massage="${massage}
🧪 Tests
${tests}
"
fi
printf "\n${CYAN}>>> 💭 Other explanations you want to add (optional).${RESET}\n"
read -e others
if [ ! -z "$others" ]; then
massage="${massage}
💭 Others
${others}
"
fi
fi
printf "\n${GREEN}v${version} ${header}\n${massage}\n${RESET}"
massage="${header}
${massage}"
# Git tag
if [ $? == 0 ]; then
if [[ $1 == "-s" ]] || [[ $1 == "sign" ]]; then
if [ ! -z "$COMMENT_FLAG" ]; then
git tag -s "v$version" -m "$massage"
else
git tag -s "v$version"
fi
else
if [ ! -z "$COMMENT_FLAG" ]; then
git tag "v$version" -m "$massage"
else
git tag "v$version"
fi
fi
else
printf "\n${RED}❌ An error occurred. Please try again.${RESET}\n"
exit 1
fi