1
1
#! /usr/bin/env bash
2
2
set -euo pipefail
3
3
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.
6
6
#
7
7
# The script reminds you about some pre-requisites before actually running. These are:
8
8
#
9
9
# - 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.
11
11
# - Have a clean working directory.
12
12
#
13
13
# This script takes a major.minor.patch version as an argument and
@@ -20,43 +20,46 @@ set -euo pipefail
20
20
# the version is _required_ and -p for push is optional.
21
21
# If you do not push, you have to push manually afterwards with a regular 'git push'
22
22
23
+ REMOTE_REF=" origin/main"
24
+ LOCAL_REF=" HEAD"
25
+
23
26
# ------------------------------
24
27
# Args parsing
25
28
# ------------------------------
26
29
27
- version =" "
28
- push =false
30
+ VERSION =" "
31
+ PUSH =false
29
32
30
33
while [[ " $# " -gt 0 ]]; do
31
34
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 ;;
34
37
* ) echo " Unknown parameter passed: $1 " ; exit 1 ;;
35
38
esac
36
39
shift
37
40
done
38
41
39
42
# Check if the required version argument is provided
40
- if [ -z " $version " ]; then
43
+ if [ -z " $VERSION " ]; then
41
44
echo " Usage: make-release-branch.sh -v <version> [-p]"
42
45
echo " The version needs to be provided as <major>.<minor>.<patch>."
43
46
echo " Use -p to automatically push at the end."
44
47
exit 1
45
48
fi
46
49
47
50
# 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
49
52
echo " Invalid version format. Please use the major.minor.patch format."
50
53
exit 1
51
54
fi
52
55
53
- echo " Settings: Version: $version , Push: $push "
56
+ echo " Settings: Version: $VERSION , Push: $PUSH "
54
57
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
57
60
58
61
# 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)
60
63
61
64
# ------------------------------
62
65
# Checking prerequisites
@@ -66,28 +69,33 @@ docs_version=$(echo "$version" | cut -d. -f1,2)
66
69
echo " Release notes for the new version should already be written and commited to the main branch,"
67
70
echo " so they show up in both the nightly and future versions, as well as the new release branch"
68
71
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
70
73
71
74
# 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:]' )
73
76
74
77
# Check the user's response
75
- if [ " $release_notes_answer_lowercase " != " yes" ]; then
78
+ if [ " $RELEASE_NOTES_ANSWER_LOWERCASE " != " yes" ]; then
76
79
echo " Please write release notes and merge them into main before running this script."
77
80
exit 1
78
81
fi
79
82
80
83
# 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
83
86
echo " Not on the main branch. Please switch to the main branch."
84
87
exit 1
85
88
fi
86
89
87
90
# Check if the branch is up to date with the origin
88
91
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
91
99
exit 1
92
100
fi
93
101
100
108
echo " All checks passed. You are on the main branch, up to date with the origin, and the working directory is clean."
101
109
102
110
# ------------------------------
103
- # Updating the antora.yaml
111
+ # Updating the antora.yaml file
104
112
# ------------------------------
105
113
106
114
# 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 "
108
116
109
117
# Set prerelease to false
110
- sed -i " s/^prerelease:.*/prerelease: false/" " $antora_yaml "
118
+ sed -i " s/^prerelease:.*/prerelease: false/" " $ANTORA_YAML_FILE "
111
119
112
120
# 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 "
114
122
115
123
# Display changes using git diff
116
- git diff " $antora_yaml "
124
+ git diff " $ANTORA_YAML_FILE "
117
125
118
126
# ------------------------------
119
127
# Wrap up: commit and push
120
128
# ------------------------------
121
129
122
130
# 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
124
132
125
133
# 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:]' )
127
135
128
136
# 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 ."
131
139
exit 1
132
140
fi
133
141
134
142
# User wants to proceed
135
143
# 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 "
138
146
139
147
# 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 "
142
150
143
151
# Push the branch if requested
144
- if [ " $push " = true ]; then
152
+ if [ " $PUSH " = true ]; then
145
153
echo " Pushing changes to origin ..."
146
- git push origin " $branch_name "
154
+ git push origin " $BRANCH_NAME "
147
155
else
148
156
echo " Skipping push to origin. You still need to run:"
149
- echo " git push origin \" $branch_name \" "
157
+ echo " git push origin \" $BRANCH_NAME \" "
150
158
echo " to complete the process."
151
159
fi
0 commit comments