Skip to content

Commit 121ddbd

Browse files
authored
actions: Adds backport github action (#1058)
Sets default action parameters explicitly. In order to backport a PR, the PR should have the an appropriate label: "backport branch-name" (e.g.: "backport 1.32"). When the PR merges, the github action will automatically backport it. The label can also be added after the PR merges, after which a user should comment /backport in order to trigger the action. The github-actions bot does not trigger any other CI workflows, but we'd like to have tests running for the backports as well. Which is why the backports will be made with a different account. Additionally, we're now adding the "automerge" label to the new backports, allowing the automerger action to merge the PR once the tests pass.
1 parent e84e8c5 commit 121ddbd

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

.github/workflows/backport.yaml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Backport merged pull request
2+
on:
3+
pull_request_target:
4+
types: [closed]
5+
issue_comment:
6+
types: [created]
7+
permissions:
8+
contents: write # so it can comment
9+
pull-requests: write # so it can create pull requests
10+
jobs:
11+
backport:
12+
name: Backport pull request
13+
runs-on: ubuntu-latest
14+
15+
# Only run when pull request is merged
16+
# or when a comment containing `/backport` is created by someone other than the
17+
# https://github.com/backport-action bot user (user id: 97796249). Note that if you use your
18+
# own PAT as `github_token`, that you should replace this id with yours.
19+
# cdkbot's user ID is 99445902.
20+
if: >
21+
(
22+
github.event_name == 'pull_request_target' &&
23+
github.event.pull_request.merged
24+
) || (
25+
github.event_name == 'issue_comment' &&
26+
github.event.issue.pull_request &&
27+
github.event.comment.user.id != 99445902 &&
28+
contains(github.event.comment.body, '/backport')
29+
)
30+
steps:
31+
- uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0
34+
35+
- name: Create backport pull requests
36+
id: create_backports
37+
uses: korthout/backport-action@v3
38+
with:
39+
# Set (default) action parameters explicitly.
40+
branch_name: backport-${pull_number}-to-${target_branch}
41+
cherry_picking: auto
42+
copy_assignees: false
43+
copy_milestone: false
44+
copy_requested_reviewers: false
45+
experimental: >
46+
{
47+
"conflict_resolution": "fail"
48+
}
49+
github_token: ${{ secrets.BOT_TOKEN }}
50+
github_workspace: ${{ github.workspace }}
51+
label_pattern: ^backport ([^ ]+)$
52+
merge_commits: fail
53+
pull_description: |-
54+
# Description
55+
Backport of #${pull_number} to `${target_branch}`.
56+
pull_title: >-
57+
[Backport ${target_branch}] ${pull_title}
58+
59+
- name: Label backports with automerge and approve
60+
env:
61+
GH_TOKEN: ${{ github.token }}
62+
run: |
63+
for pr_number in ${{ steps.create_backports.outputs.created_pull_numbers }}; do
64+
gh pr edit "$pr_number" --add-label "automerge"
65+
gh pr review "$pr_number" --approve
66+
done

0 commit comments

Comments
 (0)