Skip to content

Commit d0bfbb2

Browse files
committed
feat(release): Update create-release-candidate-branch.sh to use new common functions
1 parent 0ed623c commit d0bfbb2

1 file changed

Lines changed: 48 additions & 48 deletions

File tree

release/create-release-candidate-branch.sh

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
#!/usr/bin/env bash
22
#
3-
# See README.adoc
3+
# See README.md
44
#
55
set -euo pipefail
66
# set -x
77

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-
# optional release-candidate suffixes are in the form:
11-
# - rc-1, e.g. 23.1.1-rc1, 23.12.1-rc12 etc.
12-
TAG_REGEX="^[0-9][0-9]\.([1-9]|[1][0-2])\.[0-9]+(-rc[0-9]+)?$"
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
source "$SCRIPT_DIR/common.sh"
10+
1311
REMOTE="origin"
1412
PR_MSG="> [!CAUTION]
1513
> ## DO NOT MERGE MANUALLY!
@@ -18,19 +16,27 @@ PR_MSG="> [!CAUTION]
1816
rc_branch_products() {
1917
# assume that the branch exists and has either been pushed or has been created locally
2018
cd "$TEMP_RELEASE_FOLDER/$DOCKER_IMAGES_REPO"
19+
assert_cwd_is_repo "$DOCKER_IMAGES_REPO"
20+
assert_clean_index "$DOCKER_IMAGES_REPO"
2121

2222
# the PR branch should already exist
2323
git switch "$PR_BRANCH"
24+
assert_on_branch "$PR_BRANCH"
2425
update_product_images_changelogs
25-
26+
assert_on_branch "$PR_BRANCH"
2627
git commit -sam "chore: Release $RELEASE_TAG"
28+
assert_clean_index "$DOCKER_IMAGES_REPO"
29+
assert_remote_exists "$REMOTE" "$DOCKER_IMAGES_REPO"
2730
push_branch
2831
}
2932

3033
rc_branch_operators() {
3134
while IFS="" read -r operator || [ -n "$operator" ]; do
3235
cd "${TEMP_RELEASE_FOLDER}/${operator}"
36+
assert_cwd_is_repo "$operator"
37+
assert_clean_index "$operator"
3338
git switch "$PR_BRANCH"
39+
assert_on_branch "$PR_BRANCH"
3440

3541
# Update git submodules if needed
3642
if [ -f .gitmodules ]; then
@@ -53,18 +59,23 @@ rc_branch_operators() {
5359
# inserts a single line with tag and date
5460
update_changelog "$TEMP_RELEASE_FOLDER/${operator}"
5561

62+
assert_on_branch "$PR_BRANCH"
5663
git commit -sam "chore: Release $RELEASE_TAG"
64+
assert_clean_index "$operator"
65+
assert_remote_exists "$REMOTE" "$operator"
5766
push_branch
5867
done < <(yq '... comments="" | .operators[] ' "$INITIAL_DIR"/release/config.yaml)
5968
}
6069

6170
rc_branch_repos() {
62-
if [ "products" == "$WHAT" ] || [ "all" == "$WHAT" ]; then
63-
rc_branch_products
64-
fi
65-
if [ "operators" == "$WHAT" ] || [ "all" == "$WHAT" ]; then
66-
rc_branch_operators
67-
fi
71+
case "$WHAT" in
72+
products) rc_branch_products ;;
73+
operators) rc_branch_operators ;;
74+
all)
75+
rc_branch_products
76+
rc_branch_operators
77+
;;
78+
esac
6879
}
6980

7081
check_tag_is_valid() {
@@ -96,10 +107,13 @@ check_products() {
96107
git clone "git@github.com:stackabletech/${DOCKER_IMAGES_REPO}.git" "$TEMP_RELEASE_FOLDER/$DOCKER_IMAGES_REPO"
97108
fi
98109
cd "$TEMP_RELEASE_FOLDER/$DOCKER_IMAGES_REPO"
110+
assert_cwd_is_repo "$DOCKER_IMAGES_REPO"
111+
assert_clean_index "$DOCKER_IMAGES_REPO"
99112

100113
# Need to update here because if we deleted the local state, or someone else continues
101-
# we might be back on main, or on the release branch without having pulled updates from fixes.
114+
# we might be back on main, or on the release branch without having pulled updates from fixes.
102115
git fetch && git switch "$RELEASE_BRANCH" && git pull
116+
assert_on_branch "$RELEASE_BRANCH"
103117

104118
# switch to the release branch, which should exist as tagging
105119
# is subsequent to creating the branch.
@@ -121,6 +135,7 @@ check_products() {
121135

122136
# create a new branch for the PR off of this
123137
git switch -c "$PR_BRANCH" "$RELEASE_BRANCH"
138+
assert_on_branch "$PR_BRANCH"
124139

125140
check_tag_is_valid
126141
}
@@ -137,10 +152,13 @@ check_operators() {
137152

138153
fi
139154
cd "$TEMP_RELEASE_FOLDER/${operator}"
155+
assert_cwd_is_repo "$operator"
156+
assert_clean_index "$operator"
140157

141158
# Need to update here because if we deleted the local state, or someone else continues
142159
# we might be back on main, or on the release branch without having pulled updates from fixes.
143160
git fetch && git switch "$RELEASE_BRANCH" && git pull
161+
assert_on_branch "$RELEASE_BRANCH"
144162
# Note, if this needs to check the branch exists locally, then use:
145163
# "^[ *]*$RELEASE_BRANCH\$"
146164
if ! git branch -a | grep -E "$RELEASE_BRANCH\$"; then
@@ -159,18 +177,21 @@ check_operators() {
159177

160178
# create a new branch for the PR off of this
161179
git switch -c "$PR_BRANCH" "$RELEASE_BRANCH"
180+
assert_on_branch "$PR_BRANCH"
162181

163182
check_tag_is_valid
164183
done < <(yq '... comments="" | .operators[] ' "$INITIAL_DIR"/release/config.yaml)
165184
}
166185

167186
checks() {
168-
if [ "products" == "$WHAT" ] || [ "all" == "$WHAT" ]; then
169-
check_products
170-
fi
171-
if [ "operators" == "$WHAT" ] || [ "all" == "$WHAT" ]; then
172-
check_operators
173-
fi
187+
case "$WHAT" in
188+
products) check_products ;;
189+
operators) check_operators ;;
190+
all)
191+
check_products
192+
check_operators
193+
;;
194+
esac
174195
}
175196

176197
update_code() {
@@ -293,52 +314,31 @@ parse_inputs() {
293314
}
294315

295316
check_dependencies() {
296-
# check for a globally configured git user
297-
if ! git_user=$(git config --global --includes --get user.name) \
298-
|| ! git_email=$(git config --global --includes --get user.email); then
299-
>&2 echo "Error: global git user name/email is not set."
300-
exit 1
301-
else
302-
echo "global git user: $git_user <$git_email>"
303-
echo "Is this correct? (y/n)"
304-
read -r response
305-
if [[ "$response" == "y" || "$response" == "Y" ]]; then
306-
echo "Proceeding with $git_user <$git_email>"
307-
else
308-
>&2 echo "User not accepted. Exiting."
309-
exit 1
310-
fi
311-
fi
317+
check_common_dependencies
312318

313-
# check gh authentication: if this fails you will need to e.g. gh auth login
314-
gh auth status
315-
yq --version
319+
# Additional dependencies for operator RC branch creation
316320
python --version
317321
cargo --version
318322
cargo set-version --version
319-
# check for jinja2-cli including pyyaml package
323+
# jinja2-cli including pyyaml package (for docs templating)
320324
jinja2 --version
321325
python -m pip show pyyaml
322326
}
323327

324328
main() {
325329
parse_inputs "$@"
326330

327-
# check if tag argument provided
328331
if [ -z "${RELEASE_TAG}" ]; then
329332
>&2 echo "Usage: create-release-candidate-branch.sh -t <tag> [-p] [-c] [-w products|operators|all]"
330333
exit 1
331334
fi
332335

333-
# check if argument matches our tag regex
334-
if [[ ! $RELEASE_TAG =~ $TAG_REGEX ]]; then
335-
>&2 echo "Provided tag [$RELEASE_TAG] does not match the required tag regex pattern [$TAG_REGEX]"
336-
exit 1
337-
fi
336+
validate_tag "$RELEASE_TAG"
337+
validate_what "$WHAT" "products" "operators" "all"
338338

339339
if [ ! -d "$TEMP_RELEASE_FOLDER" ]; then
340-
echo "Creating folder for cloning docker images and/or operators: [$TEMP_RELEASE_FOLDER]"
341-
mkdir -p "$TEMP_RELEASE_FOLDER"
340+
echo "Creating folder for cloning docker images and/or operators: [$TEMP_RELEASE_FOLDER]"
341+
mkdir -p "$TEMP_RELEASE_FOLDER"
342342
fi
343343

344344
check_dependencies

0 commit comments

Comments
 (0)