Skip to content

Commit e48889e

Browse files
authored
bugfix/patch release script (#44)
1 parent df4fb97 commit e48889e

File tree

4 files changed

+245
-5
lines changed

4 files changed

+245
-5
lines changed

release/README.adoc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,45 @@ images-repo: docker-images
199199
- commons
200200
- ...
201201
----
202+
203+
### Bugfix/patch tags
204+
205+
To create release tags for bugfix/patch releases use the `create-bugfix-tag.sh` script, called from the repository root folder. The syntax is given below:
206+
207+
[source]
208+
----
209+
./release/create-bugfix-tag.sh -t <release-tag> [-p] [-c] [-w products|operators|both]
210+
----
211+
212+
- `-t <release-tag>`: the release tag (mandatory). This must be a semver-compatible value (i.e. major/minor/path, without leading zeros) such as `23.1.0`, `23.10.3` etc. and will be used to create a tag with the name
213+
- `-p`: push flag (optional, default is "false"). If provided, the created commits and tags made as part of this process will be pushed to the origin.
214+
- `-c`: cleanup flag (optional, default is "false"). If provided, the repository folders will be torn down on completion.
215+
- `-w`: where to create the tag and update versions in code. It can be "products", "operators", "both".
216+
217+
N.B. the flags cannot be combined (e.g. `-p -c` but not `-pc)
218+
219+
e.g.
220+
221+
[source]
222+
----
223+
./release/create-bugfix-tag.sh -t 23.1.0 -p -c -w both
224+
----
225+
226+
#### What this script does
227+
228+
* checks that the release argument is valid (e.g. semver-compatible, major/minor/patch levels)
229+
* strips this argument of any leading or trailing quote marks
230+
* for docker images
231+
** creates a temporary folder with clones of the images repository (given in `config.yaml`)
232+
** clones the docker images repository
233+
** checks that the release branch exists and the tag doesn't
234+
** switches to the release branch
235+
** tags the branch and pushes it if the push argument is provided
236+
** deletes the temporary folder (if requested with "-c")
237+
* for operators:
238+
** iterates over a list of operator repository names (listed in `config.yaml`), and for each one:
239+
** clones the operator repositories
240+
** checks that the release branch exists and the tag doesn't
241+
** switches to the release branch
242+
** tags the branch and pushes it if the push argument is provided
243+
** deletes the temporary folder (if requested with "-c")

release/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ operators:
1111
- listener-operator
1212
- nifi-operator
1313
- opa-operator
14-
- trino-operator
1514
- secret-operator
1615
- spark-k8s-operator
1716
- superset-operator
17+
- trino-operator
1818
- zookeeper-operator

release/create-bugfix-tag.sh

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
#!/usr/bin/env bash
2+
#
3+
# See README.adoc
4+
#
5+
set -euo pipefail
6+
set -x
7+
#-----------------------------------------------------------
8+
# tags should be semver-compatible e.g. 23.1.1 not 23.01.1
9+
# this is needed for cargo commands to work properly
10+
#-----------------------------------------------------------
11+
TAG_REGEX="^[0-9][0-9]\.([1-9]|[1][0-2])\.[0-9]+$"
12+
REPOSITORY="origin"
13+
14+
tag_products() {
15+
cd "$TEMP_RELEASE_FOLDER/$DOCKER_IMAGES_REPO"
16+
git switch "$RELEASE_BRANCH"
17+
git tag "$RELEASE_TAG"
18+
push_branch
19+
}
20+
21+
tag_operators() {
22+
while IFS="" read -r operator || [ -n "$operator" ]
23+
do
24+
cd "${TEMP_RELEASE_FOLDER}/${operator}"
25+
git switch "$RELEASE_BRANCH"
26+
27+
# Update git submodules if needed
28+
if [ -f .gitmodules ]; then
29+
git submodule update --recursive --init
30+
fi
31+
32+
git tag "$RELEASE_TAG"
33+
push_branch
34+
done < <(yq '... comments="" | .operators[] ' "$INITIAL_DIR"/release/config.yaml)
35+
}
36+
37+
tag_repos() {
38+
if [ "products" == "$WHAT" ] || [ "both" == "$WHAT" ]; then
39+
tag_products
40+
fi
41+
if [ "operators" == "$WHAT" ] || [ "both" == "$WHAT" ]; then
42+
tag_operators
43+
fi
44+
}
45+
46+
check_products() {
47+
#-------------------------------------------------------------
48+
# $TEMP_RELEASE_FOLDER has been created in the calling routine
49+
#-------------------------------------------------------------
50+
git clone "git@github.com:stackabletech/${DOCKER_IMAGES_REPO}.git" "$TEMP_RELEASE_FOLDER/$DOCKER_IMAGES_REPO"
51+
cd "$TEMP_RELEASE_FOLDER/$DOCKER_IMAGES_REPO"
52+
#---------------------------------------
53+
# switch to the release branch
54+
# N.B. look for exact match
55+
#---------------------------------------
56+
BRANCH_EXISTS=$(git branch -r | grep -E "$RELEASE_BRANCH$")
57+
58+
if [ -z "${BRANCH_EXISTS}" ]; then
59+
echo "Expected release branch is missing: $RELEASE_BRANCH"
60+
exit 1
61+
fi
62+
63+
git switch "${RELEASE_BRANCH}"
64+
git fetch --tags
65+
#---------------------------------------
66+
# check tags: N.B. look for exact match
67+
#---------------------------------------
68+
TAG_EXISTS=$(git tag -l | grep -E "$RELEASE_TAG$")
69+
if [ -n "$TAG_EXISTS" ]; then
70+
echo "Tag $RELEASE_TAG already exists in $DOCKER_IMAGES_REPO"
71+
exit 1
72+
fi
73+
}
74+
75+
check_operators() {
76+
#-------------------------------------------------------------
77+
# $TEMP_RELEASE_FOLDER has been created in the calling routine
78+
#-------------------------------------------------------------
79+
while IFS="" read -r operator || [ -n "$operator" ]
80+
do
81+
echo "Operator: $operator"
82+
git clone "git@github.com:stackabletech/${operator}.git" "$TEMP_RELEASE_FOLDER/${operator}"
83+
cd "$TEMP_RELEASE_FOLDER/${operator}"
84+
85+
BRANCH_EXISTS=$(git branch -r | grep -E "$RELEASE_BRANCH$")
86+
87+
if [ -z "${BRANCH_EXISTS}" ]; then
88+
echo "Expected release branch is missing: ${operator}/$RELEASE_BRANCH"
89+
exit 1
90+
fi
91+
git switch "${RELEASE_BRANCH}"
92+
93+
git fetch --tags
94+
TAG_EXISTS=$(git tag -l | grep -E "$RELEASE_TAG$")
95+
if [ -n "${TAG_EXISTS}" ]; then
96+
echo "Tag $RELEASE_TAG already exists in ${operator}"
97+
exit 1
98+
fi
99+
done < <(yq '... comments="" | .operators[] ' "$INITIAL_DIR"/release/config.yaml)
100+
}
101+
102+
checks() {
103+
if [ "products" == "$WHAT" ] || [ "both" == "$WHAT" ]; then
104+
check_products
105+
fi
106+
if [ "operators" == "$WHAT" ] || [ "both" == "$WHAT" ]; then
107+
check_operators
108+
fi
109+
}
110+
111+
112+
push_branch() {
113+
if $PUSH; then
114+
echo "Pushing changes..."
115+
git push "${REPOSITORY}" "${RELEASE_BRANCH}"
116+
git push "${REPOSITORY}" "${RELEASE_TAG}"
117+
git switch main
118+
else
119+
echo "(Dry-run: not pushing...)"
120+
fi
121+
}
122+
123+
cleanup() {
124+
if $CLEANUP; then
125+
echo "Cleaning up..."
126+
rm -rf "$TEMP_RELEASE_FOLDER"
127+
fi
128+
}
129+
130+
parse_inputs() {
131+
RELEASE_TAG=""
132+
PUSH=false
133+
CLEANUP=false
134+
WHAT=""
135+
136+
while [[ "$#" -gt 0 ]]; do
137+
case $1 in
138+
-t|--tag) RELEASE_TAG="$2"; shift ;;
139+
-w|--what) WHAT="$2"; shift ;;
140+
-p|--push) PUSH=true ;;
141+
-c|--cleanup) CLEANUP=true ;;
142+
*) echo "Unknown parameter passed: $1"; exit 1 ;;
143+
esac
144+
shift
145+
done
146+
#-----------------------------------------------------------
147+
# remove leading and trailing quotes
148+
#-----------------------------------------------------------
149+
RELEASE_TAG="${RELEASE_TAG%\"}"
150+
RELEASE_TAG="${RELEASE_TAG#\"}"
151+
#----------------------------------------------------------------------------------------------------
152+
# for a tag of e.g. 23.1.1, the release branch (already created) will be 23.1
153+
#----------------------------------------------------------------------------------------------------
154+
RELEASE="$(cut -d'.' -f1,2 <<< "$RELEASE_TAG")"
155+
RELEASE_BRANCH="release-$RELEASE"
156+
157+
INITIAL_DIR="$PWD"
158+
DOCKER_IMAGES_REPO=$(yq '... comments="" | .images-repo ' "$INITIAL_DIR"/release/config.yaml)
159+
TEMP_RELEASE_FOLDER="/tmp/stackable-$RELEASE_BRANCH"
160+
161+
echo "Settings: ${RELEASE_BRANCH}: Push: $PUSH: Cleanup: $CLEANUP"
162+
}
163+
164+
main() {
165+
parse_inputs "$@"
166+
#-----------------------------------------------------------
167+
# check if tag argument provided
168+
#-----------------------------------------------------------
169+
if [ -z "${RELEASE_TAG}" ]; then
170+
echo "Usage: create-release-tag.sh -t <tag>"
171+
exit 1
172+
fi
173+
#-----------------------------------------------------------
174+
# check if argument matches our tag regex
175+
#-----------------------------------------------------------
176+
if [[ ! $RELEASE_TAG =~ $TAG_REGEX ]]; then
177+
echo "Provided tag [$RELEASE_TAG] does not match the required tag regex pattern [$TAG_REGEX]"
178+
exit 1
179+
fi
180+
181+
if [ -d "$TEMP_RELEASE_FOLDER" ]; then
182+
echo "Folder already exists, please delete it!: $TEMP_RELEASE_FOLDER"
183+
exit 1
184+
fi
185+
186+
echo "Creating folder for cloning docker images and operators: [$TEMP_RELEASE_FOLDER]"
187+
mkdir -p "$TEMP_RELEASE_FOLDER"
188+
189+
# sanity checks before we start: folder, branches etc.
190+
# deactivate -e so that piped commands can be used
191+
set +e
192+
checks
193+
set -e
194+
195+
tag_repos
196+
cleanup
197+
}
198+
199+
main "$@"

release/create-release-tag.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ check_products() {
8585

8686
git fetch --tags
8787

88-
# N.B. look for exact match (no -rcXXX)
89-
TAG_EXISTS=$(git tag -l | grep -E "$RELEASE_TAG&")
88+
TAG_EXISTS=$(git tag -l | grep -E "$RELEASE_TAG$")
9089
if [ -n "$TAG_EXISTS" ]; then
9190
echo "Tag $RELEASE_TAG already exists in $DOCKER_IMAGES_REPO"
9291
exit 1
@@ -102,13 +101,13 @@ check_operators() {
102101
exit 1
103102
fi
104103
cd "$TEMP_RELEASE_FOLDER/${operator}"
105-
BRANCH_EXISTS=$(git branch -r | grep "$RELEASE_BRANCH")
104+
BRANCH_EXISTS=$(git branch -r | grep -E "$RELEASE_BRANCH$")
106105
if [ -z "${BRANCH_EXISTS}" ]; then
107106
echo "Expected release branch is missing: ${operator}/$RELEASE_BRANCH"
108107
exit 1
109108
fi
110109
git fetch --tags
111-
TAG_EXISTS=$(git tag | grep "$RELEASE_TAG")
110+
TAG_EXISTS=$(git tag -l | grep -E "$RELEASE_TAG$")
112111
if [ -n "${TAG_EXISTS}" ]; then
113112
echo "Tag $RELEASE_TAG already exists in ${operator}"
114113
exit 1

0 commit comments

Comments
 (0)