-
Notifications
You must be signed in to change notification settings - Fork 17
/
release.sh
executable file
·96 lines (73 loc) · 2.35 KB
/
release.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
#!/bin/bash
set -e
Red='\e[0;31m'
Green='\e[0;7;32m'
Yellow='\e[0;33m'
Purple='\e[0;35m'
NC='\e[0m' # No Color
current_version=''
bump_revision() {
ver=$current_version
major=$(echo $ver | cut -d. -f1)
minor=$(echo $ver | cut -d. -f2)
revision=$(echo $ver | cut -d. -f3)
meta=$(echo $ver | cut -d- -f4)
next_release="$major.$minor.$revision"
}
start_prompt() {
while [[ ! "${response,,}" =~ ^y|yes|n|no$ ]]; do
read -p "This will create a new release and deploy to production. Continue(y|yes/n|no)?" response
if [[ "${response,,}" =~ ^y|yes$ ]]; then
echo -e "Starting release process..."
echo ""
elif [[ "${response,,}" =~ ^n|no$ ]]; then
echo "Exiting..."
exit 1
fi
done
}
set_changelog() {
if [[ $# -eq 0 ]]; then
release_message="# In this release
$(git log --oneline $current_version..@ --pretty=format:"- %s (%h)" --abbrev-commit | sort)"
echo -e "$release_message"
echo ""
fi
}
version_prompt() {
echo -e "Current released version is:\e[2;7;33m $current_version ${NC}"
echo ""
read -p "$(echo -e "Enter next version number. Ctrl+C to cancel. Enter to Continue. [Detected: ${Green} $next_release ${NC}]: ")" user_entered_version
if [[ ! -z "${user_entered_version// /}" ]]; then
next_release=$user_entered_version
fi
}
check_version_format() {
if [[ $next_release != v* ]]; then
next_release="v$next_release"
fi
if [[ $next_release =~ ^v((([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$ ]]; then
if [[ "$should_continue" == true ]]; then
echo -e "${Yellow}Next release version will be $next_release${NC}"
fi
version_format_ok=true
else
version_format_ok=false
echo -e "${Red}Error: Please make sure version follows semver${NC}"
fi
}
start_prompt
current_version="$(git tag --sort=v:refname | tail -1)"
next_release=''
version_format_ok=false
should_continue=false
set_changelog
bump_revision
version_prompt
check_version_format
if [ "$version_format_ok" = true ]; then
vendor/bin/pest
git release -m"$release_message" -v"$next_release"
echo""
echo "Please check your GitHub actions for more information about the status of the release."
fi