Skip to content

Commit 1f8f3be

Browse files
committed
Improved arg parsing and comments
1 parent 812ea48 commit 1f8f3be

File tree

2 files changed

+88
-21
lines changed

2 files changed

+88
-21
lines changed

scripts/make-release-branch.sh

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,52 @@
11
#!/usr/bin/env bash
2-
set -eo pipefail
2+
set -euo pipefail
33

44
# This script takes a major.minor.patch version and
55
# - updates the antora.yml file accordingly
66
# - creates a release branch
77
# - pushes the release branch
88

9-
# Check if a version argument is provided
10-
if [ -z "$1" ]; then
11-
echo "Please provide a version as a command-line argument (major.minor.patch)."
12-
exit 1
9+
# ------------------------------
10+
# Args parsing
11+
# ------------------------------
12+
13+
version=""
14+
push=false
15+
16+
while [[ "$#" -gt 0 ]]; do
17+
case $1 in
18+
-v|--version) version="$2"; shift ;;
19+
-p|--push) push=true ;;
20+
*) echo "Unknown parameter passed: $1"; exit 1 ;;
21+
esac
22+
shift
23+
done
24+
25+
# Check if the required version argument is provided
26+
if [ -z "$version" ]; then
27+
echo "Usage: your_script.sh -v <version> [-p]"
28+
echo "The version needs to be provided as major.minor.patch."
29+
exit 1
1330
fi
1431

1532
# Validate the version format (major.minor.patch)
16-
if [[ ! "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
33+
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
1734
echo "Invalid version format. Please use the major.minor.patch format."
1835
exit 1
1936
fi
2037

38+
echo "Settings: Version: $version, Push: $push"
39+
2140
docs_dir="$(dirname "$0")/.."
2241
antora_yaml=$docs_dir/antora.yml
2342

24-
version="$1"
25-
2643
# Extract major.minor part of the version
2744
docs_version=$(echo "$version" | cut -d. -f1,2)
2845

46+
# ------------------------------
47+
# Checking prerequisites
48+
# ------------------------------
49+
2950
# Ask the user if they have written release notes and merged them into main
3051
echo "Release notes for the new version should already be written and commited to the main branch,"
3152
echo "so the show up in both the nightly and future versions, as well as the new release branch"
@@ -63,6 +84,10 @@ fi
6384

6485
echo "All checks passed. You are on the main branch, up to date with the origin, and the working directory is clean."
6586

87+
# ------------------------------
88+
# Updating the antora.yaml
89+
# ------------------------------
90+
6691
# Set version key to docs_version
6792
sed -i "s/^version:.*/version: \"$docs_version\"/" "$antora_yaml"
6893

@@ -75,6 +100,10 @@ sed -i "s/^\(\s*\)crd-docs-version:.*/\1crd-docs-version: \"$version\"/" "$antor
75100
# Display changes using git diff
76101
git diff "$antora_yaml"
77102

103+
# ------------------------------
104+
# Wrap up: commit and push
105+
# ------------------------------
106+
78107
# Ask the user whether to proceed
79108
read -p "Do you want to proceed with these changes? (yes/no): " proceed_answer
80109

@@ -96,5 +125,10 @@ git checkout -b "$branch_name"
96125
git add "$antora_yaml"
97126
git commit -m "Update version in antora.yml to $version"
98127

99-
# Push the branch
100-
git push origin "$branch_name"
128+
# Push the branch if requested
129+
if [ "$push" = true ]; then
130+
echo "Pushing changes to origin ..."
131+
git push origin "$branch_name"
132+
else
133+
echo "Skipping push to origin."
134+
fi

scripts/publish-new-version.sh

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

44
# This script updates all the playbook files with the new branches for a given version.
55
# The version should be given as major.minor.
@@ -13,24 +13,43 @@ if ! command -v yq &> /dev/null; then
1313
exit 1
1414
fi
1515

16-
# Check if a version argument is provided
17-
if [ -z "$1" ]; then
18-
echo "Please provide a version as a command-line argument (major.minor)."
19-
exit 1
16+
# ------------------------------
17+
# Args parsing
18+
# ------------------------------
19+
20+
docs_version=""
21+
push=false
22+
23+
while [[ "$#" -gt 0 ]]; do
24+
case $1 in
25+
-v|--version) docs_version="$2"; shift ;;
26+
-p|--push) push=true ;;
27+
*) echo "Unknown parameter passed: $1"; exit 1 ;;
28+
esac
29+
shift
30+
done
31+
32+
# Check if the required version argument is provided
33+
if [ -z "$docs_version" ]; then
34+
echo "Usage: your_script.sh -v <version> [-p]"
35+
echo "The version needs to be provided as major.minor."
36+
exit 1
2037
fi
2138

22-
# Validate the version format (major.minor)
23-
if [[ ! "$1" =~ ^[0-9]+\.[0-9]$ ]]; then
39+
# Validate the version format (major.minor.patch)
40+
if [[ ! "$docs_version" =~ ^[0-9]+\.[0-9]+$ ]]; then
2441
echo "Invalid version format. Please use the major.minor format."
2542
exit 1
2643
fi
2744

28-
docs_version="$1"
29-
3045
# Define the branches to add. The documentation repo uses a '/' while the operators use a '-'
3146
docs_branch="release/$docs_version"
3247
operator_branch="release-$docs_version"
3348

49+
# ------------------------------
50+
# Checking prerequisites
51+
# ------------------------------
52+
3453
# Check if the release branch exists upstream
3554
if ! git rev-parse --quiet --verify "$docs_branch" > /dev/null; then
3655
echo "Release branch '$docs_branch' is missing upstream in the documentation repository."
@@ -70,6 +89,11 @@ if [ -n "$(git status --porcelain)" ]; then
7089
fi
7190

7291
echo "All checks passed."
92+
93+
# ------------------------------
94+
# Updating playbooks
95+
# ------------------------------
96+
7397
echo "Updating playbooks."
7498

7599
# Define the branches to add. The documentation repo uses a '/' while the operators use a '-'
@@ -89,6 +113,10 @@ for yaml_file in "${playbook_files[@]}"; do
89113
yq "with(.content.sources.[]; select(.url == \"*operator*\") | .branches |= .[:$insert_position] + [\"$operator_branch\"] + .[$insert_position:])" -i "$yaml_file"
90114
done
91115

116+
# ------------------------------
117+
# Wrap up: commit and push
118+
# ------------------------------
119+
92120
# Display changes and ask for user confirmation
93121
git diff
94122
read -p "Do you want to proceed with these changes? (yes/no): " proceed_answer
@@ -109,8 +137,13 @@ git checkout -b "$publish_branch"
109137
git add .
110138
git commit -m "Add release branches to the playbooks for release $docs_version."
111139

112-
# Push the branch upstream
113-
git push -u origin "$publish_branch"
140+
# Push the branch if requested
141+
if [ "$push" = true ]; then
142+
echo "Pushing changes to origin ..."
143+
git push -u origin "$publish_branch"
144+
else
145+
echo "Skipping push to origin."
146+
fi
114147

115148
echo "The changes have been pushed to GitHub!"
116149
echo "Click the link above to create the PR in GitHub, and then verify that the build works with Netlify previews."

0 commit comments

Comments
 (0)