Skip to content

Commit 6ce320a

Browse files
committed
ci: address the fourth round of review comments
- Update the Rust (fork) check a commit already has instead of adding a second one, when a pull request of the same branch to a release branch or a reopened pull request signals that commit again. - Log every failed lookup and label of the release version labeler with its commit or pull request. - Note in the signal workflow that skip markers in the head commit skip it, and that a re-run of it does not send requested.
1 parent aa555be commit 6ce320a

5 files changed

Lines changed: 55 additions & 8 deletions

File tree

‎.github/workflows/fork_ci_status.yml‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,19 @@ jobs:
235235
core.info('Not a fork pull request to main; nothing to mirror.');
236236
return;
237237
}
238+
// A pull request of the same branch to a release branch, or a
239+
// reopened pull request, signals a commit that can already have
240+
// the check. Update that check instead of adding a second one.
241+
const { data } = await github.rest.checks.listForRef({
242+
...upstream,
243+
ref: pr.head.sha,
244+
check_name: CHECK,
245+
per_page: 1,
246+
});
247+
if (data.check_runs.length > 0) {
248+
await syncCheck(pr);
249+
return;
250+
}
238251
await createCheck(pr, 12);
239252
}
240253

‎.github/workflows/pull_request_signal.yml‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@
1515
# They trigger on the `requested` event of this workflow. GitHub sends it at
1616
# once for every run, even one that waits for the approval of a first-time
1717
# contributor. This is not documented, but it is seen in
18-
# apache/spark-kubernetes-operator, which uses the same pattern.
18+
# apache/spark-kubernetes-operator, which uses the same pattern. GitHub does not
19+
# send `requested` when this workflow is re-run, so push to the pull request, or
20+
# close and reopen it, to run them again.
1921
#
2022
# A pull request runs its own copy of this file, so it can change or delete it.
2123
# That only skips the labels and the immediate `Rust (fork)` check for that pull
2224
# request. GitHub also skips `pull_request` workflows while a pull request has
23-
# merge conflicts, so such a pull request gets its labels after a push that
24-
# resolves them. The scheduled update in `fork_ci_status.yml` creates the check
25-
# in both cases, and the merge queue stays the gate.
25+
# merge conflicts, or when its head commit message has `[skip ci]` or another
26+
# skip marker, so such a pull request gets its labels with a later push. The
27+
# scheduled update in `fork_ci_status.yml` creates the check in all of these
28+
# cases, and the merge queue stays the gate.
2629
name: Pull request signal
2730

2831
on:

‎ci/scripts/release_version_labeler.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module.exports = async ({ github, context }) => {
5151
// A push can include several merged pull requests. Look the commits up a
5252
// batch at a time, so the retries of commits without one overlap. A failed
5353
// lookup or label must not cost the other pull requests their label, so
54-
// collect the errors and throw the first one after labeling.
54+
// log every error and throw the first one after labeling.
5555
const pushed = (context.payload.commits || []).map((commit) => commit.id);
5656
const shas = pushed.length ? pushed : [context.sha];
5757
const numbers = new Set();
@@ -61,13 +61,14 @@ module.exports = async ({ github, context }) => {
6161
const settled = await Promise.allSettled(
6262
batch.map((sha) => mergedPulls({ github, context, sha }))
6363
);
64-
for (const result of settled) {
64+
settled.forEach((result, index) => {
6565
if (result.status === 'fulfilled') {
6666
result.value.forEach((pull) => numbers.add(pull.number));
6767
} else {
68+
console.log(`Looking up ${batch[index]} failed: ${result.reason}`);
6869
errors.push(result.reason);
6970
}
70-
}
71+
});
7172
}
7273
if (numbers.size === 0 && errors.length === 0) {
7374
console.log(`No merged pull request found for ${shas.join(', ')}`);
@@ -81,11 +82,12 @@ module.exports = async ({ github, context }) => {
8182
labels: [target_version]
8283
});
8384
} catch (error) {
85+
console.log(`Labeling #${number} failed: ${error}`);
8486
errors.push(error);
8587
}
8688
}
8789
if (errors.length > 0) {
88-
console.log(`${errors.length} request(s) failed. The pull requests that were found are labeled.`);
90+
console.log(`${errors.length} request(s) failed, see above.`);
8991
throw errors[0];
9092
}
9193
};

‎ci/scripts/test_fork_ci_status.cjs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,21 @@ test("notification mirrors the pull request to main when a newer one targets a r
190190
assertRun(writes[0], "create", latest);
191191
});
192192

193+
test("notification updates the check a commit already has instead of adding one", async () => {
194+
// A pull request of the same branch to a release branch signals the commit
195+
// of the pull request to main.
196+
const release = { ...pr, number: 2, base: { ref: "branch-55" } };
197+
const latest = run(2, "workflow_dispatch");
198+
const writes = await execute({
199+
event: "workflow_run",
200+
check: checkFor(run(1)),
201+
openPrs: [release, pr],
202+
runs: [latest],
203+
});
204+
assert.equal(writes.length, 1);
205+
assertRun(writes[0], "update", latest);
206+
});
207+
193208
test("notification skips a commit that is no longer a pull request head", async () => {
194209
const writes = await execute({
195210
event: "workflow_run",

‎ci/scripts/test_release_version_labeler.cjs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,17 @@ test("labels the other pull requests when one label fails, then fails the run",
199199
[2]
200200
);
201201
});
202+
203+
test("logs every failed request with its commit or pull request", async () => {
204+
const { result, error } = await run({
205+
commits: ["a", "b"],
206+
lookups: { a: new Error("rate limited"), b: [[pull(2)]] },
207+
failLabels: [2],
208+
});
209+
assert.equal(error.message, "rate limited");
210+
assert.deepEqual(result.logs, [
211+
"Looking up a failed: Error: rate limited",
212+
"Labeling #2 failed: Error: cannot label 2",
213+
"2 request(s) failed, see above.",
214+
]);
215+
});

0 commit comments

Comments
 (0)