Skip to content

Commit 3e117e7

Browse files
committed
Refactor GitHub Actions workflow to improve label checking and backport PR handling
1 parent d875227 commit 3e117e7

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

.github/workflows/labels.yml

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33

4-
name: Verify PR Labels
4+
name: Check Labels
55

66
on:
77
pull_request:
@@ -10,16 +10,52 @@ on:
1010
permissions:
1111
contents: read
1212
pull-requests: read
13+
issues: write
1314

1415
jobs:
16+
label-backport-prs:
17+
permissions:
18+
contents: read
19+
pull-requests: read
20+
issues: write
21+
22+
name: Label Backport PRs
23+
if: github.repository_owner == 'PowerShell' && github.event.action == 'opened' && startsWith(github.event.pull_request.base.ref, 'release/v') && startsWith(github.event.pull_request.title, '[release/v')
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- name: Label Original PRs if backport PR
28+
continue-on-error: true
29+
if: ${{ github.event.action == 'opened' && startsWith(github.event.pull_request.base.ref, 'release/v') && startsWith(github.event.pull_request.title, '[release/v') }}
30+
uses: actions/github-script@v7
31+
with:
32+
script: |
33+
const description = github.event.pull_request.body || '';
34+
const branch = github.event.pull_request.base.ref;
35+
const match = description.match(/\$\$\$originalprnumber:(\d+)\$\$\$/);
36+
if (match) {
37+
const originalPrNumber = match[1];
38+
console.log(`Original PR number found: ${originalPrNumber}`);
39+
40+
const labelName = branch.replace('release/v', 'backport-') + '.x-migrated';
41+
console.log(`labelName: ${labelName}`);
42+
43+
await github.issues.addLabels({
44+
owner: context.repo.owner,
45+
repo: context.repo.repo,
46+
issue_number: originalPrNumber,
47+
labels: [labelName]
48+
});
49+
} else {
50+
console.log("No original PR number found in the description.");
51+
}
52+
1553
verify-labels:
54+
name: Verify Change Log Labels
1655
if: github.repository_owner == 'PowerShell'
1756
runs-on: ubuntu-latest
1857

1958
steps:
20-
- name: Check out the repository
21-
uses: actions/checkout@v4
22-
2359
- name: Verify PR has label starting with 'cl-'
2460
id: verify-labels
2561
uses: actions/github-script@v7
@@ -28,4 +64,5 @@ jobs:
2864
const labels = context.payload.pull_request.labels.map(label => label.name.toLowerCase());
2965
if (!labels.some(label => label.startsWith('cl-'))) {
3066
core.setFailed("Every PR must have at least one label starting with 'cl-'.");
31-
}
67+
68+

0 commit comments

Comments
 (0)