Skip to content

Commit d8509ff

Browse files
authored
Merge pull request #6434 from NomicFoundation/changeset-check
ci: run the changeset check in the merge queue
2 parents 25067ca + 8ff58ca commit d8509ff

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

.github/workflows/check-changeset-added.yml

+65
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
name: Check that the PR has a changeset
55

66
on:
7+
merge_group:
78
pull_request:
89
branches:
910
- main
@@ -25,6 +26,70 @@ jobs:
2526
- uses: actions/github-script@v7
2627
with:
2728
script: |
29+
const isMergeGroup = context.eventName === "merge_group";
30+
31+
// Merge group context
32+
if (isMergeGroup) {
33+
console.log("Merge group context");
34+
console.log(context)
35+
36+
console.log("Running in merge_group context...");
37+
const { data: mergeQueue } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
38+
owner: context.repo.owner,
39+
repo: context.repo.repo,
40+
commit_sha: context.sha
41+
});
42+
43+
if (mergeQueue.length === 0) {
44+
console.log("No associated PRs found for this merge_group commit.");
45+
process.exit(1);
46+
}
47+
48+
console.log(`Found ${mergeQueue.length} PR(s) in the merge group.`);
49+
50+
for (const pr of mergeQueue) {
51+
const pullNumber = context.issue.number;
52+
53+
console.log(`Checking PR #${pr.number}...`);
54+
const { data: files } = await github.rest.pulls.listFiles({
55+
owner: context.repo.owner,
56+
repo: context.repo.repo,
57+
pull_number: pullNumber
58+
});
59+
60+
const changeset = files.find(
61+
file => file.status === "added" && file.filename.startsWith(".changeset/")
62+
);
63+
64+
if (changeset !== undefined) {
65+
console.log(`PR #${pr.number} has a changeset: ${changeset.filename}`);
66+
continue;
67+
}
68+
69+
console.log(`PR #${pr.number} has no changeset.`);
70+
71+
const { data: prDetails } = await github.rest.pulls.get({
72+
owner: context.repo.owner,
73+
repo: context.repo.repo,
74+
pull_number: pullNumber
75+
});
76+
77+
const noChangesetNeededLabel = prDetails.labels.some(l => l.name === "no changeset needed");
78+
79+
if (noChangesetNeededLabel) {
80+
console.log(`PR #${pr.number} is labeled as "no changeset needed".`);
81+
continue;
82+
}
83+
84+
console.log(`PR #${pr.number} is not labeled as "no changeset needed". Failing job.`);
85+
process.exit(1);
86+
}
87+
88+
console.log("All PRs in the merge group have a changeset or are labeled correctly.");
89+
return;
90+
}
91+
92+
// Single PR context
2893
const pullNumber = context.issue.number;
2994
3095
const { data: files } = await github.rest.pulls.listFiles({

0 commit comments

Comments
 (0)