Skip to content

Commit 08b15a7

Browse files
committed
chore: update changeset job to work with merge queues
The merge group event is triggered on a group of PRs, so the existing approach would fail on looking up the PR number. The job now splits into the merge group context and the single pr context. In the Merge group context, the same check as the single pr approach is applied to each of the PRs in the merge group.
1 parent 1ce47e7 commit 08b15a7

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

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

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

0 commit comments

Comments
 (0)