Skip to content
Draft
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
10 changes: 9 additions & 1 deletion .github/workflows/release-charts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ on:
description: "New Webhook version (eg: v0.10.0-rc.14)"
required: true
default: ""
bump_major:
description: "Set 'true' to bump chart major version when the Webhook minor version increases (e.g., v0.5.0 → v0.6.0-rc.0). Default: false"
required: false
default: "false"
type: choice
options:
- "true"
- "false"

env:
CHARTS_REF: ${{ github.event.inputs.charts_ref }}
Expand Down Expand Up @@ -78,7 +86,7 @@ jobs:
BRANCH="bump-webhook-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
echo "BRANCH=${BRANCH}" >> $GITHUB_ENV
git checkout -b "$BRANCH" "$CHARTS_REF"
../webhook/.github/workflows/scripts/release-against-charts.sh . "$PREV_WEBHOOK" "$NEW_WEBHOOK"
../webhook/.github/workflows/scripts/release-against-charts.sh . "$PREV_WEBHOOK" "$NEW_WEBHOOK" ${{ github.event.inputs.bump_major }}

- name: Push and create pull request
env:
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/release-rancher.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ on:
description: "New Webhook version (eg: v0.5.0-rc.14)"
required: true
default: ""
bump_major:
description: "Set 'true' to bump chart major version when the Webhook minor version increases (e.g., v0.5.0 → v0.6.0-rc.0). Default: false"
required: false
default: "false"
type: choice
options:
- "true"
- "false"

env:
RANCHER_REF: ${{ github.event.inputs.rancher_ref }}
Expand Down Expand Up @@ -108,7 +116,7 @@ jobs:
BRANCH="bump-webhook-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
echo "BRANCH=${BRANCH}" >> $GITHUB_ENV
git checkout -b "$BRANCH" "$RANCHER_REF"
../webhook/.github/workflows/scripts/release-against-rancher.sh . "$NEW_WEBHOOK"
../webhook/.github/workflows/scripts/release-against-rancher.sh . "$NEW_WEBHOOK" ${{ github.event.inputs.bump_major }}

- name: Push and create pull request
env:
Expand Down
70 changes: 62 additions & 8 deletions .github/workflows/scripts/release-against-charts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,39 @@
# Bumps Webhook version in a locally checked out rancher/charts repository
#
# Usage:
# ./release-against-charts.sh <path to charts repo> <prev webhook release> <new webhook release>
# ./release-against-charts.sh <path to charts repo> <prev webhook release> <new webhook release> <bump major>
#
# Example:
# ./release-against-charts.sh "${GITHUB_WORKSPACE}" "v0.5.0-rc.13" "v0.5.0-rc.14"
# ./release-against-charts.sh "${GITHUB_WORKSPACE}" "v0.5.0-rc.13" "v0.5.0-rc.14" false

CHARTS_DIR=$1
PREV_WEBHOOK_VERSION=$2 # e.g. v0.5.2-rc.3
NEW_WEBHOOK_VERSION=$3 # e.g. v0.5.2-rc.4
PREV_WEBHOOK_VERSION="$2" # e.g. 0.5.0-rc.13
NEW_WEBHOOK_VERSION="$3" # e.g. 0.5.0-rc.14
BUMP_MAJOR="$4" # must be "true" or "false"

usage() {
cat <<EOF
Usage:
$0 <path to charts repo> <prev webhook release> <new webhook release>
$0 <path to charts repo> <prev webhook release> <new webhook release> <bump_major>

Arguments:
<path to charts repo> Path to locally checked out charts repo
<prev webhook release> Previous rancher-webhook version (e.g. v0.5.0-rc.13)
<new webhook release> New rancher-webhook version (e.g. v0.5.0-rc.14, v0.5.0, v0.6.0-rc.0)
<bump_major> Must be "true" if introducing a new webhook minor version, "false" otherwise.
Example: v0.5.0 → v0.6.0-rc.0 requires bump_major=true.

Examples:
RC to RC: $0 ./charts v0.5.0-rc.0 v0.5.0-rc.1 false
RC to stable: $0 ./charts v0.5.0-rc.0 v0.5.0 false
stable to RC: $0 ./charts v0.5.0 v0.5.1-rc.1 false
new minor RC: $0 ./charts v0.5.0 v0.6.0-rc.0 true # bump chart major
EOF
}

# Bumps the patch version of a semver version string
# e.g. 1.2.3 -> 1.2.4
# e.g. 1.2.3-rc.4 -> 1.2.4
bump_patch() {
version=$1
major=$(echo "$version" | cut -d. -f1)
Expand All @@ -28,6 +45,17 @@ bump_patch() {
echo "${major}.${minor}.${new_patch}"
}

# Bumps the major version of a semver version string and resets minor and patch to 0
# e.g. 1.2.3 -> 2.0.0
# e.g. 1.2.3-rc.4 -> 2.0.0
bump_major() {
version=$1
major=$(echo "$version" | cut -d. -f1)
new_major=$((major + 1))
echo "${new_major}.0.0"
}

# Validates that the version is in the format v<major>.<minor>.<patch> or v<major>.<minor>.<patch>-rc.<number>
validate_version_format() {
version=$1
if ! echo "$version" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$'; then
Expand All @@ -36,11 +64,16 @@ validate_version_format() {
fi
}

if [ -z "$CHARTS_DIR" ] || [ -z "$PREV_WEBHOOK_VERSION" ] || [ -z "$NEW_WEBHOOK_VERSION" ]; then
if [ -z "$CHARTS_DIR" ] || [ -z "$PREV_WEBHOOK_VERSION" ] || [ -z "$NEW_WEBHOOK_VERSION" ] || [ -z "$BUMP_MAJOR" ]; then
usage
exit 1
fi

if [ "$BUMP_MAJOR" != "true" ] && [ "$BUMP_MAJOR" != "false" ]; then
echo "Error: bump_major must be 'true' or 'false', got '$BUMP_MAJOR'"
exit 1
fi

validate_version_format "$PREV_WEBHOOK_VERSION"
validate_version_format "$NEW_WEBHOOK_VERSION"

Expand All @@ -59,6 +92,14 @@ fi
PREV_WEBHOOK_VERSION_SHORT=$(echo "$PREV_WEBHOOK_VERSION" | sed 's|^v||') # e.g. 0.5.2-rc.3
NEW_WEBHOOK_VERSION_SHORT=$(echo "$NEW_WEBHOOK_VERSION" | sed 's|^v||') # e.g. 0.5.2-rc.4

prev_minor=$(echo "$PREV_WEBHOOK_VERSION_SHORT" | cut -d. -f2)
new_minor=$(echo "$NEW_WEBHOOK_VERSION_SHORT" | cut -d. -f2)

is_new_minor=false
if [ "$new_minor" -gt "$prev_minor" ]; then
is_new_minor=true
fi

set -ue

cd "${CHARTS_DIR}"
Expand All @@ -77,17 +118,30 @@ if ! PREV_CHART_VERSION=$(yq '.version' ./packages/rancher-webhook/package.yaml)
exit 1
fi

if [ "$is_prev_rc" = "false" ]; then
# Determine new chart version
if [ "$is_new_minor" = "true" ]; then
if [ "$BUMP_MAJOR" != "true" ]; then
echo "Error: Detected new minor bump ($PREV_WEBHOOK_VERSION to $NEW_WEBHOOK_VERSION), but bump_major flag was not set."
exit 1
fi
NEW_CHART_VERSION=$(bump_major "$PREV_CHART_VERSION")
echo "Bumping chart major: $PREV_CHART_VERSION to $NEW_CHART_VERSION"
COMMIT_MSG="Bump rancher-webhook to $NEW_WEBHOOK_VERSION (chart version major bump)"
elif [ "$is_prev_rc" = "false" ]; then
NEW_CHART_VERSION=$(bump_patch "$PREV_CHART_VERSION")
echo "Bumping chart patch: $PREV_CHART_VERSION to $NEW_CHART_VERSION"
COMMIT_MSG="Bump rancher-webhook to $NEW_WEBHOOK_VERSION (chart version patch bump)"
else
echo "Keeping chart version unchanged: $PREV_CHART_VERSION"
NEW_CHART_VERSION=$PREV_CHART_VERSION
COMMIT_MSG="Bump rancher-webhook to $NEW_WEBHOOK_VERSION (no chart version bump)"
fi

sed -i "s/${PREV_WEBHOOK_VERSION_SHORT}/${NEW_WEBHOOK_VERSION_SHORT}/g" ./packages/rancher-webhook/package.yaml
sed -i "s/${PREV_CHART_VERSION}/${NEW_CHART_VERSION}/g" ./packages/rancher-webhook/package.yaml

git add packages/rancher-webhook
git commit -m "Bump rancher-webhook to $NEW_WEBHOOK_VERSION"
git commit -m "$COMMIT_MSG"

PACKAGE=rancher-webhook make charts
git add ./assets/rancher-webhook ./charts/rancher-webhook index.yaml
Expand Down
64 changes: 58 additions & 6 deletions .github/workflows/scripts/release-against-rancher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,37 @@
# Bumps Webhook version in a locally checked out rancher/rancher repository
#
# Usage:
# ./release-against-rancher.sh <path to rancher repo> <new webhook release>
# ./release-against-rancher.sh <path to rancher repo> <new webhook release> <bump_major>
#
# Example:
# ./release-against-charts.sh "${GITHUB_WORKSPACE}" "v0.5.0-rc.14"
# ./release-against-rancher.sh "${GITHUB_WORKSPACE}" "v0.5.0-rc.14" false

RANCHER_DIR=$1
NEW_WEBHOOK_VERSION=$2 # e.g. v0.5.2-rc.3
BUMP_MAJOR=$3 # must be "true" or "false"

usage() {
cat <<EOF
Usage:
$0 <path to rancher repo> <new webhook release>
$0 <path to rancher repo> <new webhook release> <bump_major>

Arguments:
<path to rancher repo> Path to locally checked out rancher repo
<new webhook release> New Webhook version (e.g. v0.5.0-rc.14, v0.5.0, v0.6.0-rc.0)
<bump_major> Must be "true" if introducing a new Webhook minor version, "false" otherwise.
Example: v0.5.0 → v0.6.0-rc.0 requires bump_major=true.

Examples:
RC to RC: $0 ./rancher v0.5.0-rc.1 false
RC to stable: $0 ./rancher v0.5.0 false
stable → RC: $0 ./rancher v0.5.1-rc.0 false
new minor RC: $0 ./rancher v0.6.0-rc.0 true
EOF
}

# Bumps the patch version of a semver version string
# e.g. 1.2.3 -> 1.2.4
# e.g. 1.2.3-rc.4 -> 1.2.4
bump_patch() {
version=$1
major=$(echo "$version" | cut -d. -f1)
Expand All @@ -27,6 +43,18 @@ bump_patch() {
echo "${major}.${minor}.${new_patch}"
}

# Bumps the major version of a semver version string and resets minor and patch to 0
# e.g. 1.2.3 -> 2.0.0
# e.g. 1.2.3-rc.4 -> 2.0.0
bump_major() {
version=$1
major=$(echo "$version" | cut -d. -f1)
# Increment major, reset minor/patch to 0
new_major=$((major + 1))
echo "${new_major}.0.0"
}

# Validates that the version is in the format v<major>.<minor>.<patch> or v<major>.<minor>.<patch>-rc.<number>
validate_version_format() {
version=$1
if ! echo "$version" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$'; then
Expand All @@ -35,11 +63,16 @@ validate_version_format() {
fi
}

if [ -z "$RANCHER_DIR" ] || [ -z "$NEW_WEBHOOK_VERSION" ]; then
if [ -z "$RANCHER_DIR" ] || [ -z "$NEW_WEBHOOK_VERSION" ] || [ -z "$BUMP_MAJOR" ]; then
usage
exit 1
fi

if [ "$BUMP_MAJOR" != "true" ] && [ "$BUMP_MAJOR" != "false" ]; then
echo "Error: bump_major must be 'true' or 'false', got '$BUMP_MAJOR'"
exit 1
fi

validate_version_format "$NEW_WEBHOOK_VERSION"

# Remove the prefix v because the chart version doesn't contain it
Expand All @@ -56,6 +89,14 @@ if ! PREV_WEBHOOK_VERSION_SHORT=$(yq -r '.webhookVersion' ./build.yaml | sed 's|
exit 1
fi

prev_minor=$(echo "$PREV_WEBHOOK_VERSION_SHORT" | cut -d. -f2)
new_minor=$(echo "$NEW_WEBHOOK_VERSION_SHORT" | cut -d. -f2)

is_new_minor=false
if [ "$new_minor" -gt "$prev_minor" ]; then
is_new_minor=true
fi

if [ "$PREV_WEBHOOK_VERSION_SHORT" = "$NEW_WEBHOOK_VERSION_SHORT" ]; then
echo "Previous and new webhook version are the same: $NEW_WEBHOOK_VERSION, but must be different"
exit 1
Expand All @@ -74,10 +115,21 @@ if ! PREV_CHART_VERSION=$(yq -r '.webhookVersion' ./build.yaml | cut -d+ -f1); t
exit 1
fi

if [ "$is_prev_rc" = "false" ]; then
# Determine new chart version
if [ "$is_new_minor" = "true" ]; then
if [ "$BUMP_MAJOR" != "true" ]; then
echo "Error: Detected new minor bump ($PREV_WEBHOOK_VERSION_SHORT → $NEW_WEBHOOK_VERSION_SHORT), but bump_major flag was not set."
exit 1
fi
NEW_CHART_VERSION=$(bump_major "$PREV_CHART_VERSION")
echo "Bumping chart major: $PREV_CHART_VERSION → $NEW_CHART_VERSION"
COMMIT_MSG="Bump webhook to ${NEW_CHART_VERSION}+up${NEW_WEBHOOK_VERSION_SHORT} (chart version major bump)"
elif [ "$is_prev_rc" = "false" ]; then
NEW_CHART_VERSION=$(bump_patch "$PREV_CHART_VERSION")
COMMIT_MSG="Bump webhook to ${NEW_CHART_VERSION}+up${NEW_WEBHOOK_VERSION_SHORT} (chart version patch bump)"
else
NEW_CHART_VERSION=$PREV_CHART_VERSION
COMMIT_MSG="Bump webhook to ${NEW_CHART_VERSION}+up${NEW_WEBHOOK_VERSION_SHORT} (no chart version bump)"
fi

yq --inplace ".webhookVersion = \"${NEW_CHART_VERSION}+up${NEW_WEBHOOK_VERSION_SHORT}\"" ./build.yaml
Expand All @@ -90,6 +142,6 @@ DAPPER_MODE=bind ./.dapper go generate ./... || true
DAPPER_MODE=bind ./.dapper rm -rf go .config

git add .
git commit -m "Bump webhook to ${NEW_CHART_VERSION}+up${NEW_WEBHOOK_VERSION_SHORT}"
git commit -m "$COMMIT_MSG"

popd > /dev/null