Skip to content

Feat: new release scripts, component attribute for CRD docs links #511

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
13 changes: 13 additions & 0 deletions antora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,17 @@ nav:
- modules/operators/nav.adoc
- modules/contributor/nav.adoc
- modules/ROOT/nav2.adoc
# The prerelease setting affects version sorting.
# Set to 'true' for nightly and false otherwise.
prerelease: true
# The attributes below are specific to this component and version
# https://docs.antora.org/antora/latest/component-attributes/#hard-set
asciidoc:
attributes:
# Keep this version in line with the 'version' key above
# The versions for the CRD docs are either 'nightly' or
# a full major.minor.patch version like 23.7.1
crd-docs-version: "nightly"
# use the attributes below to link to the CRD docs
crd-docs-base-url: "https://crds.stackable.tech"
crd-docs: "{crd-docs-base-url}/{crd-docs-version}"
81 changes: 0 additions & 81 deletions gitpod-antora-playbook.yml

This file was deleted.

100 changes: 100 additions & 0 deletions scripts/make-release-branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/usr/bin/env bash
set -euo pipefail

# This script takes a major.minor.patch version and
# - updates the antora.yml file accordingly
# - 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
fi

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

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)

# 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"
echo "that is about the be created."
read -p "Did you already write release notes and merge them into main? (yes/no): " release_notes_answer

# Convert the user input to lowercase for case-insensitive comparison
release_notes_answer_lowercase=$(echo "$release_notes_answer" | tr '[:upper:]' '[:lower:]')

# Check the user's response
if [ "$release_notes_answer_lowercase" != "yes" ]; then
echo "Please write release notes and merge them into main before running this script."
exit 1
fi

# Check if on main branch
current_branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$current_branch" != "main" ]; then
echo "Not on the main branch. Please switch to the main branch."
exit 1
fi

# Check if the branch is up to date with the origin
git fetch
if [ "$(git rev-parse HEAD)" != "$(git rev-parse origin/main)" ]; then
echo "Your branch is not up to date with the origin main branch. Please pull the latest changes."
exit 1
fi

# Check if the working directory is clean
if [ -n "$(git status --porcelain)" ]; then
echo "Working directory is not clean. Please commit or stash your changes."
exit 1
fi

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

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

# Set prerelease to false
sed -i "s/^prerelease:.*/prerelease: false/" "$antora_yaml"

# Set crd-docs-version key to the 'version' variable
sed -i "s/^\(\s*\)crd-docs-version:.*/\1crd-docs-version: \"$version\"/" "$antora_yaml"

# Display changes using git diff
git diff "$antora_yaml"

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

# Convert the user input to lowercase for case-insensitive comparison
proceed_answer_lowercase=$(echo "$proceed_answer" | tr '[:upper:]' '[:lower:]')

# Check the user's response
if [ "$proceed_answer_lowercase" != "yes" ]; then
echo "Aborted. Nothing was commited."
exit 1
fi

# User wants to proceed
# Checkout a new branch
branch_name="release/$docs_version"
git checkout -b "$branch_name"

# Commit the changes
git add "$antora_yaml"
git commit -m "Update version in antora.yml to $version"

# Push the branch
git push origin "$branch_name"
117 changes: 117 additions & 0 deletions scripts/publish-new-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/usr/bin/env bash
set -euo pipefail

# This script updates all the playbook files with the new branches for a given version.
# The version should be given as major.minor.
# All the release branches in the operators as well as the docs release branch should already be there.

# Check if yq is installed
if ! command -v yq &> /dev/null; then
echo "Error: 'yq' is not installed. It is needed to update yaml files later in the script."
echo "This script was tested with yq v4.40.5"
echo "Please install 'yq' from https://github.com/mikefarah/yq and then run the script again."
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
fi

# Validate the version format (major.minor)
if [[ ! "$1" =~ ^[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"

# 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."
echo "Please create the $docs_branch branch first using the make-release-branch.sh script."
echo "Aborting."
exit 1
fi

read -p "Did you create all the release branches in the operators? (yes/no): " operators_branches_answer

# Convert the user input to lowercase for case-insensitive comparison
operators_branches_answer_lowercase=$(echo "$operators_branches_answer" | tr '[:upper:]' '[:lower:]')

if [ "$operators_branches_answer_lowercase" != "yes" ]; then
echo "Please create all the branches in the operators before proceeding."
exit 1
fi

# Check if on main branch
current_branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$current_branch" != "main" ]; then
echo "Not on the main branch. Please switch to the main branch."
exit 1
fi

# Check if the branch is up to date with the origin
git fetch
if [ "$(git rev-parse HEAD)" != "$(git rev-parse origin/main)" ]; then
echo "Your branch is not up to date with the origin main branch. Please pull the latest changes."
exit 1
fi

# Check if the working directory is clean
if [ -n "$(git status --porcelain)" ]; then
echo "Working directory is not clean. Please commit or stash your changes."
exit 1
fi

echo "All checks passed."
echo "Updating playbooks."

# 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"
insert_position=1

docs_dir="$(dirname "$0")/.."
playbook_files=("$docs_dir/antora-playbook.yml" "$docs_dir/local-antora-playbook.yml")

# Loop through each playbook file
for yaml_file in "${playbook_files[@]}"; do
# Insert the docs_branch
yq ".content.sources[0].branches |= (.[:$insert_position] + [\"$docs_branch\"] + .[$insert_position:])" -i "$yaml_file"

# Update all the operator sources.
yq "with(.content.sources.[]; select(.url == \"*operator*\") | .branches |= .[:$insert_position] + [\"$operator_branch\"] + .[$insert_position:])" -i "$yaml_file"
done

# Display changes and ask for user confirmation
git diff
read -p "Do you want to proceed with these changes? (yes/no): " proceed_answer

# Convert the user input to lowercase for case-insensitive comparison
proceed_answer_lowercase=$(echo "$proceed_answer" | tr '[:upper:]' '[:lower:]')

# Check the user's response
if [ "$proceed_answer_lowercase" != "yes" ]; then
echo "Aborted. Nothing was commited."
exit 1
fi

publish_branch="publish-$docs_version"

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"

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."
echo "Once the branch is merged, the changes are live."
48 changes: 0 additions & 48 deletions scripts/version_bump.sh

This file was deleted.