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
16 changes: 11 additions & 5 deletions .github/scripts/pr-section-drift.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
// fails the PR that introduces either drift, comparing both mirrors to the
// exact composite bytes this repository's gate already executes.
//
// Comparison target is derived: the 40-hex `check-contract` pin in
// `.github/workflows/pr-require-checks.yml`, then that ref's `run.sh`. The four section names
// Comparison target is derived: the 40-hex `check-contract` or
// `report-ci-status` pin in `.github/workflows/pr-require-checks.yml` (the
// latter runs `check-contract` through `$/` at its own commit), then that
// ref's `check-contract/run.sh`. The four section names
// are not hardcoded here. Fetch failures are `fetch-error` (never a skip),
// matching standards' `lockstep-drift.mjs` posture.
//
Expand Down Expand Up @@ -39,7 +41,7 @@ const CONTRACT_FOOTER =
"Change the contract there and bump the pin, then update both local files in the same PR.";

const CALLER_PIN_RE =
/uses:\s*melodic-software\/ci-workflows\/\.github\/actions\/pr-require-checks\/check-contract@([0-9a-f]{40})/g;
/uses:\s*melodic-software\/ci-workflows\/\.github\/actions\/pr-require-checks\/(?:check-contract|report-ci-status)@([0-9a-f]{40})/g;
const SECTION_REPORT_RE = /section_report\("([^"]+)"\)/g;

export class DriftError extends Error {
Expand All @@ -57,10 +59,14 @@ export function sourceOfTruth(sha) {
export function parseCallerPin(callerText, location = CALLER_PATH) {
const unique = [...new Set([...callerText.matchAll(CALLER_PIN_RE)].map((match) => match[1]))];
if (unique.length === 0) {
throw new DriftError(`${location}: no 40-hex check-contract@ pin found on a uses: line`);
throw new DriftError(
`${location}: no 40-hex check-contract@ or report-ci-status@ pin found on a uses: line`,
);
}
if (unique.length > 1) {
throw new DriftError(`${location}: multiple distinct check-contract pins: ${unique.join(", ")}`);
throw new DriftError(
`${location}: multiple distinct check-contract or report-ci-status pins: ${unique.join(", ")}`,
);
}
return unique[0];
}
Expand Down
14 changes: 14 additions & 0 deletions .github/scripts/pr-section-drift.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ describe("parseCallerPin", () => {
assert.equal(parseCallerPin(text), SHA);
});

it("returns the report-ci-status pin, which runs check-contract at that commit", () => {
const text = ` - uses: melodic-software/ci-workflows/.github/actions/pr-require-checks/report-ci-status@${SHA} # v9.9.9\n`;
assert.equal(parseCallerPin(text), SHA);
});

it("fails when check-contract and report-ci-status are pinned at different SHAs", () => {
const text = [
callerYaml(SHA),
` - uses: melodic-software/ci-workflows/.github/actions/pr-require-checks/report-ci-status@${OTHER_SHA} # v9.9.9`,
"",
].join("\n");
assert.throws(() => parseCallerPin(text), /multiple distinct/);
});

it("fails when two distinct pins are present", () => {
const text = `${callerYaml(SHA)}\n${callerYaml(OTHER_SHA)}`;
assert.throws(() => parseCallerPin(text), /multiple distinct/);
Expand Down
74 changes: 42 additions & 32 deletions .github/workflows/pr-require-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ permissions:
#
# The cost of the branch: a contract-only run does not queue behind the full
# run whose `ci-lanes` status it carries forward, so the two race. The
# `aggregate-results` composite's `yield-to-full-run` closes that: a contract-only
# run fails at once while a full run is in flight, whose newer ci-status then
# decides the gate; see the job below.
# `report-ci-status` composite closes that: a contract-only run fails at once
# while a full run is in flight, whose newer ci-status then decides the gate;
# see the job below.
#
# One hazard the branch does not remove, because no concurrency setting both
# removes it and keeps supersession: the full branch is keyed on the pull
Expand Down Expand Up @@ -81,8 +81,8 @@ concurrency:
# ignored: `ci-status` stays green while it fails. Two lanes are local scripts
# rather than remote actions, and both are deliberately left out of `needs:`:
# they report drift but do not gate. `check-pr-sections` guards the PR-body
# contract, itself advisory: it fetches the `run.sh` of the pinned
# `check-contract` composite and compares this repository's two PR-body mirrors
# contract, itself advisory: it fetches the `check-contract` `run.sh` at the
# commit `report-ci-status` is pinned to and compares this repository's two PR-body mirrors
# to the sections that gate reports. `check-issue-forms` compares the synced
# issue forms to the synced issue-body contract.
jobs:
Expand Down Expand Up @@ -321,8 +321,9 @@ jobs:

# Compares `.github/PULL_REQUEST_TEMPLATE.md` headings and
# `docs/conventions/source-control.yaml`'s `pr_body_required_sections` to the
# `section_report` calls inside the SHA-pinned `check-contract` composite's
# `run.sh`. The comparison target is that pin's bytes, not a
# `section_report` calls inside the `check-contract` composite's `run.sh` at
# the SHA `report-ci-status` is pinned to, which runs that `check-contract`.
# The comparison target is that pin's bytes, not a
# third hardcoded copy of the four names. Fetches over the network; a fetch
# failure is red, never a skip, same posture as standards'
# `pr-convention-lockstep` (ADR-0008). Advisory: not in `ci-status` `needs:`.
Expand Down Expand Up @@ -368,15 +369,16 @@ jobs:
if: always()
needs: [markdownlint, typos, editorconfig-checker, gitleaks, check-links, actionlint, jsonschema, shellcheck, check-line-endings]
runs-on: ubuntu-latest
# No run waits for another: with `yield-to-full-run` a contract-only run
# lists in-flight runs once and reads the status once, and a full run's
# ci-status runs after its lanes, so either finishes in seconds.
# No run waits for another: a contract-only run lists in-flight runs once
# and reads the status once, and a full run's ci-status runs after its
# lanes, so either finishes in seconds.
timeout-minutes: 3
permissions:
# `yield-to-full-run` lists this workflow's runs on the head SHA, and
# `rerun-contract-only-siblings` re-runs the red contract-only ones once
# the full run records `success`. Under an explicit `permissions:` block
# every unlisted scope defaults to none; write covers the read.
# The composite lists this workflow's runs on the head SHA (its fixed
# `yield-to-full-run`) and re-runs the red contract-only ones once the
# full run records `success` (`rerun-contract-only-siblings`). Under an
# explicit `permissions:` block every unlisted scope defaults to none;
# write covers the read.
actions: write
contents: read
# check-contract upserts the advisory linkage comment and moves the linkage
Expand All @@ -385,30 +387,38 @@ jobs:
pull-requests: write
statuses: write
steps:
- name: Check the pull-request contract
uses: melodic-software/ci-workflows/.github/actions/pr-require-checks/check-contract@24067add42f5fa04743c587c6a22aa7d4059e7b8 # v0.75.0
with:
token: ${{ github.token }}
# The contract, the draft policy and the aggregation in one step. The
# step keeps the aggregation step's old name: a contract-only run finds
# the writer step of the full run it carries forward by this name.
# The composite fixes `yield-to-full-run: 'true'` and
# `carry-forward-wait-seconds: '0'`, the values this job set before
# (https://github.com/melodic-software/ci-workflows/blob/ebd0e3bed99ae1365fcb4ef47ce97cfa745fcf2f/.github/actions/pr-require-checks/report-ci-status/action.yml#L128-L129):
# a contract-only run never waits; while a full run on the SHA is in
# flight it fails with "superseded by full run <url>", and once that run
# records `success` it re-runs the red contract-only runs
# (`rerun-contract-only-siblings`, default `true`).
- name: Aggregate lane results
# `!cancelled()` so a failing check-contract step does not skip the
# aggregation: the job still fails on the contract step's exit code, and
# the `ci-lanes` status is on the SHA for the next contract-only run.
if: ${{ !cancelled() }}
uses: melodic-software/ci-workflows/.github/actions/pr-require-checks/aggregate-results@24067add42f5fa04743c587c6a22aa7d4059e7b8 # v0.75.0
id: report
uses: melodic-software/ci-workflows/.github/actions/pr-require-checks/report-ci-status@ebd0e3bed99ae1365fcb4ef47ce97cfa745fcf2f # v0.76.0
with:
step-name: Aggregate lane results
# This workflow is not draft-gated (no `ready_for_review` trigger), so a draft passes.
draft: allow
# A skipped lane passes, as it did under aggregate-results' own
# default; the composite's default is `fail`.
treat-skipped-as: pass
# Derived from `needs:` rather than restating it. Hand-listing the
# results let a lane be dropped from this input alone: still gated via
# `needs:`, but its verdict withheld from the aggregator, so the check
# went green on that lane's failure with no linter to catch it. `join`
# over the `needs.*` object filter yields the whitespace-separated form
# the action word-splits.
results: ${{ join(needs.*.result, ' ') }}
# A contract-only run never waits: while a full run on the SHA is in
# flight it fails with "superseded by full run <url>", and that run's
# newer ci-status decides the gate. Once the full run records
# `success` it re-runs those red contract-only runs, which then read
# the `success` and replace their red check runs.
yield-to-full-run: 'true'
rerun-contract-only-siblings: 'true'
carry-forward-wait-seconds: '0'
token: ${{ github.token }}
# The composite's step concludes on the lanes alone; the contract and
# draft results fail the job here. Anything but `success` fails, so an
# empty or renamed output fails closed.
- name: Fail on the contract or draft policy
if: ${{ !cancelled() && (steps.report.outputs.contract != 'success' || steps.report.outputs.draft != 'success') }}
run: |
echo "::error::ci-status: the pull-request contract or the draft policy failed; see the step above."
exit 1
Loading