11#! /usr/bin/env bash
22set -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
3033while [[ " $# " -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
3740done
3841
3942# Check if the required version argument is provided
40- if [ -z " $version " ]; then
43+ if [ -z " $VERSION " ]; then
4144echo " Usage: make-release-branch.sh -v <version> [-p]"
4245echo " The version needs to be provided as <major>.<minor>.<patch>."
4346echo " Use -p to automatically push at the end."
4447exit 1
4548fi
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
5154fi
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)
6669echo " Release notes for the new version should already be written and commited to the main branch,"
6770echo " so they show up in both the nightly and future versions, as well as the new release branch"
6871echo " 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
7881fi
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
8588fi
8689
8790# Check if the branch is up to date with the origin
8891git 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
92100fi
93101
100108echo " 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
132140fi
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 "
147155else
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."
151159fi
0 commit comments