-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
entrypoint.sh
executable file
·93 lines (81 loc) · 2.37 KB
/
entrypoint.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
#!/bin/bash -l
# active bash options:
# - stops the execution of the shell script whenever there are any errors from a command or pipeline (-e)
# - option to treat unset variables as an error and exit immediately (-u)
# - print each command before executing it (-x)
# - sets the exit code of a pipeline to that of the rightmost command
# to exit with a non-zero status, or to zero if all commands of the
# pipeline exit successfully (-o pipefail)
set -euo pipefail
main() {
prev_version="$1"; release_type="$2"
if [[ "$prev_version" == "" ]]; then
echo "could not read previous version"; exit 1
fi
possible_release_types="major feature bug alpha beta rc"
if [[ ! ${possible_release_types[*]} =~ ${release_type} ]]; then
echo "valid argument: [ ${possible_release_types[*]} ]"; exit 1
fi
major=0; minor=0; patch=0; pre=""; preversion=0
# break down the version number into it's components
regex="^([0-9]+).([0-9]+).([0-9]+)((-[a-z]+)([0-9]+))?$"
if [[ $prev_version =~ $regex ]]; then
major="${BASH_REMATCH[1]}"
minor="${BASH_REMATCH[2]}"
patch="${BASH_REMATCH[3]}"
pre="${BASH_REMATCH[5]}"
preversion="${BASH_REMATCH[6]}"
else
echo "previous version '$prev_version' is not a semantic version"
exit 1
fi
# increment version number based on given release type
case "$release_type" in
"major")
((++major)); minor=0; patch=0; pre="";;
"feature")
((++minor)); patch=0; pre="";;
"bug")
((++patch)); pre="";;
"alpha")
if [[ -z "$preversion" ]];
then
preversion=0
else
if [[ "$pre" != "-alpha" ]];
then
preversion=1
else ((++preversion))
fi
fi
pre="-alpha$preversion";;
"beta")
if [[ -z "$preversion" ]];
then
preversion=0
else
if [[ "$pre" != "-beta" ]];
then
preversion=1
else ((++preversion))
fi
fi
pre="-beta$preversion";;
"rc")
if [[ -z "$preversion" ]];
then
preversion=0
else
if [[ "$pre" != "-rc" ]];
then
preversion=1
else ((++preversion))
fi
fi
pre="-rc$preversion";;
esac
next_version="${major}.${minor}.${patch}${pre}"
echo "create $release_type-release version: $prev_version -> $next_version"
echo "next-version=$next_version" >> $GITHUB_OUTPUT
}
main "$1" "$2"