Skip to content

Commit 49224cf

Browse files
mihir-kandoimergify[bot]
authored andcommitted
ci: auto merge backports (#54701)
* ci: auto merge backports * ci: add github action to propogate auto-merge label (cherry picked from commit 032a282)
1 parent bbb4e79 commit 49224cf

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Propagate auto-merge label to backports
2+
3+
on:
4+
pull_request:
5+
types: [opened]
6+
7+
jobs:
8+
propagate-label:
9+
runs-on: ubuntu-latest
10+
11+
permissions:
12+
pull-requests: write
13+
issues: write
14+
15+
steps:
16+
- name: Detect backport and original PR (metadata)
17+
id: extract
18+
uses: actions/github-script@v7
19+
with:
20+
script: |
21+
const pr = context.payload.pull_request;
22+
const base = pr.base.ref;
23+
if (!/^version-(15|16)-hotfix$/.test(base)) {
24+
core.setOutput('is_backport', 'false');
25+
return;
26+
}
27+
28+
const isMergify = pr.user && pr.user.login === 'mergify[bot]';
29+
const headRef = pr.head.ref || '';
30+
const match = headRef.match(/(?:^|\/)pr-(\d+)(?:-|$)/i);
31+
32+
if (isMergify && match) {
33+
const original = Number(match[1]);
34+
if (!Number.isNaN(original)) {
35+
core.setOutput('original_pr', String(original));
36+
core.setOutput('is_backport', 'true');
37+
return;
38+
}
39+
}
40+
41+
core.setOutput('is_backport', 'false');
42+
43+
- name: Check original PR labels
44+
if: steps.extract.outputs.is_backport == 'true'
45+
id: check
46+
uses: actions/github-script@v7
47+
with:
48+
script: |
49+
const prNumber = Number("${{ steps.extract.outputs.original_pr }}");
50+
51+
const { data } = await github.rest.issues.get({
52+
owner: context.repo.owner,
53+
repo: context.repo.repo,
54+
issue_number: prNumber
55+
});
56+
57+
const labels = data.labels.map(l => l.name);
58+
core.setOutput("has_auto_merge", labels.includes("auto-merge backports"));
59+
60+
- name: Add auto-merge label to backport PR
61+
if: steps.check.outputs.has_auto_merge == 'true'
62+
uses: actions/github-script@v7
63+
with:
64+
script: |
65+
await github.rest.issues.addLabels({
66+
owner: context.repo.owner,
67+
repo: context.repo.repo,
68+
issue_number: context.payload.pull_request.number,
69+
labels: ["auto-merge"]
70+
});

.mergify.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,18 @@ pull_request_rules:
9292
{{ title }} (#{{ number }})
9393
9494
{{ body }}
95+
- name: Auto merge backports (safe)
96+
conditions:
97+
- label=auto-merge
98+
- base~=^version-(15|16)-hotfix$
99+
- -conflict
100+
- status-success=Python Unit Tests (1)
101+
- status-success=Python Unit Tests (2)
102+
- status-success=Python Unit Tests (3)
103+
- status-success=Python Unit Tests (4)
104+
- status-success=linters
105+
- status-success=semgrep
106+
- status-success=Patch Test
107+
actions:
108+
merge:
109+
method: squash

0 commit comments

Comments
 (0)