Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion build/shared/landing.mts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export type CheckRun = {
status: string;
conclusion: string | null;
detailsUrl?: string;
startedAt?: string;
};

/** What GitHub reports about one commit status, which is the older kind. */
Expand Down Expand Up @@ -130,7 +131,18 @@ export function checksVerdict(
(ownRunId !== '' &&
(run.detailsUrl ?? '').includes(`/actions/runs/${ownRunId}/`)) ||
(ownCheckName !== '' && run.name === ownCheckName);
const runs = all.filter((run) => !isOwn(run));
// A workflow that cancels superseded runs leaves the cancelled one on the
// commit beside the run that replaced it. Both carry the same name, and
// only the newest says how that check turned out.
const newest = new Map<string, CheckRun>();
for (const run of all.filter((run) => !isOwn(run))) {
const seen = newest.get(run.name);
if (seen === undefined || (run.startedAt ?? '') >= (seen.startedAt ?? '')) {
newest.set(run.name, run);
}
}

const runs = [...newest.values()];
const pending = [
...runs.filter((run) => run.status !== 'completed').map((run) => run.name),
...statuses
Expand Down
35 changes: 35 additions & 0 deletions build/shared/landing.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,45 @@ describe('checksVerdict', () => {
conclusion,
});

const at = (
name: string,
conclusion: string | null,
startedAt: string,
status = 'completed'
) => ({ name, conclusion, startedAt, status });

test('says nothing when everything passed', () => {
deepStrictEqual(checksVerdict([run('Lint and test', 'success')], []), '');
});

test('reads only the newest run of a check', () => {
// A workflow that cancels superseded runs leaves the cancelled one on the
// commit beside the run that replaced it.
deepStrictEqual(
checksVerdict(
[
at('Title and description', 'cancelled', '2026-08-24T02:03:54Z'),
at('Title and description', 'success', '2026-08-24T02:03:58Z'),
],
[]
),
''
);
});

test('still reports a check whose newest run failed', () => {
match(
checksVerdict(
[
at('Lint and test', 'success', '2026-08-24T02:00:00Z'),
at('Lint and test', 'failure', '2026-08-24T02:10:00Z'),
],
[]
),
/did not pass: Lint and test/
);
});

test('counts anything still running against it', () => {
// A label applied while a check was in flight says nothing about how that
// check turned out.
Expand Down
2 changes: 1 addition & 1 deletion build/tasks/land-pull-request.mts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const checksRefuse = (sha: string) =>
'api',
`repos/${repository()}/commits/${sha}/check-runs`,
'--jq',
'[.check_runs[] | {name, status, conclusion, detailsUrl: .details_url}]'
'[.check_runs[] | {name, status, conclusion, detailsUrl: .details_url, startedAt: .started_at}]'
)
),
JSON.parse(
Expand Down
Loading