Skip to content

Script mini-fix and improvements #512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 43 additions & 9 deletions scripts/make-release-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,47 @@ set -euo pipefail
# - creates a release branch
# - pushes the release branch

# Check if a version argument is provided
if [ -z "$1" ]; then
echo "Please provide a version as a command-line argument (major.minor.patch)."
exit 1
# ------------------------------
# Args parsing
# ------------------------------

version=""
push=false

while [[ "$#" -gt 0 ]]; do
case $1 in
-v|--version) version="$2"; shift ;;
-p|--push) push=true ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done

# Check if the required version argument is provided
if [ -z "$version" ]; then
echo "Usage: your_script.sh -v <version> [-p]"
echo "The version needs to be provided as major.minor.patch."
exit 1
fi

# Validate the version format (major.minor.patch)
if [[ ! "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version format. Please use the major.minor.patch format."
exit 1
fi

echo "Settings: Version: $version, Push: $push"

docs_dir="$(dirname "$0")/.."
antora_yaml=$docs_dir/antora.yml

version="$1"

# Extract major.minor part of the version
docs_version=$(echo "$version" | cut -d. -f1,2)

# ------------------------------
# Checking prerequisites
# ------------------------------

# Ask the user if they have written release notes and merged them into main
echo "Release notes for the new version should already be written and commited to the main branch,"
echo "so the show up in both the nightly and future versions, as well as the new release branch"
Expand Down Expand Up @@ -63,6 +84,10 @@ fi

echo "All checks passed. You are on the main branch, up to date with the origin, and the working directory is clean."

# ------------------------------
# Updating the antora.yaml
# ------------------------------

# Set version key to docs_version
sed -i "s/^version:.*/version: \"$docs_version\"/" "$antora_yaml"

Expand All @@ -75,6 +100,10 @@ sed -i "s/^\(\s*\)crd-docs-version:.*/\1crd-docs-version: \"$version\"/" "$antor
# Display changes using git diff
git diff "$antora_yaml"

# ------------------------------
# Wrap up: commit and push
# ------------------------------

# Ask the user whether to proceed
read -p "Do you want to proceed with these changes? (yes/no): " proceed_answer

Expand All @@ -96,5 +125,10 @@ git checkout -b "$branch_name"
git add "$antora_yaml"
git commit -m "Update version in antora.yml to $version"

# Push the branch
git push origin "$branch_name"
# Push the branch if requested
if [ "$push" = true ]; then
echo "Pushing changes to origin ..."
git push origin "$branch_name"
else
echo "Skipping push to origin."
fi
53 changes: 43 additions & 10 deletions scripts/publish-new-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,43 @@ if ! command -v yq &> /dev/null; then
exit 1
fi

# Check if a version argument is provided
if [ -z "$1" ]; then
echo "Please provide a version as a command-line argument (major.minor)."
exit 1
# ------------------------------
# Args parsing
# ------------------------------

docs_version=""
push=false

while [[ "$#" -gt 0 ]]; do
case $1 in
-v|--version) docs_version="$2"; shift ;;
-p|--push) push=true ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done

# Check if the required version argument is provided
if [ -z "$docs_version" ]; then
echo "Usage: your_script.sh -v <version> [-p]"
echo "The version needs to be provided as major.minor."
exit 1
fi

# Validate the version format (major.minor)
if [[ ! "$1" =~ ^[0-9]+\.[0-9]$ ]]; then
# Validate the version format (major.minor.patch)
if [[ ! "$docs_version" =~ ^[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version format. Please use the major.minor format."
exit 1
fi

docs_version="$1"

# Define the branches to add. The documentation repo uses a '/' while the operators use a '-'
docs_branch="release/$docs_version"
operator_branch="release-$docs_version"

# ------------------------------
# Checking prerequisites
# ------------------------------

# Check if the release branch exists upstream
if ! git rev-parse --quiet --verify "$docs_branch" > /dev/null; then
echo "Release branch '$docs_branch' is missing upstream in the documentation repository."
Expand Down Expand Up @@ -70,6 +89,11 @@ if [ -n "$(git status --porcelain)" ]; then
fi

echo "All checks passed."

# ------------------------------
# Updating playbooks
# ------------------------------

echo "Updating playbooks."

# Define the branches to add. The documentation repo uses a '/' while the operators use a '-'
Expand All @@ -89,6 +113,10 @@ for yaml_file in "${playbook_files[@]}"; do
yq "with(.content.sources.[]; select(.url == \"*operator*\") | .branches |= .[:$insert_position] + [\"$operator_branch\"] + .[$insert_position:])" -i "$yaml_file"
done

# ------------------------------
# Wrap up: commit and push
# ------------------------------

# Display changes and ask for user confirmation
git diff
read -p "Do you want to proceed with these changes? (yes/no): " proceed_answer
Expand All @@ -109,8 +137,13 @@ git checkout -b "$publish_branch"
git add .
git commit -m "Add release branches to the playbooks for release $docs_version."

# Push the branch upstream
git push -u origin "$publish_branch"
# Push the branch if requested
if [ "$push" = true ]; then
echo "Pushing changes to origin ..."
git push -u origin "$publish_branch"
else
echo "Skipping push to origin."
fi

echo "The changes have been pushed to GitHub!"
echo "Click the link above to create the PR in GitHub, and then verify that the build works with Netlify previews."
Expand Down