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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- **`gstack-pr-wait`, `gstack-ci-gate` and the release cut no longer call a commit green while a check on it failed.** They read CI from GitHub's rollup or its default check-runs list, which hold only each check suite's latest attempt, so when a rerun attempt created no jobs the failed run before it disappeared, and a workflow run that failed before creating any job never appeared at all. That is the false green the merge queue had on gstack-evals#303 (#4235). All three now also read CI at the commit through the merge queue's own helper, which reads every attempt and every workflow run, and keep the worse answer per check. So `gstack-pr-wait --until green` blocks with `check failed: checks` and `check failed: sealed (run <id>, no jobs)`, the land gate says `VERDICT FAIL`, and the release cut skips the commit. The release cut now also counts a failed commit status as red, as the merge queue does. A rerun that passed still reads green, and an unreadable read is an error, never a pass (GST-2252).
33 changes: 23 additions & 10 deletions crew/scripts/release-cut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ import * as os from 'node:os';
import * as path from 'node:path';
import { spawnSync } from 'node:child_process';
import { FLOOR_HOURS, IMPORTANT_FLOOR_HOURS, SCHEDULED_GRACE_HOURS, decideDaily, importantChanges, type DailyDecision } from './release-cadence';
import { bucketClass } from '../../lib/ci-gate';
import { headCheckRows, type AsideRuns } from '../../lib/ci-head-checks';

export { FLOOR_HOURS, SCHEDULED_GRACE_HOURS };

Expand Down Expand Up @@ -120,25 +122,33 @@ interface CheckRun { id?: number; name: string; status: string; conclusion: stri
export interface TrainEvidence { bySha: Map<string, string>; byTree: Map<string, string>; release?: Map<string, string> }
export interface GateOptions { requiredCheck?: string; backstopCheck?: string; evidence?: TrainEvidence; treeOf?: (sha: string) => string | null }

/** Why a commit is not releasable, or green and through which evidence. */
/**
* Why a commit is not releasable, or green and through which evidence. Red and running checks also come from CI at the commit as the
* merge queue reads it (lib/ci-head-checks.ts), so a failed check whose rerun attempt created no jobs, or a workflow run that failed
* before any job, is red here too (GST-2252).
*/
export function gateVerdict(gh: Gh, repo: string, sha: string, o: GateOptions = {}): Verdict {
const required = o.requiredCheck ?? REQUIRED_CHECK;
const backstop = o.backstopCheck ?? BACKSTOP_CHECK;
const paged = parseJson<unknown>(gh(['api', '--paginate', '--slurp', `repos/${repo}/commits/${sha}/check-runs?per_page=100`]));
if (!paged) return { green: false, why: 'cannot read its check runs', pending: false };
const pages = (Array.isArray(paged) ? paged : [paged]) as Array<{ check_runs?: CheckRun[] }>;
let runs = pages.flatMap(p => p.check_runs ?? []);
if (runs.some(c => c.status !== 'completed' || RED.has(c.conclusion ?? ''))) {
const setAside = (): AsideRuns => {
const wf = parseJson<unknown>(gh(['api', '--paginate', '--slurp', `repos/${repo}/actions/runs?head_sha=${sha}&per_page=100`]));
const wfRuns = (Array.isArray(wf) ? wf : wf ? [wf] : []) as Array<{ workflow_runs?: Array<{ id?: number; path?: string }> }>;
const asideWorkflows = new Set([CUT_WORKFLOW, ...NEVER_GATING_WORKFLOWS]);
const aside = new Set<number>();
const checkRunIds = new Set<number>();
const workflowRunIds = new Set<number>();
for (const w of wfRuns.flatMap(p => p.workflow_runs ?? []).filter(w => asideWorkflows.has(w.path ?? '') && typeof w.id === 'number')) {
workflowRunIds.add(w.id!);
const jobs = parseJson<unknown>(gh(['api', '--paginate', '--slurp', `repos/${repo}/actions/runs/${w.id}/jobs?filter=all&per_page=100`]));
for (const p of (Array.isArray(jobs) ? jobs : jobs ? [jobs] : []) as Array<{ jobs?: Array<{ id?: number }> }>) for (const j of p.jobs ?? []) if (typeof j.id === 'number') aside.add(j.id);
for (const p of (Array.isArray(jobs) ? jobs : jobs ? [jobs] : []) as Array<{ jobs?: Array<{ id?: number }> }>) for (const j of p.jobs ?? []) if (typeof j.id === 'number') checkRunIds.add(j.id);
}
runs = runs.filter(c => !(typeof c.id === 'number' && aside.has(c.id)));
}
return { checkRunIds, workflowRunIds };
};
let aside = runs.some(c => c.status !== 'completed' || RED.has(c.conclusion ?? '')) ? setAside() : undefined;
if (aside) runs = runs.filter(c => !(typeof c.id === 'number' && aside!.checkRunIds.has(c.id)));
let via = backstop;
for (const name of [required, backstop]) {
const named = runs.filter(c => c.name === name);
Expand All @@ -151,10 +161,13 @@ export function gateVerdict(gh: Gh, repo: string, sha: string, o: GateOptions =
if (named.length === 0) return { green: false, why: `no ${name} check run`, pending: false };
return { green: false, why: `${name} concluded ${named.map(c => c.conclusion).join(',')}`, pending: false };
}
const red = runs.filter(c => c.status === 'completed' && RED.has(c.conclusion ?? ''));
if (red.length > 0) return { green: false, why: `red check runs: ${[...new Set(red.map(c => c.name))].join(', ')}`, pending: false };
const running = runs.filter(c => c.status !== 'completed');
if (running.length > 0) return { green: false, why: `check runs still going: ${[...new Set(running.map(c => c.name))].join(', ')}`, pending: true };
let head = headCheckRows(gh, repo, sha, aside);
if (!aside && 'rows' in head && head.rows.some(r => bucketClass(r.bucket) !== 'pass')) head = headCheckRows(gh, repo, sha, aside = setAside());
if ('error' in head) return { green: false, why: 'cannot read its check runs', pending: false };
const red = [...runs.filter(c => c.status === 'completed' && RED.has(c.conclusion ?? '')).map(c => c.name), ...head.rows.filter(r => bucketClass(r.bucket) === 'fail').map(r => r.name)];
if (red.length > 0) return { green: false, why: `red check runs: ${[...new Set(red)].join(', ')}`, pending: false };
const running = [...runs.filter(c => c.status !== 'completed').map(c => c.name), ...head.rows.filter(r => r.bucket === 'pending').map(r => r.name)];
if (running.length > 0) return { green: false, why: `check runs still going: ${[...new Set(running)].join(', ')}`, pending: true };
return { green: true, via };
}

Expand Down
8 changes: 5 additions & 3 deletions crew/test/release-cadence.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as path from 'node:path';
import { bunIsolationArgs } from '../../lib/bun-isolation';
import { FLOOR_HOURS, FORCED_AFTER_HOURS, IMPORTANT_FLOOR_HOURS, SCHEDULED_GRACE_HOURS, decideDaily, importantChanges, type DailyInput, type ImportantChange } from '../scripts/release-cadence';
import { gitIn, planDaily, type Gh } from '../scripts/release-cut';
import { ciRest, ciShimCases } from '../../test/helpers/ci-attempts-fixture';

const H = 3_600_000;
// Tuesday 2026-11-10 14:00 UTC: not a regular day.
Expand Down Expand Up @@ -138,8 +139,9 @@ const GREEN = [{ name: 'free-tests', status: 'completed', conclusion: 'success'
function fakeGh(pending: Set<string> = new Set()): Gh {
return (args) => {
const api = args[0] === 'api' ? args[args.length - 1]! : '';
const m = /commits\/([0-9a-f]+)\/check-runs/.exec(api);
if (m) return { status: 0, stdout: JSON.stringify([{ check_runs: pending.has(m[1]!) ? [{ name: 'main-backstop', status: 'in_progress', conclusion: null }] : GREEN }]), stderr: '' };
const m = /commits\/([0-9a-f]+)\/|head_sha=([0-9a-f]+)/.exec(api);
const rest = m && ciRest(args, { check_runs: pending.has(m[1] ?? m[2]!) ? [{ name: 'main-backstop', status: 'in_progress', conclusion: null }] : GREEN });
if (rest) return rest;
if (args[0] === 'release' && args[1] === 'view' && args[2] === 'v1.0.0') return { status: 0, stdout: '{}', stderr: '' };
return { status: 1, stdout: '', stderr: 'gh: Not Found (HTTP 404)' };
};
Expand Down Expand Up @@ -245,7 +247,7 @@ describe.skipIf(process.platform === 'win32')('release-cut --daily (the workflow
const r = repo(30);
const shim = path.join(r.root, 'shim');
fs.mkdirSync(shim);
fs.writeFileSync(path.join(shim, 'gh'), '#!/usr/bin/env bash\ncase "$*" in\n *check-runs*) echo \'' + JSON.stringify([{ check_runs: GREEN }]) + '\' ;;\n "release view v1.0.0 "*) echo \'{}\' ;;\n *) exit 1 ;;\nesac\n', { mode: 0o755 });
fs.writeFileSync(path.join(shim, 'gh'), '#!/usr/bin/env bash\ncase "$*" in\n' + ciShimCases(GREEN) + ' "release view v1.0.0 "*) echo \'{}\' ;;\n *) exit 1 ;;\nesac\n', { mode: 0o755 });
const env: Record<string, string | undefined> = { ...process.env, PATH: shim + path.delimiter + process.env.PATH, GITHUB_ACTIONS: 'true' };
for (const k of ['GITHUB_EVENT_NAME', 'GITHUB_STEP_SUMMARY']) delete env[k];
const run = (...args: string[]) => spawnSync(process.execPath, [...bunIsolationArgs(), 'run', path.join(path.resolve(import.meta.dir, '..', '..'), 'crew', 'scripts', 'release-cut.ts'), '--repo', 'o/r', ...args],
Expand Down
Loading
Loading