From f070e0405a034c4085f8445a36fc88cd5a3c421a Mon Sep 17 00:00:00 2001 From: Joshua Hoblitt Date: Tue, 28 Jul 2026 13:09:28 -0700 Subject: [PATCH] build: validate the release version before tagging and publishing Nothing verified that the commit being tagged for a release actually carries the intended version. Tagging a release branch before the version update PR is merged publishes images and manifests that reference the previous release. Add build/release/validate-tag.sh to check that the tree is clean and that deploy/examples/images.txt and the helm chart values match the tag, run it from the release build workflow before any artifact is published, and document it in the tagging steps. Alpha tags are exempt as they only mark the creation of a release branch. Signed-off-by: Joshua Hoblitt (cherry picked from commit adda6b17d3583166795a788a5fb38509a076a7a0) # Conflicts: # .github/workflows/push-build.yaml --- .github/workflows/push-build.yaml | 6 ++++ build/release/README.md | 2 ++ build/release/validate-tag.sh | 54 +++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100755 build/release/validate-tag.sh diff --git a/.github/workflows/push-build.yaml b/.github/workflows/push-build.yaml index b1bc5e000..d9b3d97da 100644 --- a/.github/workflows/push-build.yaml +++ b/.github/workflows/push-build.yaml @@ -27,6 +27,12 @@ jobs: with: fetch-depth: 0 + - name: validate release version + if: startsWith(github.ref, 'refs/tags/v') + env: + TAG_NAME: ${{ github.ref_name }} + run: build/release/validate-tag.sh "$TAG_NAME" + - uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0 with: go-version: "1.25" diff --git a/build/release/README.md b/build/release/README.md index 0e855b3ce..26698a5e5 100644 --- a/build/release/README.md +++ b/build/release/README.md @@ -104,6 +104,8 @@ To publish a new patch release build, follow these steps: git reset --hard upstream/$BRANCH_NAME # set to the new release TAG_NAME= # e.g., v1.12.9 + # verify the checkout matches the version being tagged + build/release/validate-tag.sh "$TAG_NAME" git tag -a "$TAG_NAME" -m "$TAG_NAME release tag" git push upstream "$TAG_NAME" ``` diff --git a/build/release/validate-tag.sh b/build/release/validate-tag.sh new file mode 100755 index 000000000..c85ca74a9 --- /dev/null +++ b/build/release/validate-tag.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Verifies that the checked out tree matches the release version being tagged, so that a +# mismatched tag cannot publish artifacts that reference a different version. Run it before +# pushing a release tag; the release build runs it again before publishing anything. + +if [[ $# -ne 1 ]]; then + echo "usage: $0 # e.g., v1.17.2" >&2 + exit 1 +fi +TAG="$1" + +if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-(alpha|beta|rc)\.[0-9]+)?$ ]]; then + echo "error: '$TAG' is not a release version (vX.Y.Z with an optional -alpha/-beta/-rc.N suffix)" >&2 + exit 1 +fi + +cd "$(git rev-parse --show-toplevel)" + +# The alpha tag marks the creation of a release branch and is tagged before the version +# update PR, so the tree is not expected to match it. +if [[ "$TAG" == *"-alpha."* ]]; then + echo "$TAG is an alpha tag; skipping the release version check." + exit 0 +fi + +if [[ -n "$(git status --porcelain --untracked-files=no)" ]]; then + echo "error: the working tree has local modifications, which would taint the version reported by 'git describe'." >&2 + exit 1 +fi + +IMAGE_TAG=$(grep "docker.io/rook/ceph" deploy/examples/images.txt | awk -F : '{ print $2 }') || true +if [[ -z "$IMAGE_TAG" ]]; then + echo "error: could not find the docker.io/rook/ceph image in deploy/examples/images.txt" >&2 + exit 1 +fi +if [[ "$IMAGE_TAG" != "$TAG" ]]; then + echo "error: deploy/examples/images.txt has docker.io/rook/ceph:${IMAGE_TAG}, expected ${TAG}." >&2 + echo "Merge the version update PR (see set-release-ver.sh) to the release branch before tagging ${TAG}." >&2 + exit 1 +fi + +CHART_TAG=$(awk '/repository: docker\.io\/rook\/ceph/{f=1; next} f && /^[[:space:]]*tag:/{print $2; exit}' deploy/charts/rook-ceph/values.yaml) +if [[ -z "$CHART_TAG" ]]; then + echo "error: could not find the docker.io/rook/ceph image tag in deploy/charts/rook-ceph/values.yaml" >&2 + exit 1 +fi +if [[ "$CHART_TAG" != "$TAG" ]]; then + echo "error: deploy/charts/rook-ceph/values.yaml sets the rook image tag to '${CHART_TAG}', expected ${TAG}." >&2 + exit 1 +fi + +echo "OK: the tree matches release version ${TAG}."