Skip to content

Commit 4bb5c12

Browse files
Add cloud backport tagging workflow (#6896)
## Summary - add workflow to tag merged backport-labeled PRs into cloud/* with cloud/v<package.json version> - 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?
1 parent 8b5cfe7 commit 4bb5c12

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
name: Cloud Backport Tag
3+
4+
on:
5+
pull_request:
6+
types: ['closed']
7+
branches: [cloud/*]
8+
9+
jobs:
10+
create-tag:
11+
if: >
12+
github.event.pull_request.merged == true &&
13+
contains(github.event.pull_request.labels.*.name, 'backport')
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
17+
pull-requests: read
18+
19+
steps:
20+
- name: Checkout merge commit
21+
uses: actions/checkout@v5
22+
with:
23+
ref: ${{ github.event.pull_request.merge_commit_sha }}
24+
25+
- name: Setup Node.js
26+
uses: actions/setup-node@v5
27+
with:
28+
node-version-file: '.nvmrc'
29+
30+
- name: Create tag for cloud backport
31+
id: tag
32+
run: |
33+
set -euo pipefail
34+
35+
BRANCH="${{ github.event.pull_request.base.ref }}"
36+
if [[ ! "$BRANCH" =~ ^cloud/([0-9]+)\.([0-9]+)$ ]]; then
37+
echo "::error::Base branch '$BRANCH' is not a cloud/x.y branch"
38+
exit 1
39+
fi
40+
41+
MAJOR="${BASH_REMATCH[1]}"
42+
MINOR="${BASH_REMATCH[2]}"
43+
44+
VERSION=$(node -p "require('./package.json').version")
45+
if [[ "$VERSION" =~ ^${MAJOR}\.${MINOR}\.([0-9]+)(-.+)?$ ]]; then
46+
PATCH="${BASH_REMATCH[1]}"
47+
SUFFIX="${BASH_REMATCH[2]:-}"
48+
else
49+
echo "::error::Version '${VERSION}' does not match cloud branch '${BRANCH}'"
50+
exit 1
51+
fi
52+
53+
TAG="cloud/v${VERSION}"
54+
55+
if git ls-remote --tags origin "${TAG}" | grep -Fq "refs/tags/${TAG}"; then
56+
echo "::notice::Tag ${TAG} already exists; skipping"
57+
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
58+
exit 0
59+
fi
60+
61+
git tag "${TAG}" "${{ github.event.pull_request.merge_commit_sha }}"
62+
git push origin "${TAG}"
63+
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
64+
{
65+
echo "Created tag: ${TAG}"
66+
echo "Branch: ${BRANCH}"
67+
echo "Version: ${VERSION}"
68+
echo "Commit: ${{ github.event.pull_request.merge_commit_sha }}"
69+
} >> "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)