1
+ #! /usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ # This script updates all the playbook files with the new branches for a given version.
5
+ # The version should be given as major.minor.
6
+ # All the release branches in the operators as well as the docs release branch should already be there.
7
+
8
+ # Check if yq is installed
9
+ if ! command -v yq & > /dev/null; then
10
+ echo " Error: 'yq' is not installed. It is needed to update yaml files later in the script."
11
+ echo " This script was tested with yq v4.40.5"
12
+ echo " Please install 'yq' from https://github.com/mikefarah/yq and then run the script again."
13
+ exit 1
14
+ fi
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
20
+ fi
21
+
22
+ # Validate the version format (major.minor)
23
+ if [[ ! " $1 " =~ ^[0-9]+\. [0-9]$ ]]; then
24
+ echo " Invalid version format. Please use the major.minor format."
25
+ exit 1
26
+ fi
27
+
28
+ docs_version=" $1 "
29
+
30
+ # Define the branches to add. The documentation repo uses a '/' while the operators use a '-'
31
+ docs_branch=" release/$docs_version "
32
+ operator_branch=" release-$docs_version "
33
+
34
+ # Check if the release branch exists upstream
35
+ if ! git rev-parse --quiet --verify " $docs_branch " > /dev/null; then
36
+ echo " Release branch '$docs_branch ' is missing upstream in the documentation repository."
37
+ echo " Please create the $docs_branch branch first using the make-release-branch.sh script."
38
+ echo " Aborting."
39
+ exit 1
40
+ fi
41
+
42
+ read -p " Did you create all the release branches in the operators? (yes/no): " operators_branches_answer
43
+
44
+ # Convert the user input to lowercase for case-insensitive comparison
45
+ operators_branches_answer_lowercase=$( echo " $operators_branches_answer " | tr ' [:upper:]' ' [:lower:]' )
46
+
47
+ if [ " $operators_branches_answer_lowercase " != " yes" ]; then
48
+ echo " Please create all the branches in the operators before proceeding."
49
+ exit 1
50
+ fi
51
+
52
+ # Check if on main branch
53
+ current_branch=$( git rev-parse --abbrev-ref HEAD)
54
+ if [ " $current_branch " != " main" ]; then
55
+ echo " Not on the main branch. Please switch to the main branch."
56
+ exit 1
57
+ fi
58
+
59
+ # Check if the branch is up to date with the origin
60
+ git fetch
61
+ if [ " $( git rev-parse HEAD) " != " $( git rev-parse origin/main) " ]; then
62
+ echo " Your branch is not up to date with the origin main branch. Please pull the latest changes."
63
+ exit 1
64
+ fi
65
+
66
+ # Check if the working directory is clean
67
+ if [ -n " $( git status --porcelain) " ]; then
68
+ echo " Working directory is not clean. Please commit or stash your changes."
69
+ exit 1
70
+ fi
71
+
72
+ echo " All checks passed."
73
+ echo " Updating playbooks."
74
+
75
+ # Define the branches to add. The documentation repo uses a '/' while the operators use a '-'
76
+ docs_branch=" release/$docs_version "
77
+ operator_branch=" release-$docs_version "
78
+ insert_position=1
79
+
80
+ docs_dir=" $( dirname " $0 " ) /.."
81
+ playbook_files=(" $docs_dir /antora-playbook.yml" " $docs_dir /local-antora-playbook.yml" )
82
+
83
+ # Loop through each playbook file
84
+ for yaml_file in " ${playbook_files[@]} " ; do
85
+ # Insert the docs_branch
86
+ yq " .content.sources[0].branches |= (.[:$insert_position ] + [\" $docs_branch \" ] + .[$insert_position :])" -i " $yaml_file "
87
+
88
+ # Update all the operator sources.
89
+ yq " with(.content.sources.[]; select(.url == \" *operator*\" ) | .branches |= .[:$insert_position ] + [\" $operator_branch \" ] + .[$insert_position :])" -i " $yaml_file "
90
+ done
91
+
92
+ # Display changes and ask for user confirmation
93
+ git diff
94
+ read -p " Do you want to proceed with these changes? (yes/no): " proceed_answer
95
+
96
+ # Convert the user input to lowercase for case-insensitive comparison
97
+ proceed_answer_lowercase=$( echo " $proceed_answer " | tr ' [:upper:]' ' [:lower:]' )
98
+
99
+ # Check the user's response
100
+ if [ " $proceed_answer_lowercase " != " yes" ]; then
101
+ echo " Aborted. Nothing was commited."
102
+ exit 1
103
+ fi
104
+
105
+ publish_branch=" publish-$docs_version "
106
+
107
+ git checkout -b " $publish_branch "
108
+
109
+ git add .
110
+ git commit -m " Add release branches to the playbooks for release $docs_version ."
111
+
112
+ # Push the branch upstream
113
+ git push -u origin " $publish_branch "
114
+
115
+ echo " The changes have been pushed to GitHub!"
116
+ echo " Click the link above to create the PR in GitHub, and then verify that the build works with Netlify previews."
117
+ echo " Once the branch is merged, the changes are live."
0 commit comments