-
Notifications
You must be signed in to change notification settings - Fork 0
/
funcs.sh
executable file
·120 lines (102 loc) · 2.31 KB
/
funcs.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
#
# This is the core functionality taken out so it can be tested
#
# Core funcs.
increment() {
echo $(($1 + 1))
}
clean_string() {
echo "${1}" | tr -d '\n' | tr -d ' '
}
get_major() {
echo "${1}" | cut -d'.' -f1
}
get_minor() {
echo "${1}" | cut -d'.' -f2
}
get_patch() {
if [[ ${1} == *"-"* ]]; then
echo "${1}" | cut -d'.' -f3 | cut -d'-' -f1
else
echo "${1}" | cut -d'.' -f3
fi
}
get_maturity() {
if [[ ${1} == *"-"* ]]; then
echo "${1}" | cut -d'.' -f3 | cut -d'-' -f2
else
echo ""
fi
}
# Docker funcs.
is_tagged_version() {
if [[ $1 =~ refs/tags/v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*) ]]; then
return 0
else
return 1
fi
}
get_docker_tags() {
# Arguments:
# - Name reference for the array
# - Name of the docker image
# - The semver we are using to create the tags
local -n arr=$1 # use nameref to create values
name=$2
semver=$3
major=$(get_major "${semver}")
minor=$(get_minor "${semver}")
patch=$(get_patch "${semver}")
maturity=$(get_maturity "${semver}")
if [ -z ${maturity} ]; then
echo "Detected Version: ${major} . ${minor} . ${patch}"
full_tag="${name}:${major}.${minor}.${patch}"
minor_tag="${name}:${major}.${minor}"
major_tag="${name}:${major}"
else
echo "Detected Version: ${major} . ${minor} . ${patch} [${maturity}]"
full_tag="${name}:${major}.${minor}.${patch}-${maturity}"
minor_tag="${name}:${major}.${minor}-${maturity}"
major_tag="${name}:${major}-${maturity}"
fi
arr=($full_tag $minor_tag $major_tag)
}
# Auto-tag funcs.
is_valid_tag_name() {
if [[ $1 =~ v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*) ]]; then
return 0
else
return 1
fi
}
is_selected() {
body=$1
phrase=$2
if [ $(echo "${body}" | grep -c "\[x\] ${phrase}") -gt 0 ]; then
echo true
else
echo false
fi
}
is_patch_selected() {
local phrase=Patch
is_selected "$1" "${phrase}"
}
is_minor_selected() {
local phrase="Minor version"
is_selected "$1" "${phrase}"
}
is_major_selected() {
local phrase="Major version"
is_selected "$1" "${phrase}"
}
is_skip_selected() {
local phrase="Skip auto-tagging"
is_selected "$1" "${phrase}"
}
get_latest_tag() {
git fetch --prune --unshallow --tags --force # This is needed - without it no tags are found.
maybe_latest_tag=$(git tag --list 'v*' --sort=-v:refname | head -n1)
latest_tag=${maybe_latest_tag:-0.0.0}
echo "${latest_tag}"
}