Skip to content

Commit 08c9c35

Browse files
authored
refactor: Improve branch/release scripts (#762)
1 parent 7b618f8 commit 08c9c35

File tree

2 files changed

+76
-76
lines changed

2 files changed

+76
-76
lines changed

scripts/make-release-branch.sh

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
# This script creates a new 'release/{major}.{minor}' branch for the documetation,
5-
# off of the 'main' branch.
4+
# This script creates a new 'release-{major}.{minor}' branch for the documetation,
5+
# off of the 'main' branch.
66
#
77
# The script reminds you about some pre-requisites before actually running. These are:
88
#
99
# - Write the release notes for the release and have them committed into main.
10-
# - Have the main branch checked out, and up to date with origin.
10+
# - Have the main branch checked out, and up to date with origin.
1111
# - Have a clean working directory.
1212
#
1313
# This script takes a major.minor.patch version as an argument and
@@ -20,43 +20,46 @@ set -euo pipefail
2020
# the version is _required_ and -p for push is optional.
2121
# If you do not push, you have to push manually afterwards with a regular 'git push'
2222

23+
REMOTE_REF="origin/main"
24+
LOCAL_REF="HEAD"
25+
2326
# ------------------------------
2427
# Args parsing
2528
# ------------------------------
2629

27-
version=""
28-
push=false
30+
VERSION=""
31+
PUSH=false
2932

3033
while [[ "$#" -gt 0 ]]; do
3134
case $1 in
32-
-v|--version) version="$2"; shift ;;
33-
-p|--push) push=true ;;
35+
-v|--version) VERSION="$2"; shift ;;
36+
-p|--push) PUSH=true ;;
3437
*) echo "Unknown parameter passed: $1"; exit 1 ;;
3538
esac
3639
shift
3740
done
3841

3942
# Check if the required version argument is provided
40-
if [ -z "$version" ]; then
43+
if [ -z "$VERSION" ]; then
4144
echo "Usage: make-release-branch.sh -v <version> [-p]"
4245
echo "The version needs to be provided as <major>.<minor>.<patch>."
4346
echo "Use -p to automatically push at the end."
4447
exit 1
4548
fi
4649

4750
# Validate the version format (major.minor.patch)
48-
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
51+
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
4952
echo "Invalid version format. Please use the major.minor.patch format."
5053
exit 1
5154
fi
5255

53-
echo "Settings: Version: $version, Push: $push"
56+
echo "Settings: Version: $VERSION, Push: $PUSH"
5457

55-
docs_dir="$(dirname "$0")/.."
56-
antora_yaml=$docs_dir/antora.yml
58+
DOCS_DIRECTORY="$(dirname "$0")/.."
59+
ANTORA_YAML_FILE=$DOCS_DIRECTORY/antora.yml
5760

5861
# Extract major.minor part of the version
59-
docs_version=$(echo "$version" | cut -d. -f1,2)
62+
DOCS_VERSION=$(echo "$VERSION" | cut -d. -f1,2)
6063

6164
# ------------------------------
6265
# Checking prerequisites
@@ -66,28 +69,33 @@ docs_version=$(echo "$version" | cut -d. -f1,2)
6669
echo "Release notes for the new version should already be written and commited to the main branch,"
6770
echo "so they show up in both the nightly and future versions, as well as the new release branch"
6871
echo "that is about the be created."
69-
read -p "Did you already write release notes and merge them into main? (yes/no): " release_notes_answer
72+
read -r -p "Did you already write release notes and merge them into main? (yes/no): " RELEASE_NOTES_ANSWER
7073

7174
# Convert the user input to lowercase for case-insensitive comparison
72-
release_notes_answer_lowercase=$(echo "$release_notes_answer" | tr '[:upper:]' '[:lower:]')
75+
RELEASE_NOTES_ANSWER_LOWERCASE=$(echo "$RELEASE_NOTES_ANSWER" | tr '[:upper:]' '[:lower:]')
7376

7477
# Check the user's response
75-
if [ "$release_notes_answer_lowercase" != "yes" ]; then
78+
if [ "$RELEASE_NOTES_ANSWER_LOWERCASE" != "yes" ]; then
7679
echo "Please write release notes and merge them into main before running this script."
7780
exit 1
7881
fi
7982

8083
# Check if on main branch
81-
current_branch=$(git rev-parse --abbrev-ref HEAD)
82-
if [ "$current_branch" != "main" ]; then
84+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref $LOCAL_REF)
85+
if [ "$CURRENT_BRANCH" != "main" ]; then
8386
echo "Not on the main branch. Please switch to the main branch."
8487
exit 1
8588
fi
8689

8790
# Check if the branch is up to date with the origin
8891
git fetch
89-
if [ "$(git rev-parse HEAD)" != "$(git rev-parse origin/main)" ]; then
90-
echo "Your branch is not up to date with the origin main branch. Please pull the latest changes."
92+
93+
if [ "$(git rev-parse $LOCAL_REF)" != "$(git rev-parse $REMOTE_REF)" ]; then
94+
echo "Your branch is not up to date with the origin main branch."
95+
echo
96+
# This lists the local and remote commit hash, commit message, author name and email, and author date
97+
git log --format="%C(auto, yellow)%h: %Creset%s by %C(auto,yellow)%an <%ae>%Creset at %C(auto,blue)%ad (%S)" "$LOCAL_REF" -1
98+
git log --format="%C(auto, yellow)%h: %Creset%s by %C(auto,yellow)%an <%ae>%Creset at %C(auto,blue)%ad (%S)" "$REMOTE_REF" -1
9199
exit 1
92100
fi
93101

@@ -100,52 +108,52 @@ fi
100108
echo "All checks passed. You are on the main branch, up to date with the origin, and the working directory is clean."
101109

102110
# ------------------------------
103-
# Updating the antora.yaml
111+
# Updating the antora.yaml file
104112
# ------------------------------
105113

106114
# Set version key to docs_version
107-
sed -i "s/^version:.*/version: \"$docs_version\"/" "$antora_yaml"
115+
sed -i "s/^version:.*/version: \"$DOCS_VERSION\"/" "$ANTORA_YAML_FILE"
108116

109117
# Set prerelease to false
110-
sed -i "s/^prerelease:.*/prerelease: false/" "$antora_yaml"
118+
sed -i "s/^prerelease:.*/prerelease: false/" "$ANTORA_YAML_FILE"
111119

112120
# Set crd-docs-version key to the 'version' variable
113-
sed -i "s/^\(\s*\)crd-docs-version:.*/\1crd-docs-version: \"$version\"/" "$antora_yaml"
121+
sed -i "s/^\(\s*\)crd-docs-version:.*/\1crd-docs-version: \"$VERSION\"/" "$ANTORA_YAML_FILE"
114122

115123
# Display changes using git diff
116-
git diff "$antora_yaml"
124+
git diff "$ANTORA_YAML_FILE"
117125

118126
# ------------------------------
119127
# Wrap up: commit and push
120128
# ------------------------------
121129

122130
# Ask the user whether to proceed
123-
read -p "Do you want to proceed with these changes? (yes/no): " proceed_answer
131+
read -r -p "Do you want to proceed with these changes? (yes/no): " PROCEED_ANSWER
124132

125133
# Convert the user input to lowercase for case-insensitive comparison
126-
proceed_answer_lowercase=$(echo "$proceed_answer" | tr '[:upper:]' '[:lower:]')
134+
PROCEED_ANSWER_LOWERCASE=$(echo "$PROCEED_ANSWER" | tr '[:upper:]' '[:lower:]')
127135

128136
# Check the user's response
129-
if [ "$proceed_answer_lowercase" != "yes" ]; then
130-
echo "Aborted. Nothing was commited."
137+
if [ "$PROCEED_ANSWER_LOWERCASE" != "yes" ]; then
138+
echo "Aborted. Nothing was committed."
131139
exit 1
132140
fi
133141

134142
# User wants to proceed
135143
# Checkout a new branch
136-
branch_name="release/$docs_version"
137-
git checkout -b "$branch_name"
144+
BRANCH_NAME="release-$DOCS_VERSION"
145+
git checkout -b "$BRANCH_NAME"
138146

139147
# Commit the changes
140-
git add "$antora_yaml"
141-
git commit -m "Update version in antora.yml to $version"
148+
git add "$ANTORA_YAML_FILE"
149+
git commit -m "chore: Update version in antora.yml to $VERSION"
142150

143151
# Push the branch if requested
144-
if [ "$push" = true ]; then
152+
if [ "$PUSH" = true ]; then
145153
echo "Pushing changes to origin ..."
146-
git push origin "$branch_name"
154+
git push origin "$BRANCH_NAME"
147155
else
148156
echo "Skipping push to origin. You still need to run:"
149-
echo "git push origin \"$branch_name\""
157+
echo "git push origin \"$BRANCH_NAME\""
150158
echo "to complete the process."
151159
fi

scripts/publish-new-version.sh

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,63 +24,61 @@ fi
2424
# Args parsing
2525
# ------------------------------
2626

27-
docs_version=""
28-
push=false
27+
DOCS_VERSION=""
28+
PUSH=false
2929

3030
while [[ "$#" -gt 0 ]]; do
3131
case $1 in
32-
-v|--version) docs_version="$2"; shift ;;
33-
-p|--push) push=true ;;
32+
-v|--version) DOCS_VERSION="$2"; shift ;;
33+
-p|--push) PUSH=true ;;
3434
*) echo "Unknown parameter passed: $1"; exit 1 ;;
3535
esac
3636
shift
3737
done
3838

3939
# Check if the required version argument is provided
40-
if [ -z "$docs_version" ]; then
40+
if [ -z "$DOCS_VERSION" ]; then
4141
echo "Usage: publish-new-version.sh -v <version> [-p]"
4242
echo "The version needs to be provided as <major>.<minor>."
4343
echo "Use -p to automatically push at the end."
4444
exit 1
4545
fi
4646

4747
# Validate the version format (major.minor.patch)
48-
if [[ ! "$docs_version" =~ ^[0-9]+\.[0-9]+$ ]]; then
48+
if [[ ! "$DOCS_VERSION" =~ ^[0-9]+\.[0-9]+$ ]]; then
4949
echo "Invalid version format. Please use the major.minor format."
5050
exit 1
5151
fi
5252

53-
# Define the branches to add. The documentation repo uses a '/' while the operators use a '-'
54-
docs_branch="release/$docs_version"
55-
operator_branch="release-$docs_version"
53+
BRANCH="release-$DOCS_VERSION"
5654

5755
# ------------------------------
5856
# Checking prerequisites
5957
# ------------------------------
6058

6159
# Check if the release branch exists upstream
62-
if ! git rev-parse --quiet --verify "$docs_branch" > /dev/null; then
63-
echo "Release branch '$docs_branch' is missing upstream in the documentation repository."
64-
echo "Please create the $docs_branch branch first using the make-release-branch.sh script."
60+
if ! git rev-parse --quiet --verify "$BRANCH" > /dev/null; then
61+
echo "Release branch '$BRANCH' is missing upstream in the documentation repository."
62+
echo "Please create the $BRANCH branch first using the make-release-branch.sh script."
6563
echo "Aborting."
6664
exit 1
6765
fi
6866

6967
echo "Did you create all the release branches in the operators?"
7068
echo "Did you also create a release branch in the demos repository?"
71-
read -p "(yes/no): " operators_branches_answer
69+
read -r -p "(yes/no): " OPERATORS_BRANCHES_ANSWER
7270

7371
# Convert the user input to lowercase for case-insensitive comparison
74-
operators_branches_answer_lowercase=$(echo "$operators_branches_answer" | tr '[:upper:]' '[:lower:]')
72+
OPERATORS_BRANCHES_ANSWER_LOWERCASE=$(echo "$OPERATORS_BRANCHES_ANSWER" | tr '[:upper:]' '[:lower:]')
7573

76-
if [ "$operators_branches_answer_lowercase" != "yes" ]; then
74+
if [ "$OPERATORS_BRANCHES_ANSWER_LOWERCASE" != "yes" ]; then
7775
echo "Please create all the branches in the operators before proceeding."
7876
exit 1
7977
fi
8078

8179
# Check if on main branch
82-
current_branch=$(git rev-parse --abbrev-ref HEAD)
83-
if [ "$current_branch" != "main" ]; then
80+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
81+
if [ "$CURRENT_BRANCH" != "main" ]; then
8482
echo "Not on the main branch. Please switch to the main branch."
8583
exit 1
8684
fi
@@ -106,21 +104,13 @@ echo "All checks passed."
106104

107105
echo "Updating playbooks."
108106

109-
# Define the branches to add. The documentation repo uses a '/' while the operators use a '-'
110-
docs_branch="release/$docs_version"
111-
operator_branch="release-$docs_version"
112-
insert_position=1
113-
114-
docs_dir="$(dirname "$0")/.."
115-
playbook_files=("$docs_dir/antora-playbook.yml" "$docs_dir/local-antora-playbook.yml")
107+
DOCS_DIRECTORY="$(dirname "$0")/.."
108+
PLAYBOOK_FILES=("$DOCS_DIRECTORY/antora-playbook.yml" "$DOCS_DIRECTORY/local-antora-playbook.yml")
116109

117110
# Loop through each playbook file
118-
for yaml_file in "${playbook_files[@]}"; do
119-
# Insert the docs_branch
120-
yq ".content.sources[0].branches |= (.[:$insert_position] + [\"$docs_branch\"] + .[$insert_position:])" -i "$yaml_file"
121-
122-
# Update all the operator and demos sources.
123-
yq "with(.content.sources.[]; select(.url |test(\".*(operator|demos).*\")) | .branches |= .[:$insert_position] + [\"$operator_branch\"] + .[$insert_position:])" -i "$yaml_file"
111+
for yaml_file in "${PLAYBOOK_FILES[@]}"; do
112+
# Update all sources except stackable-cockpit.
113+
yq "with(.content.sources.[]; select(.url | test(\".*(stackable-cockpit).*\") | not) | .branches |= .[:1] + [\"release-25.7\"] + .[1:])" -i "$yaml_file"
124114
done
125115

126116
# ------------------------------
@@ -129,35 +119,37 @@ done
129119

130120
# Display changes and ask for user confirmation
131121
git diff
132-
read -p "Do you want to proceed with these changes? (yes/no): " proceed_answer
122+
read -r -p "Do you want to proceed with these changes? (yes/no): " PROCEED_ANSWER
133123

134124
# Convert the user input to lowercase for case-insensitive comparison
135-
proceed_answer_lowercase=$(echo "$proceed_answer" | tr '[:upper:]' '[:lower:]')
125+
PROCEED_ANSWER_LOWERCASE=$(echo "$PROCEED_ANSWER" | tr '[:upper:]' '[:lower:]')
136126

137127
# Check the user's response
138-
if [ "$proceed_answer_lowercase" != "yes" ]; then
139-
echo "Aborted. Nothing was commited."
128+
if [ "$PROCEED_ANSWER_LOWERCASE" != "yes" ]; then
129+
echo "Aborted. Nothing was committed."
140130
exit 1
141131
fi
142132

143-
publish_branch="publish-$docs_version"
133+
PR_BRANCH="pr-$DOCS_VERSION"
144134

145-
git checkout -b "$publish_branch"
135+
git checkout -b "$PR_BRANCH"
146136

147137
git add .
148-
git commit -m "Add release branches to the playbooks for release $docs_version"
138+
git commit -m "chore: Add release branches to the playbooks for release $DOCS_VERSION"
149139

150140
# Push the branch if requested
151-
if [ "$push" = true ]; then
141+
if [ "$PUSH" = true ]; then
152142
echo "Pushing changes to origin ..."
153-
git push -u origin "$publish_branch"
143+
git push -u origin "$PR_BRANCH"
154144
echo ""
155145
echo "The changes have been pushed to GitHub!"
146+
echo "Raise the PR against the $BRANCH branch."
156147
echo "Click the link above to create the PR in GitHub, and then verify that the build works with Netlify previews."
157148
echo "Once the branch is merged, the changes will automatically be deployed and be live."
158149
else
159150
echo ""
160151
echo "Skipping push to origin."
161-
echo "Please push the branch manually and create PR."
152+
echo "Please push the branch manually and create PR."
153+
echo "Raise the PR against the $BRANCH branch."
162154
echo "Once the changes are merged, they will automatically be deployed and be live."
163155
fi

0 commit comments

Comments
 (0)