mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-25 01:21:24 +01:00
CI reuse: a neutral run no longer blocks a passing one, and workflow_call checks clear only at the exact commit (GST-3554) (#4713)
A newer CI run that concluded `neutral` no longer blocks reusing a passing run on the same commit, and a check that only runs inside another workflow (`workflow_call`) now clears only from a run that tested your exact commit. Why: gbrain kept hitting `newer_run_vetoes` on passing runs (#9827, #10058, #10021), and a calling workflow's green run from any commit could clear such a check. Nothing to do: gbrain's skipped-run case was already fixed on main by #4695; this adds `neutral`, the exact-commit rule and regression tests built from gbrain's real runs. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/red-team#1 reader=red-team Review-Finding: p1/outside-voice#1 reader=outside-voice
This commit is contained in:
1 parent
00a6b7a353
commit
d3aed00dbe
11 files changed
+422
-11
No files matched your search
+1
-1
@@ -176,7 +176,7 @@ export async function waitForRun(deps: RunDeps, o: { workflow: string; events: s
|
||||
const end = o.clock() + o.timeoutMs;
|
||||
for (;;) {
|
||||
const runs = [o.head, ...(o.also ?? [])].flatMap(h => deps.runsForHead(o.workflow, h)).filter(r => o.events.includes(r.event)).sort(newestFirst);
|
||||
const newest = runs.find(r => !(r.status === 'completed' && r.conclusion === 'skipped')) ?? runs[0];
|
||||
const newest = runs.find(r => !(r.status === 'completed' && (r.conclusion === 'skipped' || r.conclusion === 'neutral'))) ?? runs[0];
|
||||
if (newest?.status === 'completed') {
|
||||
if (newest.conclusion === 'success') return { state: 'green', run: newest };
|
||||
const failing = deps.jobs(newest.id, newest.run_attempt).filter(j => !PASSING.includes(j.conclusion ?? '')).map(j => j.name);
|
||||
|
||||
@@ -371,6 +371,14 @@ export function clearDecision(file: PregateFile, lane: string, input: ClearInput
|
||||
return invalid(`workflow_mismatch — run ${id} attempt ${run?.run_attempt ?? '?'} ran ${run?.path ?? 'an unknown workflow'}, not ${want}${callers.length ? ` or a workflow that calls it (${names})` : ''}`, `clear ${lane} with a run of its own workflow${callers.length ? ` or of a workflow that calls it (${names})` : ''}: ${start}, then gstack-pregate clear --remote ${lane} --run-url <that run's URL>`);
|
||||
}
|
||||
const runOf = caller ?? { file: target.workflow, dispatch };
|
||||
if (caller) {
|
||||
const at = `run ${id} attempt ${run.run_attempt} of ${caller.file}`;
|
||||
const fresh = `${caller.dispatch ? `gh workflow run ${caller.file} --ref <branch>` : `push a commit that starts ${caller.file}`} at ${file.head ? file.head.slice(0, 12) : 'the head'}, then gstack-pregate clear --remote ${lane} --run-url <that run's URL>`;
|
||||
if (run.head_sha !== file.head) return invalid(`head_mismatch — ${at} ran at ${(run.head_sha ?? '').slice(0, 12)}, not pregate.json's head ${file.head ? file.head.slice(0, 12) : '(none recorded)'}, and a caller run clears ${target.workflow} only at that exact head`, file.head ? fresh : `rerun gstack-pregate at the head, then ${fresh}`);
|
||||
if (run.event === 'pull_request') return invalid(`merge_tested — ${at} is a pull_request run, which tested GitHub's merge of the head with its base, not the head itself`, fresh);
|
||||
const tested = git(repoRoot, ['rev-parse', `${run.head_sha}^{tree}`]);
|
||||
if (tested !== file.tree) return invalid(`tree_mismatch — ${at} tested tree ${(tested ?? 'unreadable').slice(0, 12)} at its head, not pregate.json's tree ${file.tree.slice(0, 12)}`, `commit what pregate.json recorded, rerun gstack-pregate, then ${fresh}`);
|
||||
}
|
||||
const green = `then gstack-pregate clear --remote ${lane} --run-url <the green run's URL>`;
|
||||
if (run.status !== 'completed') return invalid(`run_in_progress — run ${id} attempt ${run.run_attempt} is ${run.status}`, `wait for run ${id} to finish green (or rerun ${runOf.file} if it fails), ${green}`);
|
||||
if (run.conclusion !== 'success') return invalid(`run_not_success — run ${id} attempt ${run.run_attempt} concluded ${run.conclusion}`, `rerun ${runOf.file} (gh run rerun ${id}${runOf.dispatch ? `, or gh workflow run ${runOf.file} --ref <branch>` : ''}), ${green}`);
|
||||
|
||||
+3
-1
@@ -173,6 +173,8 @@ export function runProfileErrors(profiles: unknown, gateRuns: unknown): Array<{
|
||||
return errors;
|
||||
}
|
||||
|
||||
/** Newer-run conclusions that never veto: a green run, and a skipped or neutral one, which ran no job that could fail (GST-3514, GST-3554). */
|
||||
const QUIET = ['success', 'skipped', 'neutral'];
|
||||
const fail = (reason: RunRefusal, detail: string, fix?: string): RunVerdict => ({ ok: false, reason, detail, ...(fix ? { fix } : {}) });
|
||||
/** When a run's newest attempt started. A run vetoes the candidate when it started at or after the second the candidate was created: a red re-run of an older run counts, and re-running the candidate does not hide a failure in between. */
|
||||
const started = (r: ApiRun): string => r.run_started_at ?? r.created_at ?? '';
|
||||
@@ -223,7 +225,7 @@ export function verifyRun(deps: RunDeps, o: { repo: string; runRef: string; prof
|
||||
}
|
||||
const heads = [...new Set([run.head_sha, ...(o.vetoHeads ?? []).filter(h => SHA.test(h))])];
|
||||
for (const head of heads) {
|
||||
const newer = deps.runsForHead(p.workflow, head).filter(r => !(r.id === id && r.run_attempt === run.run_attempt) && r.id !== o.ignoreRun && started(r) >= (run.created_at ?? '') && !(r.status === 'completed' && (r.conclusion === 'success' || r.conclusion === 'skipped')));
|
||||
const newer = deps.runsForHead(p.workflow, head).filter(r => !(r.id === id && r.run_attempt === run.run_attempt) && r.id !== o.ignoreRun && started(r) >= (run.created_at ?? '') && !(r.status === 'completed' && QUIET.includes(r.conclusion ?? '')));
|
||||
if (newer.length) return fail('newer_run_vetoes', `newer run ${newer[0]!.id} of ${p.workflow} on ${head.slice(0, 12)} is ${newer[0]!.status === 'completed' ? newer[0]!.conclusion : newer[0]!.status}`);
|
||||
}
|
||||
if (p.skippable && p.skippable.jobs.every(j => skippedJobs.includes(j)) && o.docsOnly?.(run.head_sha)) {
|
||||
|
||||
Reference in new issue
Block a user