From 812ea48a3f9f45e0dba5df3fee1db1ec5080fb4f Mon Sep 17 00:00:00 2001 From: Felix Hennig Date: Tue, 19 Dec 2023 11:27:06 +0100 Subject: [PATCH 1/2] fix --- scripts/make-release-branch.sh | 2 +- scripts/publish-new-version.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/make-release-branch.sh b/scripts/make-release-branch.sh index 8fb91349b..e69f9aea0 100755 --- a/scripts/make-release-branch.sh +++ b/scripts/make-release-branch.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -euo pipefail +set -eo pipefail # This script takes a major.minor.patch version and # - updates the antora.yml file accordingly diff --git a/scripts/publish-new-version.sh b/scripts/publish-new-version.sh index d0f8af4dc..738761f50 100755 --- a/scripts/publish-new-version.sh +++ b/scripts/publish-new-version.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -euo pipefail +set -eo pipefail # This script updates all the playbook files with the new branches for a given version. # The version should be given as major.minor. From 1f8f3becf158a6000d4ae6e216be4312ba3bc331 Mon Sep 17 00:00:00 2001 From: Felix Hennig Date: Tue, 19 Dec 2023 11:54:13 +0100 Subject: [PATCH 2/2] Improved arg parsing and comments --- scripts/make-release-branch.sh | 54 ++++++++++++++++++++++++++------- scripts/publish-new-version.sh | 55 +++++++++++++++++++++++++++------- 2 files changed, 88 insertions(+), 21 deletions(-) diff --git a/scripts/make-release-branch.sh b/scripts/make-release-branch.sh index e69f9aea0..f926e5619 100755 --- a/scripts/make-release-branch.sh +++ b/scripts/make-release-branch.sh @@ -1,31 +1,52 @@ #!/usr/bin/env bash -set -eo pipefail +set -euo pipefail # This script takes a major.minor.patch version and # - updates the antora.yml file accordingly # - creates a release branch # - pushes the release branch -# Check if a version argument is provided -if [ -z "$1" ]; then - echo "Please provide a version as a command-line argument (major.minor.patch)." - exit 1 +# ------------------------------ +# Args parsing +# ------------------------------ + +version="" +push=false + +while [[ "$#" -gt 0 ]]; do + case $1 in + -v|--version) version="$2"; shift ;; + -p|--push) push=true ;; + *) echo "Unknown parameter passed: $1"; exit 1 ;; + esac + shift +done + +# Check if the required version argument is provided +if [ -z "$version" ]; then +echo "Usage: your_script.sh -v [-p]" +echo "The version needs to be provided as major.minor.patch." +exit 1 fi # Validate the version format (major.minor.patch) -if [[ ! "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then +if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then echo "Invalid version format. Please use the major.minor.patch format." exit 1 fi +echo "Settings: Version: $version, Push: $push" + docs_dir="$(dirname "$0")/.." antora_yaml=$docs_dir/antora.yml -version="$1" - # Extract major.minor part of the version docs_version=$(echo "$version" | cut -d. -f1,2) +# ------------------------------ +# Checking prerequisites +# ------------------------------ + # Ask the user if they have written release notes and merged them into main echo "Release notes for the new version should already be written and commited to the main branch," echo "so the show up in both the nightly and future versions, as well as the new release branch" @@ -63,6 +84,10 @@ fi echo "All checks passed. You are on the main branch, up to date with the origin, and the working directory is clean." +# ------------------------------ +# Updating the antora.yaml +# ------------------------------ + # Set version key to docs_version sed -i "s/^version:.*/version: \"$docs_version\"/" "$antora_yaml" @@ -75,6 +100,10 @@ sed -i "s/^\(\s*\)crd-docs-version:.*/\1crd-docs-version: \"$version\"/" "$antor # Display changes using git diff git diff "$antora_yaml" +# ------------------------------ +# Wrap up: commit and push +# ------------------------------ + # Ask the user whether to proceed read -p "Do you want to proceed with these changes? (yes/no): " proceed_answer @@ -96,5 +125,10 @@ git checkout -b "$branch_name" git add "$antora_yaml" git commit -m "Update version in antora.yml to $version" -# Push the branch -git push origin "$branch_name" \ No newline at end of file +# Push the branch if requested +if [ "$push" = true ]; then + echo "Pushing changes to origin ..." + git push origin "$branch_name" +else + echo "Skipping push to origin." +fi diff --git a/scripts/publish-new-version.sh b/scripts/publish-new-version.sh index 738761f50..2e3c94f1c 100755 --- a/scripts/publish-new-version.sh +++ b/scripts/publish-new-version.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -eo pipefail +set -euo pipefail # This script updates all the playbook files with the new branches for a given version. # The version should be given as major.minor. @@ -13,24 +13,43 @@ if ! command -v yq &> /dev/null; then exit 1 fi -# Check if a version argument is provided -if [ -z "$1" ]; then - echo "Please provide a version as a command-line argument (major.minor)." - exit 1 +# ------------------------------ +# Args parsing +# ------------------------------ + +docs_version="" +push=false + +while [[ "$#" -gt 0 ]]; do + case $1 in + -v|--version) docs_version="$2"; shift ;; + -p|--push) push=true ;; + *) echo "Unknown parameter passed: $1"; exit 1 ;; + esac + shift +done + +# Check if the required version argument is provided +if [ -z "$docs_version" ]; then +echo "Usage: your_script.sh -v [-p]" +echo "The version needs to be provided as major.minor." +exit 1 fi -# Validate the version format (major.minor) -if [[ ! "$1" =~ ^[0-9]+\.[0-9]$ ]]; then +# Validate the version format (major.minor.patch) +if [[ ! "$docs_version" =~ ^[0-9]+\.[0-9]+$ ]]; then echo "Invalid version format. Please use the major.minor format." exit 1 fi -docs_version="$1" - # Define the branches to add. The documentation repo uses a '/' while the operators use a '-' docs_branch="release/$docs_version" operator_branch="release-$docs_version" +# ------------------------------ +# Checking prerequisites +# ------------------------------ + # Check if the release branch exists upstream if ! git rev-parse --quiet --verify "$docs_branch" > /dev/null; then echo "Release branch '$docs_branch' is missing upstream in the documentation repository." @@ -70,6 +89,11 @@ if [ -n "$(git status --porcelain)" ]; then fi echo "All checks passed." + +# ------------------------------ +# Updating playbooks +# ------------------------------ + echo "Updating playbooks." # 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 yq "with(.content.sources.[]; select(.url == \"*operator*\") | .branches |= .[:$insert_position] + [\"$operator_branch\"] + .[$insert_position:])" -i "$yaml_file" done +# ------------------------------ +# Wrap up: commit and push +# ------------------------------ + # Display changes and ask for user confirmation git diff read -p "Do you want to proceed with these changes? (yes/no): " proceed_answer @@ -109,8 +137,13 @@ git checkout -b "$publish_branch" git add . git commit -m "Add release branches to the playbooks for release $docs_version." -# Push the branch upstream -git push -u origin "$publish_branch" +# Push the branch if requested +if [ "$push" = true ]; then + echo "Pushing changes to origin ..." + git push -u origin "$publish_branch" +else + echo "Skipping push to origin." +fi echo "The changes have been pushed to GitHub!" echo "Click the link above to create the PR in GitHub, and then verify that the build works with Netlify previews."