-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
entrypoint.sh
executable file
·71 lines (59 loc) · 2.12 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
#!/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 minor bug patch hotfix alpha beta pre rc stable)
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 its components
regex="^v?([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[7]}"
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")
((++minor)); patch=0; pre="";;
"bug"|"patch"|"hotfix")
((++patch)); pre="";;
"alpha"|"beta"|"pre"|"rc")
if [[ -z "$pre" ]]; then
# Increment patch if transitioning from stable to pre-release
((++patch))
preversion=0
elif [[ "$pre" != "$release_type" ]]; then
preversion=1
else
((++preversion))
fi
pre="-$release_type.$preversion";;
"stable")
# Remove pre-release tag
pre=""; preversion=0;;
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"