-
Notifications
You must be signed in to change notification settings - Fork 83
52 lines (48 loc) · 1.48 KB
/
backport-on-label.yml
File metadata and controls
52 lines (48 loc) · 1.48 KB
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
name: Backport on Label
on:
pull_request:
types:
- closed
jobs:
detect:
name: Detect backport labels
runs-on: ubuntu-latest
if: >-
github.event.pull_request.merged == true &&
contains(toJSON(github.event.pull_request.labels.*.name), 'backport-release-')
outputs:
branches: ${{ steps.detect.outputs.branches }}
steps:
- name: Extract target branches from labels
id: detect
env:
LABELS_JSON: ${{ toJSON(github.event.pull_request.labels.*.name) }}
run: |
set -euo pipefail
branches=()
for label in $(echo "$LABELS_JSON" | jq -r '.[]'); do
if [[ "$label" =~ ^backport-(release-[0-9]+\.[0-9]+)$ ]]; then
branches+=("\"${BASH_REMATCH[1]}\"")
fi
done
if [[ ${#branches[@]} -eq 0 ]]; then
echo "branches=[]" >> "$GITHUB_OUTPUT"
else
echo "branches=[$(IFS=,; echo "${branches[*]}")]" >> "$GITHUB_OUTPUT"
fi
backport:
name: Backport to ${{ matrix.target_branch }}
needs: detect
if: needs.detect.outputs.branches != '[]'
permissions:
contents: write
pull-requests: write
strategy:
fail-fast: false
matrix:
target_branch: ${{ fromJSON(needs.detect.outputs.branches) }}
uses: ./.github/workflows/backport.yml
with:
branch_name: ${{ matrix.target_branch }}
pr_number: ${{ github.event.pull_request.number }}
secrets: inherit