diff --git a/scripts/make-release-branch.sh b/scripts/make-release-branch.sh index 8fb91349b..f926e5619 100755 --- a/scripts/make-release-branch.sh +++ b/scripts/make-release-branch.sh @@ -6,26 +6,47 @@ set -euo pipefail # - 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 d0f8af4dc..2e3c94f1c 100755 --- a/scripts/publish-new-version.sh +++ b/scripts/publish-new-version.sh @@ -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."