|
| 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