-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate_tag.sh
executable file
·118 lines (98 loc) · 3.16 KB
/
validate_tag.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
#!/usr/bin/env bash
#
# Set of Regular expressions / checks to ensure compliance of git version tags with SODALITE standards
#
# <valid prerelease tag> ::= <version core> "-" <pre-release>
# | <version core> "-" <pre-release> "+" <build>
# | <major release>
#
# <valid release tag> ::= <version core>
# | <version core> "+" <build>
# | <major release>
#
# <major release> ::= "M18Release" | "M24Release" | "M36Release"
#
# <version core> ::= <major> "." <minor> "." <patch>
# Usage:
# $0 [SemVar|SemVarStage|SemVarProd|MajRel|production|staging] <tag>
FUNC=$1
VALUE=$2
# Functions
SemVar() {
if [[ "$VALUE" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$ ]]; then
echo true | tr -d '\n'
else
echo false | tr -d '\n'
fi
}
SemVarStage() {
if [[ "$VALUE" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$ ]]; then
echo true | tr -d '\n'
else
echo false | tr -d '\n'
fi
}
SemVarProd() {
if [[ "$VALUE" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$ ]]; then
echo true | tr -d '\n'
else
echo false | tr -d '\n'
fi
}
MajorRelease() {
if [[ "$VALUE" == "M18Release" ]] || [[ "$VALUE" == "M24Release" ]] || [[ "$VALUE" == "M30Release" ]] || [[ "$VALUE" == "M36Release" ]]; then
echo true | tr -d '\n'
else
echo false | tr -d '\n'
fi
}
Production() {
if [[ "$(SemVarProd)" == true ]] || [[ "$(MajorRelease)" == true ]]; then
echo true | tr -d '\n'
else
echo false | tr -d '\n'
fi
}
Staging() {
if [[ "$(SemVarStage)" == true ]] || [[ "$(MajorRelease)" == true ]]; then
echo true | tr -d '\n'
else
echo false | tr -d '\n'
fi
}
# Help
if [[ $# -gt 2 ]] || [[ $# -lt 2 ]] ||
[[ "$1" != "SemVar" && "$1" != "SemVarStage" && "$1" != "SemVarProd" && "$1" != "MajRel" && "$1" != "production" && "$1" != "staging" ]]; then
echo "Usage: $0 [SemVar|SemVarStage|SemVarProd|MajRel|production|staging] <tag>"
exit 1
fi
# checks compliance with Semantic versioning 2.0.0 (https://semver.org/spec/v2.0.0.html)
if [[ "$FUNC" == "SemVar" ]]; then
SemVar
exit
fi
# checks if tag has pre-release and is compliant with Semantic versioning 2.0.0 (https://semver.org/spec/v2.0.0.html)
if [[ "$FUNC" == "SemVarStage" ]]; then
SemVarStage
exit
fi
# checks if tag does not have pre-release and is compliant with Semantic versioning 2.0.0 (https://semver.org/spec/v2.0.0.html)
if [[ "$FUNC" == "SemVarProd" ]]; then
SemVarProd
exit
fi
# checks if tag in form of major release (M18Release,M24Release,M36Release)
if [[ "$FUNC" == "MajRel" ]]; then
MajorRelease
exit
fi
# checks if tag is ready for production (SemVarProd or MajorRelease)
if [[ "$FUNC" == "production" ]]; then
Production
exit
fi
# checks if tag is ready for staging (SemVarStage or MajorRelease)
if [[ "$FUNC" == "staging" ]]; then
Staging
exit
fi