-
Notifications
You must be signed in to change notification settings - Fork 446
54 lines (44 loc) · 1.93 KB
/
backport.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
name: Automatic backport action
on:
pull_request_target:
types: ["labeled", "closed"]
jobs:
backport:
name: Backport PR
if: github.event.pull_request.merged == true && !(contains(github.event.pull_request.labels.*.name, 'backport'))
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install GH CLI
uses: dev-hanz-ops/[email protected]
- name: Fetch PR description and update backportrc
env:
GH_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
run: |
# Grab raw original PR body, gh CLI uses the default token.
BODY_CONTENT="$(gh api "/repos/$REPO/pulls/$PR_NUMBER" | jq -r .body)"
# Escape the markdown content so that sed can produce valid JSON.
# Remove starting and ending quites and replace new lines with literals.
ESCAPED_CONTENT=$(echo "$BODY_CONTENT" | jq -aRs .)
ESCAPED_CONTENT="${ESCAPED_CONTENT%\"}"
ESCAPED_CONTENT="${ESCAPED_CONTENT#\"}"
ESCAPED_CONTENT=$(echo "$ESCAPED_CONTENT" | sed 's/[\/&]/\\&/g')
# sourcePullRequest is an actual variable, but the PR description is not provided by the action or the CLI.
# Instead we are using it as a substitution target and replacing it with the markdown content.
sed -i "s/{{sourcePullRequest}}/$ESCAPED_CONTENT/g" .backportrc.json
- name: Backport Action
uses: sorenlouv/[email protected]
with:
github_token: ${{ secrets.GH_ACCESS_TOKEN }}
auto_backport_label_prefix: backport-to-
- name: Info log
if: ${{ success() }}
run: cat ~/.backport/backport.info.log
- name: Debug log
if: ${{ failure() }}
run: cat ~/.backport/backport.debug.log