-
Notifications
You must be signed in to change notification settings - Fork 602
70 lines (62 loc) · 2.2 KB
/
backport-fixup.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
65
66
67
68
69
70
# Fixes up Mergify-created backport PRs to include necessary labels and other
# information for release notes generation.
# This action formerly copied over the PR body but it seems Mergify does that
# itself now.
name: Backport Fixup
on:
pull_request:
types: [opened]
workflow_dispatch:
inputs:
pr:
description: 'Number of the Pull Request to Fixup'
require: true
permissions:
pull-requests: write
contents: write
jobs:
resolve_prs:
name: Resolve PRs
runs-on: ubuntu-22.04
# If triggering PR actually is a backport, then original_pr will be set
outputs:
backport_pr: ${{ steps.backport.outputs.pr }}
original_pr: ${{ steps.original.outputs.pr }}
steps:
- uses: actions/checkout@v4
- name: Figure out backport PR number
id: backport
run: |
if [[ -z "${{ inputs.pr }}" ]]; then
echo "pr=${{ github.event.number }}" >> "$GITHUB_OUTPUT"
else
echo "pr=${{ inputs.pr }}" >> "$GITHUB_OUTPUT"
fi
- name: Figure out original PR number (if one exists)
id: original
env:
GH_TOKEN: ${{ github.token }}
run: |
BP_PR=${{ steps.backport.outputs.pr }}
TITLE=$(gh pr view --json title --jq '.title' $BP_PR)
if [[ "$TITLE" =~ \(backport\ #([0-9]+)\) ]]; then
echo "pr=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT"
else
echo "$BP_PR is not a backport PR!" >> $GITHUB_STEP_SUMMARY
fi
fixup_backport:
name: Fixup the backport PR
runs-on: ubuntu-22.04
needs: [resolve_prs]
if: ${{ needs.resolve_prs.outputs.original_pr }}
steps:
- uses: actions/checkout@v4
- name: Copy over labels
env:
GH_TOKEN: ${{ github.token }}
run: |
BP_PR=${{ needs.resolve_prs.outputs.backport_pr }}
ORIG_PR=${{ needs.resolve_prs.outputs.original_pr }}
# Long line but the paste joining must be done right away or we run into issues with spaces in labels
LABELS=$(gh pr view --json labels --jq '.labels | .[].name | select(. != "Backported")' $ORIG_PR | paste -sd "," -)
gh pr edit $BP_PR --add-label "$LABELS"