diff --git a/.github/workflows/release-charts.yaml b/.github/workflows/release-charts.yaml index acab80838..ab4f05258 100644 --- a/.github/workflows/release-charts.yaml +++ b/.github/workflows/release-charts.yaml @@ -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 }} @@ -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: diff --git a/.github/workflows/release-rancher.yaml b/.github/workflows/release-rancher.yaml index 72acf1c93..a4d8e7b9b 100644 --- a/.github/workflows/release-rancher.yaml +++ b/.github/workflows/release-rancher.yaml @@ -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 }} @@ -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: diff --git a/.github/workflows/scripts/release-against-charts.sh b/.github/workflows/scripts/release-against-charts.sh index 6c90d09b7..d09d0a576 100755 --- a/.github/workflows/scripts/release-against-charts.sh +++ b/.github/workflows/scripts/release-against-charts.sh @@ -3,22 +3,39 @@ # Bumps Webhook version in a locally checked out rancher/charts repository # # Usage: -# ./release-against-charts.sh +# ./release-against-charts.sh # # 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 < + $0 + +Arguments: + Path to locally checked out charts repo + Previous rancher-webhook version (e.g. v0.5.0-rc.13) + New rancher-webhook version (e.g. v0.5.0-rc.14, v0.5.0, v0.6.0-rc.0) + 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) @@ -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.. or v..-rc. validate_version_format() { version=$1 if ! echo "$version" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$'; then @@ -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" @@ -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}" @@ -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 diff --git a/.github/workflows/scripts/release-against-rancher.sh b/.github/workflows/scripts/release-against-rancher.sh index cc9ff3a80..9e792b014 100755 --- a/.github/workflows/scripts/release-against-rancher.sh +++ b/.github/workflows/scripts/release-against-rancher.sh @@ -3,21 +3,37 @@ # Bumps Webhook version in a locally checked out rancher/rancher repository # # Usage: -# ./release-against-rancher.sh +# ./release-against-rancher.sh # # 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 < + $0 + +Arguments: + Path to locally checked out rancher repo + New Webhook version (e.g. v0.5.0-rc.14, v0.5.0, v0.6.0-rc.0) + 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) @@ -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.. or v..-rc. validate_version_format() { version=$1 if ! echo "$version" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$'; then @@ -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 @@ -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 @@ -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 @@ -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