-
-
Notifications
You must be signed in to change notification settings - Fork 49
80 lines (73 loc) · 2.75 KB
/
Copy pathbackport.yml
File metadata and controls
80 lines (73 loc) · 2.75 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
name: Backport merged PR
on:
pull_request_target:
types:
- closed
- labeled
permissions:
contents: write
pull-requests: write
jobs:
backport:
name: Backport merged PR
runs-on: ubuntu-latest
# closed: when PR is merged with label `backport *`
# labeled: when `backport *` label is added to a merged PR
if: >
(github.event.action == 'closed' &&
github.event.pull_request.merged == true &&
contains(join(github.event.pull_request.labels.*.name, ' '), 'backport '))
||
(github.event.action == 'labeled' &&
github.event.pull_request.merged == true &&
startsWith(github.event.label.name, 'backport '))
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Expand backport label into target branches
id: targets
uses: actions/github-script@v8
with:
script: |
// definitions
const labelPattern = /^backport (.+)$/
const esBranches = ["es-9", "es-8.18-plus", "es-8.10-8.17"]
const osBranches = ["os-3", "os-2.6-plus"]
const groups = {
"es": esBranches,
"os": osBranches,
"all": [...esBranches, ...osBranches],
}
const labels = new Set(
(context.payload.pull_request.labels || []).map(l => l.name)
)
const targets = new Set()
for (const label of labels) {
const m = labelPattern.exec(label)
if (!m) continue
const key = m[1]
if (groups[key]) {
for (const branch of groups[key]) {
targets.add(branch)
}
} else {
targets.add(key)
}
}
core.setOutput("target_branches", Array.from(targets).join(" "))
- name: Create backport PRs
id: backport
# Keep third-party actions pinned to a commit SHA for supply-chain safety.
# https://github.com/korthout/backport-action/releases/tag/v4.5.2
uses: korthout/backport-action@4aaf0e03a94ff0a619c9a511b61aeb42adea5b02
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# Target branches are resolved by the github-script step above.
# Disable the action's own label parsing so shorthand keys such as
# "all" are not treated as literal branch names.
label_pattern: '^$'
target_branches: ${{ steps.targets.outputs.target_branches }}
branch_name: 'backport/${target_branch}/${pull_number}'
pull_title: '[Backport ${target_branch}] #${pull_number} ${pull_title}'
experimental: >-
{ "conflict_resolution": "draft_commit_conflicts" }