Skip to content

Commit 999f23b

Browse files
authored
Enforce all PRs are labeled for Release Note generation (#3181)
This reads the release notes config to generate a list of expected labels. It then compares the list of labels set on the PR and checks to make sure the PR has one of the labels provided. Not in this PR: in theory, there are some GraphQL queries we could run so that if we have an associated issue, we could try and guess the label from the issue. This keeps it simple, though, and just makes sure that the label has been set. If the check fails, it should be a pretty straightforward and fast thing to fix.
1 parent 736abec commit 999f23b

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

.github/workflows/pr_labels.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Pull Request Labels
2+
3+
on:
4+
pull_request:
5+
types: [opened, labeled, unlabeled]
6+
7+
jobs:
8+
labels:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
checks: write
12+
contents: read
13+
pull-requests: read
14+
steps:
15+
- name: Checkout sources
16+
uses: actions/[email protected]
17+
with:
18+
sparse-checkout: build/release-notes-config.json
19+
- name: Check Labels
20+
uses: actions/github-script@v7
21+
with:
22+
script: |
23+
// Gather required labels from release notes configuration
24+
const releaseNotesConfig = require('./build/release-notes-config.json');
25+
var requiredLabels = new Set();
26+
releaseNotesConfig.categories
27+
.flatMap(category => category.labels)
28+
.forEach(label => requiredLabels.add(label));
29+
30+
// Check if the current PR has a label in the required set
31+
const pr_labels = context.payload.pull_request.labels.map(l => l.name);
32+
if (!pr_labels.some(l => requiredLabels.has(l))) {
33+
core.setFailed("PR is not labeled with any of the required labels: " + JSON.stringify(Array.from(requiredLabels)));
34+
}

build/release-notes-config.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{"categories":
2+
[
3+
{"title": "Breaking Changes",
4+
"labels": ["breaking change"]},
5+
{"title": "New Features",
6+
"labels": ["enhancement"]},
7+
{"title": "Bug Fixes",
8+
"labels": ["bug fix"]},
9+
{"title": "Performance Improvements",
10+
"labels": ["performance"]},
11+
{"title": "Dependency Updates",
12+
"labels": ["dependencies"]},
13+
{"title": "Build/Test/Documentation Improvements",
14+
"collapsed": true,
15+
"labels": [
16+
"build improvement",
17+
"documentation",
18+
"testing improvement"]}
19+
],
20+
"catch_all": "Other Changes"
21+
}

0 commit comments

Comments
 (0)