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
23 changes: 20 additions & 3 deletions .github/scripts/workflow-pin-metadata.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ const expectedCiWorkflowsCallers = [
["pr-require-checks.yml", ".github/actions/gitleaks"],
["pr-require-checks.yml", ".github/actions/lychee-offline"],
["pr-require-checks.yml", ".github/actions/markdownlint"],
["pr-require-checks.yml", ".github/actions/pr-require-checks/aggregate-results"],
["pr-require-checks.yml", ".github/actions/pr-require-checks/check-contract"],
["pr-require-checks.yml", ".github/actions/pr-require-checks/report-ci-status"],
["pr-require-checks.yml", ".github/actions/shellcheck"],
["pr-require-checks.yml", ".github/actions/shfmt"],
["pr-require-checks.yml", ".github/actions/typos"],
Expand Down Expand Up @@ -121,7 +120,8 @@ function ciWorkflowsPin() {
const advisory = syncManagedMarker.test(source);
const lines = source.split(/\r?\n/u);
for (const [index, line] of lines.entries()) {
if (!line.includes(ciWorkflowsReference)) {
// A full-line YAML comment can link a ci-workflows file; it calls nothing.
if (!line.includes(ciWorkflowsReference) || /^\s*#/u.test(line)) {
continue;
}

Expand Down Expand Up @@ -271,3 +271,20 @@ test("ci-status is the stable gateway for every Go lane", () => {
assert.ok(block.includes(" name: CI Status"));
assert.ok(block.includes(" if: always()"));
});

// report-ci-status never fails on the contract or the draft policy; it reports
// them as outputs. Without this step a failed contract leaves CI Status green.
test("ci-status fails closed on the report-ci-status contract and draft outputs", () => {
const block = jobBlock(workflowSource("pr-require-checks.yml"), "ci-status");
const report = block.findIndex((line) => line === " id: report");
assert.notEqual(report, -1, "the report-ci-status step must carry id: report");
assert.equal(block[report - 1], " - name: Aggregate lane results", "the writer step keeps its name");

const gate = block.findIndex(
(line) =>
line ===
" if: ${{ !cancelled() && (steps.report.outputs.contract != 'success' || steps.report.outputs.draft != 'success') }}",
);
assert.ok(gate > report, "a later step must fail the job on any contract or draft outcome but success");
assert.ok(block.slice(gate).some((line) => line.trim() === "exit 1"), "the gate step must exit 1");
});
76 changes: 43 additions & 33 deletions .github/workflows/pr-require-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ permissions:
#
# The cost of the branch: a contract-only run no longer queues behind the full
# run whose `ci-lanes` status it carries forward, so the two race.
# `yield-to-full-run` on the job below fails it at once while a full run is in
# flight, whose newer ci-status then decides the gate, instead of it queuing or
# waiting.
# The ci-status composite's fixed `yield-to-full-run` fails it at once while a
# full run is in flight, whose newer ci-status then decides the gate, instead
# of it queuing or waiting.
#
# 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 @@ -484,28 +484,45 @@ jobs:
- build-worker-image
- review-dependencies
runs-on: ubuntu-24.04
# With `yield-to-full-run` a contract-only run lists in-flight runs once and
# reads the status once, so it finishes in seconds. A full run's ci-status
# runs after its lanes and waits at most `rerun-wait-seconds` (default 90)
# for in-flight contract-only siblings before re-running them.
# With the composite's fixed `yield-to-full-run` a contract-only run lists
# in-flight runs once and reads the status once, so it finishes in
# seconds. A full run's ci-status runs after its lanes and waits at most
# `rerun-wait-seconds` (default 90) for in-flight contract-only siblings
# before re-running them.
timeout-minutes: 3
permissions:
contents: read # No checkout here; the composites read the pull request through the API.
# `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.
contents: read # No checkout here; the composite reads the pull request through the API.
# 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 # Lists this workflow's runs and re-runs contract-only siblings.
# check-contract upserts the advisory linkage comment and moves the linkage
# label; ci-status records the `ci-lanes` commit status the carry-forward
# branch reads back on the next contract-only event.
pull-requests: write # Advisory linkage comment and label writes.
statuses: write # Records and reads back the `ci-lanes` commit status.
steps:
- name: Check the pull-request contract
uses: melodic-software/ci-workflows/.github/actions/pr-require-checks/check-contract@9c5bedfbfdbdfe733b9ce4cd7ca80c1574bd4cb8 # v0.76.3
# 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, and
# the jobs API, which can list a running job's steps as [] for minutes,
# is matched on `step-name`. The composite fixes
# `yield-to-full-run: 'true'` and `carry-forward-wait-seconds: '0'`
# (https://github.com/melodic-software/ci-workflows/blob/9c5bedfbfdbdfe733b9ce4cd7ca80c1574bd4cb8/.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 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.
- name: Aggregate lane results
id: report
uses: melodic-software/ci-workflows/.github/actions/pr-require-checks/report-ci-status@9c5bedfbfdbdfe733b9ce4cd7ca80c1574bd4cb8 # v0.76.3
with:
token: ${{ github.token }}
step-name: Aggregate lane results
# This workflow is not draft-gated (no `ready_for_review` trigger), so a draft passes.
draft: allow
# Dependabot and the standards sync open pull requests that close no
# issue, so without this they collect the advisory linkage comment
# and the `needs-issue-linkage` label on every run. Exempts the
Expand All @@ -514,13 +531,6 @@ jobs:
# equality, never a `*[bot]` pattern, so a new bot is not silently
# skipped.
exempt-authors: 'dependabot[bot],melodic-standards-sync[bot]'
- 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@9c5bedfbfdbdfe733b9ce4cd7ca80c1574bd4cb8 # v0.76.3
with:
results: >-
${{ needs.markdownlint.result }}
${{ needs.shellcheck.result }}
Expand All @@ -542,16 +552,16 @@ jobs:
${{ needs.fuzz-go.result }}
${{ needs.build-worker-image.result }}
${{ needs.review-dependencies.result }}
# Lanes such as fuzz-go and review-dependencies skip by event, not
# only on a contract-only event, so a skip passes (the composite
# defaults to `fail`).
treat-skipped-as: pass
# 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'
# The jobs API can list a running job's steps as [] for minutes; the
# step's own name lets the carry-forward and yield lookups find it.
step-name: Aggregate lane results
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