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
9 changes: 4 additions & 5 deletions .github/workflows/ci-ok-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ name: CI verdict
# GitHub always loads a `workflow_run` workflow from the default branch. This
# one reads the finished `CI` run's job results, evaluates them with the default
# branch's required list and classifier, and publishes the `ci-ok` check run
# itself. The in-run aggregate inside `ci.yml` keeps publishing `ci-ok` for one
# step, because on the pull request that adds this file there would otherwise be
# no `ci-ok` at all and the change could never merge. Every check run at the head
# sha counts, so the head's green cannot retire this red one; a follow-up renames
# the in-run job to `ci-ok-head`, leaving one producer.
# itself. #1273 renamed the in-run aggregate inside `ci.yml` to `ci-ok-head`, so
# `ci-ok` has exactly one producer — this verdict — and every check run at the
# head sha still counts: no green can retire a red one. While a required context
# is still unsettled this job publishes nothing at all and logs `pending`.

on:
workflow_run:
Expand Down
20 changes: 11 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,8 @@ jobs:
fi
exit "$status"

ci-ok:
name: ci-ok
ci-ok-head:
name: ci-ok-head
if: always()
needs: [changes, lint, typecheck, test, coverage, build, visual, docker, audit, dependency-review, changelog, version, risk, restore-drill, action-pins, workflow-lint, reserved-contexts, secret-scan, codeql-required, mock-check, deploy-check]
runs-on: ubuntu-latest
Expand Down Expand Up @@ -886,22 +886,24 @@ jobs:
GITHUB_EVENT_NAME: ${{ github.event_name }}
run: node base/scripts/ci-ok.mjs

# #305: a red `main` used to be invisible. `ci-ok` computed the commit's
# #305: a red `main` used to be invisible. The aggregate computed the commit's
# health and stopped, no job held a write scope on issues, and the branch was
# noticed only by a person who went and looked. This is the one job allowed to write,
# and it writes one issue: create it, comment on it, or close it. Every
# decision is `scripts/lib/main-health.mjs`; the job only gathers the input.
#
# It is deliberately not in `ci-ok`'s `needs`: a reporter that fails must not
# be able to fail the merge gate as well.
# It is deliberately not in `ci-ok-head`'s `needs`: a reporter that fails must
# not be able to fail the merge gate as well.
#
# Its `needs` mirrors `ci-ok`'s so the tracker can name the jobs that actually
# failed. With only `ci-ok` in the list the reporter saw the aggregate and
# nothing else, and every tracker said "ci-ok did not report success".
# Its `needs` mirrors `ci-ok-head`'s so the tracker can name the jobs that
# actually failed. With only the aggregate in the list the reporter saw the
# aggregate and nothing else, and every tracker said it did not report success.
# The reporter reads the aggregate by the job id it has here, so #1273's
# rename moves both sides together.
main-health:
name: main-health
if: always() && github.ref == 'refs/heads/main'
needs: [ci-ok, changes, lint, typecheck, test, coverage, build, visual, docker, audit, dependency-review, changelog, version, risk, restore-drill, action-pins, workflow-lint, reserved-contexts, secret-scan, codeql-required, mock-check, deploy-check]
needs: [ci-ok-head, changes, lint, typecheck, test, coverage, build, visual, docker, audit, dependency-review, changelog, version, risk, restore-drill, action-pins, workflow-lint, reserved-contexts, secret-scan, codeql-required, mock-check, deploy-check]
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
Expand Down
1 change: 1 addition & 0 deletions changelog.d/1273.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A required context that GitHub reports as still running is now `pending` instead of `missing`: the publisher creates no `ci-ok` check run while any required job is unsettled, and the published summary lists every conclusion it saw per context so a re-run can be told from a job that never reported. The in-run aggregate is renamed to `ci-ok-head`, leaving `ci-ok` with one producer.
29 changes: 13 additions & 16 deletions docs/autonomous-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,11 @@ as the checks API reports them, in
[`.github/agent/required-checks.md`](../.github/agent/required-checks.md); that
file is the record and not the gate — branch protection is an owner action.

`ci-ok` is also published by `ci-ok-publish.yml`, a `workflow_run` workflow that
`ci-ok` is published by `ci-ok-publish.yml`, a `workflow_run` workflow that
GitHub always takes from the default branch, so the copy that judges a change is
never the one under test. The aggregate job inside `ci.yml` keeps publishing the
same context for one step — the pull request that adds the publisher would
otherwise carry no `ci-ok` and could never merge; every check run at the head sha
counts, so the head's green cannot retire the publisher's red — and a follow-up
renames it to `ci-ok-head`. See
never the one under test. The aggregate job inside `ci.yml` is `ci-ok-head` since
`#1273`, so the required context has one producer; every check run at the head sha
counts, so the head's green cannot retire the publisher's red. See
[Gate integrity](#gate-integrity-the-evaluator-runs-from-the-base-branch).

`ci-ok` is green only when all of these are green at the same tip:
Expand Down Expand Up @@ -443,7 +441,7 @@ the base branch into `base/` and executed from there:
| `workflow-lint` | `node base/scripts/workflow-injection.mjs --workflows .github/workflows --allowlist base/.github/agent/workflow-injection-allowlist.json` |
| `reserved-contexts` | `node base/scripts/reserved-contexts.mjs --workflows .github/workflows` |
| `codeql-required` | `node base/scripts/codeql-required.mjs` |
| `ci-ok` / `ci-ok-head` (the in-run aggregate; `#1273` renames it and both ids are accepted meanwhile) | `node base/scripts/ci-ok.mjs` |
| `ci-ok-head` (the in-run aggregate; a branch still carrying the pre-`#1273` id `ci-ok` is accepted while the transition runs) | `node base/scripts/ci-ok.mjs` |
| `ci-ok` (the publisher's verdict) | `node base/scripts/ci-ok-run.mjs`, run by `ci-ok-publish.yml` |
| CodeQL gate | `node base/scripts/codeql-gate.mjs --sarif codeql-results --baseline base/.github/agent/codeql-baseline.json` |

Expand Down Expand Up @@ -489,12 +487,11 @@ always loads a `workflow_run` workflow from the default branch, so the file that
decides is never the one under test. It reads the finished run's job results from
the API, re-derives the change flags with the default branch's `ci-changes.mjs`
over the same diff, evaluates the default branch's `REQUIRED_JOBS` and
`SKIP_WHEN`, and creates the `ci-ok` check run itself. The in-run aggregate still
publishes the same context in this step, but it is never read as evidence — the
publisher matches required jobs by name and answers `null` for both `ci-ok` and
`ci-ok-head` — so a head that rewrites its `run:` line to `exit 0` changes only
that job's own result, and every check run at the head sha counts, so the
publisher's red still blocks. A required job the head deletes or renames is
`SKIP_WHEN`, and creates the `ci-ok` check run itself. The in-run aggregate
publishes `ci-ok-head`, and it is never read as evidence — the publisher matches
required jobs by name and answers `null` for both `ci-ok` and `ci-ok-head` — so a
head that rewrites its `run:` line to `exit 0` changes only that job's own result,
and every check run at the head sha counts, so the publisher's red still blocks. A required job the head deletes or renames is
reported missing by name, which is red — the same answer as dropping it from
`needs` inside the run. A run the platform `cancelled` publishes nothing, because
the run that replaced it owns the verdict. A `pull_request` run whose payload no
Expand Down Expand Up @@ -558,9 +555,9 @@ enumerates the open pull request heads and publishes a red `ci-ok` where the
newest verdict that names a policy was computed under a different policy, so a
green verdict does not outlive the required set it was computed under — a head
whose verdict predates a newly required job stops being satisfying the moment that
job reaches `main`. Two shapes are deliberately not verdicts. The in-run `ci-ok`
job in `.github/workflows/ci.yml` publishes the same check name, finishes before
the publisher and names no policy (it is the aggregate #855 removed as evidence);
job reaches `main`. Two shapes are deliberately not verdicts. The in-run
`ci-ok-head` job in `.github/workflows/ci.yml` finishes before the publisher and
names no policy (it is the aggregate #855 removed as evidence);
while a `ci-ok-publish.yml` run for the head is queued or in progress the sweep
skips that head, because its verdict is imminent and a red published against the
aggregate would be permanent. Once the CI workflow has finished and no publisher
Expand Down
17 changes: 17 additions & 0 deletions docs/code-standards.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,23 @@ not a conclusion.
- Never admin-merge, never bypass a required check, never force-push `main`.
- One PR per issue. Push to the existing branch instead of opening a duplicate.

## Required contexts

A required context is green only when its latest **settled** conclusion is
`success`. `status != completed` is `pending`, never `missing`: a context whose
only job object is unsettled after the run finished is reported as `pending` and
stays red, and the publisher creates no check run at all while any required
context is unsettled. A context with no job object at all is `missing` and stays
red — the two words are distinct on purpose, because `missing` sends a reader to
look for a job that did run. When one context carries several conclusions at one
commit, the newest settled one decides, and every conclusion seen is recorded in
the published summary, so "two conclusions" can be told from "no conclusions"
without re-querying the API. `ci-ok` has one workflow-file producer,
`ci-ok-publish.yml`; `ci-ok-refresh.yml` posts a red `ci-ok` through the API on
every push to `main`, and `scripts/lib/reserved-contexts.mjs` reads job ids and
job-level `name:` values, so that producer sits outside the scanner's view by
design and must keep blocking — deleting it would let a stale green stand.

## The issue tie in a PR body

`pr-lint` requires every pull request to name the issue it belongs to, in one of
Expand Down
23 changes: 20 additions & 3 deletions scripts/ci-ok-run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@
//
// `ci-ok-publish.yml` runs this on `workflow_run`, after a `CI` run completes,
// so the file that decides the merge is the default branch's and not the pull
// request's. The aggregate inside `ci.yml` keeps publishing `ci-ok` until the
// follow-up renames it to `ci-ok-head`; every check run at the head sha counts,
// so the head's green cannot retire this verdict.
// request's. #1273 renamed the in-run aggregate to `ci-ok-head`, so the
// required context `ci-ok` has one producer — this verdict — and every check
// run at the head sha still counts: no green can retire a red.
//
// A concluded run can still carry an unsettled job object (`status:
// in_progress` beside a `conclusion`, jobs 138082842033 and 138086900960).
// While any required context is unsettled this publishes nothing at all: the
// word `pending` goes to this log, and the absent context stays red through
// the reader's `missing` branch. A red check run that invented a conclusion
// would keep the duplicate-producer shape #863 removed.
//
// The trigger names the finished run as an integer (`CI_OK_RUN_ID`, set from
// `github.event.workflow_run.id`), and every fact about that run is then read
Expand Down Expand Up @@ -60,6 +67,7 @@ import {
checkRunPayload,
lostItsBase,
mergedPullRequestOf,
pendingRequired,
runIdFrom,
skipDetail,
skipReason,
Expand Down Expand Up @@ -290,6 +298,15 @@ async function main() {
} catch (error) {
result = failingResult(`ci-ok could not be computed from run ${String(run.id)}: ${error.message}`)
}
// #1273, shape 1: a required context that has not settled is not a verdict.
// This lands after `loadJobs` (`:273`) and before `publish` (`:301`) on
// purpose — the run-level skip above inspects only the run object, so a
// concluded run carrying an `in_progress` job walks past it.
const pending = pendingRequired(result.needs)
if (pending.length > 0) {
console.log(`ci-ok-run: pending — run ${String(run.id)} has unsettled required job(s): ${pending.join(', ')}; no check run is created`)
return
}
const payload = checkRunPayload({
headSha: String(run.head_sha),
result,
Expand Down
22 changes: 22 additions & 0 deletions scripts/lib/ci-ok-run.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,23 @@
// finished `CI` run's job list and publishes the `ci-ok` check run itself, so
// the suite needs the pure half to assert what a head cannot do.
export interface FinishedJob {
id?: number
name?: string
status?: string
conclusion?: string | null
completed_at?: string | null
}

/** One job object seen for a required context, as the published summary quotes
* it (#1273). `status` and `conclusion` are whitelisted values or `unknown`. */
export interface SeenConclusion {
key: string
name: string
id: number | null
status: string
conclusion: string
completedAt: string
result: string
}

export interface JobResult {
Expand All @@ -16,6 +30,8 @@ export interface AggregateVerdict {
lines: string[]
problems: string[]
ok: boolean
/** Present on a verdict built from a job list; a hand-built red may omit it. */
seen?: SeenConclusion[]
}

export interface AggregateInput {
Expand Down Expand Up @@ -49,9 +65,15 @@ export declare const HEAD_AGGREGATE_JOB: string
export declare const CHECK_STATUS: string
export declare const CHECK_CONCLUSIONS: Readonly<{ pass: string; fail: string }>
export declare const SKIP_REASONS: Readonly<{ superseded: string; merged: string; notARun: string }>
/** #1273: the word an unsettled job object gets; red, and not `missing`. */
export declare const PENDING: string
export declare function runIdFrom(input?: { args?: string[]; env?: Record<string, string | undefined> }): number
export declare function jobKey(name: string, required?: string[]): string | null
export declare function conclusionsSeen(jobs: FinishedJob[], required?: string[]): SeenConclusion[]
export declare function needsFromJobs(jobs: FinishedJob[], required?: string[]): Record<string, JobResult>
/** The required contexts whose evidence is unsettled; non-empty means the
* publisher creates no check run. */
export declare function pendingRequired(needs: Record<string, JobResult> | null | undefined | unknown, required?: string[]): string[]
export declare function verdict(input: AggregateInput): AggregateVerdict
export declare function baseShas(run: FinishedRun | null): string[]
export declare function lostItsBase(run: FinishedRun | null): boolean
Expand Down
Loading
Loading