forked from fedimint/fedimint
-
Notifications
You must be signed in to change notification settings - Fork 0
64 lines (64 loc) · 2.45 KB
/
backport.yml
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
54
55
56
57
58
59
60
61
62
63
64
name: Backport merged pull request
on:
pull_request_target:
# Run on merge (close) or if label is added after merging
types: [closed, labeled]
# Set concurrenty limit to a single backport workflow per branch
# https://docs.github.com/en/actions/using-jobs/using-concurrency
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
backport:
permissions:
contents: write # so it can comment
pull-requests: write # so it can create pull requests
name: Backport pull request
runs-on: ubuntu-latest
# Don't run on closed unmerged pull requests or if a non-backport label is added
if: |
github.event.pull_request.merged &&
(
github.event.action != 'labeled' ||
contains(github.event.label.name, 'backport')
)
# Save the output from the create-pr step so it can be used in downstream jobs
# https://github.com/korthout/backport-action/blob/e53c7b292aa9985d372c178a89d416ef2176c091/README.md#outputs
outputs:
was_successful: ${{ steps.create-pr.outputs.was_successful }}
steps:
- uses: actions/checkout@v4
- id: create-pr
name: Create backport pull requests
uses: korthout/backport-action@v3
with:
github_token: ${{ secrets.BACKPORT_TOKEN }}
open-issue:
permissions:
contents: read
issues: write
name: Open issue for failed backports
runs-on: ubuntu-latest
needs: backport
# Open an issue only if the backport job failed
if: ${{ needs.backport.outputs.was_successful == 'false' }}
steps:
- uses: actions/checkout@v4
- name: Set SHORT_PR_TITLE env
run: |
# logic to truncate titles needs to be run in a previous step
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
SHORT_PR_TITLE=$(
echo '${{ github.event.pull_request.title }}' \
| awk '{print (length($0) > 40) ? substr($0, 1, 40) "..." : $0}'
)
echo "SHORT_PR_TITLE=$SHORT_PR_TITLE" >> "$GITHUB_ENV"
- name: Create issue
uses: JasonEtco/create-an-issue@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
SHORT_PR_TITLE: ${{ env.SHORT_PR_TITLE }}
with:
filename: .github/templates/failed-backport-issue.md