1+ name : Backport merged pull request
2+ on :
3+ issue_comment :
4+ types : [created]
5+ permissions :
6+ contents : write # for comment creation on original PR
7+ pull-requests : write
8+ jobs :
9+ backport :
10+ name : Backport pull request
11+ runs-on : ubuntu-latest
12+
13+ # Only run when the comment starts with the `/backport` command on a PR and
14+ # the commenter has write access to the repository. We do not want to allow
15+ # everybody to trigger backports and create branches in our repository.
16+ if : >
17+ github.event.issue.pull_request &&
18+ startsWith(github.event.comment.body, '/backport') &&
19+ (
20+ github.event.comment.author_association == 'OWNER' ||
21+ github.event.comment.author_association == 'COLLABORATOR' ||
22+ github.event.comment.author_association == 'MEMBER'
23+ )
24+ steps :
25+ - uses : actions/checkout@v4
26+ - name : Get backport metadata
27+ # the target branch is the first argument after `/backport`
28+ run : |
29+ set -euo pipefail
30+ body="${{ github.event.comment.body }}"
31+ labels_json='${{ toJSON(github.event.pull_request.labels || github.event.issue.labels) }}'
32+ target=$(echo "$body" | sed -n 's/.*\/backport[[:space:]]\+\([^[:space:]]\+\).*/\1/p')
33+
34+ if [ -z "$target" ]; then
35+ echo "No backport target found in comment." >&2
36+ exit 1
37+ fi
38+ echo "BACKPORT_TARGET=$target" >> $GITHUB_ENV
39+
40+ labels=$(echo "$labels_json" | jq -r 'if . == null then "" else map(.name) | join(",") end')
41+ if [ -z "$labels" ]; then
42+ echo "BACKPORT_PR_LABELS=backport" >> $GITHUB_ENV
43+ else
44+ echo "BACKPORT_PR_LABELS=backport,$labels" >> $GITHUB_ENV
45+ fi
46+ - name : Create backport pull request
47+ uses : korthout/backport-action@v4
48+ with :
49+ add_labels : ${{ env.BACKPORT_PR_LABELS }}
50+ target_branches : ${{ env.BACKPORT_TARGET }}
0 commit comments