Skip to content

Commit 7c74f50

Browse files
mikeeegithub-actions[bot]
authored andcommitted
BACKPORT-CONFLICT
1 parent 2e183e1 commit 7c74f50

1 file changed

Lines changed: 93 additions & 0 deletions

File tree

.github/workflows/backport.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Backport merged pull request
2+
3+
on:
4+
pull_request_target:
5+
types: [closed, labeled]
6+
branches:
7+
- main
8+
9+
jobs:
10+
determine-target-branches:
11+
name: Determine target branches
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
if: >-
16+
github.event.pull_request.merged == true
17+
&& (
18+
(
19+
github.event.action == 'closed'
20+
&& contains(toJson(github.event.pull_request.labels.*.name), '"backport-')
21+
)
22+
|| (
23+
github.event.action == 'labeled'
24+
&& startsWith(github.event.label.name, 'backport-')
25+
)
26+
)
27+
outputs:
28+
branches: ${{ steps.backport-labels.outputs.branches }}
29+
steps:
30+
- name: Map backport labels to release branches
31+
id: backport-labels
32+
env:
33+
EVENT_ACTION: ${{ github.event.action }}
34+
LABEL_NAME: ${{ github.event.label.name }}
35+
LABELS_JSON: ${{ toJson(github.event.pull_request.labels.*.name) }}
36+
run: |
37+
python3 <<'PY'
38+
import json
39+
import os
40+
import re
41+
import sys
42+
43+
if os.environ["EVENT_ACTION"] == "labeled":
44+
labels = [os.environ["LABEL_NAME"]]
45+
else:
46+
labels = json.loads(os.environ["LABELS_JSON"])
47+
48+
branches = []
49+
seen = set()
50+
for label in labels:
51+
if not label.startswith("backport-"):
52+
continue
53+
if not re.fullmatch(r"backport-[0-9A-Za-z][0-9A-Za-z._-]*", label):
54+
print(f"::error::Invalid backport label {label!r}. Expected a label like 'backport-0.19'.")
55+
sys.exit(1)
56+
57+
branch = "release-" + label.removeprefix("backport-")
58+
if branch not in seen:
59+
seen.add(branch)
60+
branches.append(branch)
61+
62+
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as output:
63+
print(f"branches={' '.join(sorted(branches))}", file=output)
64+
PY
65+
66+
backport:
67+
name: Backport pull request
68+
runs-on: ubuntu-latest
69+
needs: determine-target-branches
70+
if: needs.determine-target-branches.outputs.branches != ''
71+
permissions:
72+
contents: write
73+
issues: write
74+
pull-requests: write
75+
steps:
76+
- name: Check out trusted base branch
77+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
78+
with:
79+
fetch-depth: 0
80+
repository: ${{ github.event.pull_request.base.repo.full_name }}
81+
ref: refs/heads/${{ github.event.pull_request.base.ref }}
82+
- name: Create backport PRs
83+
uses: korthout/backport-action@66065406958f46e82238fd59546f5a99e69e22aa # v4.5.2
84+
with:
85+
cherry_picking: auto
86+
experimental: '{"conflict_resolution":"draft_commit_conflicts"}'
87+
label_pattern: ''
88+
merge_commits: skip
89+
pull_title: "[Backport ${target_branch}] ${pull_title}"
90+
pull_description: |-
91+
# Description
92+
Backport of #${pull_number} to `${target_branch}`.
93+
target_branches: ${{ needs.determine-target-branches.outputs.branches }}

0 commit comments

Comments
 (0)