From 4bb5c12fac85660fb7250aa78de58ad06dfc19b4 Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Mon, 24 Nov 2025 22:56:33 -0800 Subject: [PATCH] Add cloud backport tagging workflow (#6896) ## Summary - add workflow to tag merged backport-labeled PRs into cloud/* with cloud/v - validate branch/version alignment and skip when tag already exists - use .nvmrc (Node 24) for setup-node ## Question - This workflow expects the version bump to already be in the PR when you merge, as it fails if the tag already exists to keep immutability. Should we autobump in this case? --- .github/workflows/cloud-backport-tag.yaml | 69 +++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 .github/workflows/cloud-backport-tag.yaml diff --git a/.github/workflows/cloud-backport-tag.yaml b/.github/workflows/cloud-backport-tag.yaml new file mode 100644 index 000000000..c0edec170 --- /dev/null +++ b/.github/workflows/cloud-backport-tag.yaml @@ -0,0 +1,69 @@ +--- +name: Cloud Backport Tag + +on: + pull_request: + types: ['closed'] + branches: [cloud/*] + +jobs: + create-tag: + if: > + github.event.pull_request.merged == true && + contains(github.event.pull_request.labels.*.name, 'backport') + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: read + + steps: + - name: Checkout merge commit + uses: actions/checkout@v5 + with: + ref: ${{ github.event.pull_request.merge_commit_sha }} + + - name: Setup Node.js + uses: actions/setup-node@v5 + with: + node-version-file: '.nvmrc' + + - name: Create tag for cloud backport + id: tag + run: | + set -euo pipefail + + BRANCH="${{ github.event.pull_request.base.ref }}" + if [[ ! "$BRANCH" =~ ^cloud/([0-9]+)\.([0-9]+)$ ]]; then + echo "::error::Base branch '$BRANCH' is not a cloud/x.y branch" + exit 1 + fi + + MAJOR="${BASH_REMATCH[1]}" + MINOR="${BASH_REMATCH[2]}" + + VERSION=$(node -p "require('./package.json').version") + if [[ "$VERSION" =~ ^${MAJOR}\.${MINOR}\.([0-9]+)(-.+)?$ ]]; then + PATCH="${BASH_REMATCH[1]}" + SUFFIX="${BASH_REMATCH[2]:-}" + else + echo "::error::Version '${VERSION}' does not match cloud branch '${BRANCH}'" + exit 1 + fi + + TAG="cloud/v${VERSION}" + + if git ls-remote --tags origin "${TAG}" | grep -Fq "refs/tags/${TAG}"; then + echo "::notice::Tag ${TAG} already exists; skipping" + echo "tag=${TAG}" >> "$GITHUB_OUTPUT" + exit 0 + fi + + git tag "${TAG}" "${{ github.event.pull_request.merge_commit_sha }}" + git push origin "${TAG}" + echo "tag=${TAG}" >> "$GITHUB_OUTPUT" + { + echo "Created tag: ${TAG}" + echo "Branch: ${BRANCH}" + echo "Version: ${VERSION}" + echo "Commit: ${{ github.event.pull_request.merge_commit_sha }}" + } >> "$GITHUB_STEP_SUMMARY"