Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/backport.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Backport PR

on:
pull_request_target:
types: [closed, labeled]

permissions:
contents: write
pull-requests: write

jobs:
backport:
name: Backport PR
if: >
github.event.pull_request.merged == true
&& contains(join(github.event.pull_request.labels.*.name, ','), 'backport')
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Create backport PRs
uses: korthout/backport-action@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
label_pattern: "^backport-to-(.+)$"
pull_title: "[Backport ${target_branch}] ${pull_title}"
pull_description: |
Backport of #${pull_number} to `${target_branch}`.

---

${pull_description}
merge_commits: "skip"
copy_requested_reviewers: true
copy_assignees: true
copy_labels_pattern: "^(?!backport)"

- name: Report backport status
if: failure()
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const pull_number = context.payload.pull_request.number;

await github.rest.issues.createComment({
owner,
repo,
issue_number: pull_number,
body: `⚠️ **Backport failed!**\n\nThe automatic backport could not be completed. This might be due to merge conflicts.\n\nPlease manually cherry-pick the commits to the target branch:\n\n\`\`\`bash\ngit checkout <target-branch>\ngit cherry-pick -x ${context.payload.pull_request.merge_commit_sha}\n\`\`\`\n\nThen create a new PR targeting the branch.`
});