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