Skip to content

Commit 99a5705

Browse files
mhuisiclaude
andauthored
chore: backport action (#765)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b883b0b commit 99a5705

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

.github/workflows/backport.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Backport
2+
3+
on:
4+
pull_request_target:
5+
types: [closed, labeled]
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
11+
jobs:
12+
backport:
13+
name: Backport
14+
runs-on: ubuntu-latest
15+
# Fire on merge (for PRs already labeled) and on labels added after merge.
16+
if: |
17+
github.event.pull_request.merged == true && (
18+
(github.event.action == 'closed' && contains(github.event.pull_request.labels.*.name, 'backport')) ||
19+
(github.event.action == 'labeled' && github.event.label.name == 'backport')
20+
)
21+
steps:
22+
- uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Resolve patch-release branch from latest release tag
27+
id: resolve
28+
run: |
29+
# Highest release tag, including pre-releases. The maintainer decides
30+
# at dispatch time whether to cut a `release` or `pre-release` from
31+
# the resulting `patch-release/v<version>` branch.
32+
last_tag="$(git tag --sort=-v:refname --list 'v*' | head -1)"
33+
if [ -z "$last_tag" ]; then
34+
echo "No release tags found." >&2
35+
exit 1
36+
fi
37+
target="patch-release/$last_tag"
38+
echo "last_tag=$last_tag" >> "$GITHUB_OUTPUT"
39+
echo "target=$target" >> "$GITHUB_OUTPUT"
40+
41+
- name: Ensure patch-release branch exists
42+
run: |
43+
target="${{ steps.resolve.outputs.target }}"
44+
last_tag="${{ steps.resolve.outputs.last_tag }}"
45+
if git ls-remote --exit-code --heads origin "$target" >/dev/null; then
46+
echo "Branch $target already exists."
47+
else
48+
echo "Creating $target from $last_tag."
49+
git push origin "refs/tags/$last_tag:refs/heads/$target"
50+
fi
51+
52+
- name: Create backport PR
53+
uses: korthout/backport-action@v3
54+
with:
55+
target_branches: ${{ steps.resolve.outputs.target }}
56+
copy_labels_pattern: '.*'
57+
cherry_picking: 'auto'
58+
merge_commits: 'skip'
59+
pull_description: |-
60+
Backport of #${pull_number} to `${target_branch}`.
61+
62+
Cherry-picked from ${source_sha} (via `git cherry-pick -x`).

.github/workflows/on-push.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,11 @@ jobs:
325325
continue-on-error: true
326326
run: npm publish --workspace=lean4-unicode-input-component --access=public
327327

328+
# `release` and `pre-release` can be dispatched from `master` for regular
329+
# releases, or from a `patch-release/v<release>` branch to cut a patch on top
330+
# of a previous release after master has already advanced. The version bump
331+
# is the global max of all `v*` tags + 1, so patch releases automatically
332+
# take the next patch number and subsequent master releases skip past it.
328333
release:
329334
if: github.event_name == 'workflow_dispatch' && inputs.action == 'release'
330335
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)