1
1
#! /usr/bin/env bash
2
- set -eo pipefail
2
+ set -euo pipefail
3
3
4
4
# This script updates all the playbook files with the new branches for a given version.
5
5
# The version should be given as major.minor.
@@ -13,24 +13,43 @@ if ! command -v yq &> /dev/null; then
13
13
exit 1
14
14
fi
15
15
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
20
37
fi
21
38
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
24
41
echo " Invalid version format. Please use the major.minor format."
25
42
exit 1
26
43
fi
27
44
28
- docs_version=" $1 "
29
-
30
45
# Define the branches to add. The documentation repo uses a '/' while the operators use a '-'
31
46
docs_branch=" release/$docs_version "
32
47
operator_branch=" release-$docs_version "
33
48
49
+ # ------------------------------
50
+ # Checking prerequisites
51
+ # ------------------------------
52
+
34
53
# Check if the release branch exists upstream
35
54
if ! git rev-parse --quiet --verify " $docs_branch " > /dev/null; then
36
55
echo " Release branch '$docs_branch ' is missing upstream in the documentation repository."
@@ -70,6 +89,11 @@ if [ -n "$(git status --porcelain)" ]; then
70
89
fi
71
90
72
91
echo " All checks passed."
92
+
93
+ # ------------------------------
94
+ # Updating playbooks
95
+ # ------------------------------
96
+
73
97
echo " Updating playbooks."
74
98
75
99
# 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
89
113
yq " with(.content.sources.[]; select(.url == \" *operator*\" ) | .branches |= .[:$insert_position ] + [\" $operator_branch \" ] + .[$insert_position :])" -i " $yaml_file "
90
114
done
91
115
116
+ # ------------------------------
117
+ # Wrap up: commit and push
118
+ # ------------------------------
119
+
92
120
# Display changes and ask for user confirmation
93
121
git diff
94
122
read -p " Do you want to proceed with these changes? (yes/no): " proceed_answer
@@ -109,8 +137,13 @@ git checkout -b "$publish_branch"
109
137
git add .
110
138
git commit -m " Add release branches to the playbooks for release $docs_version ."
111
139
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
114
147
115
148
echo " The changes have been pushed to GitHub!"
116
149
echo " Click the link above to create the PR in GitHub, and then verify that the build works with Netlify previews."
0 commit comments