Repository navigation
ci: add the required CI/gate aggregator #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e99efb1
e3eee40
252571f
48b3c9a
9514441
995becc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
| # SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell | ||
| name: CI | ||
| # One entry point for the checks the `main` ruleset requires. `needs:` only | ||
| # works inside a single workflow, so the gated workflows (agda-proofs.yml, | ||
| # rust-ci.yml, dashboard-check.yml) are reusable (`on: workflow_call`) and are | ||
| # called from here. They have no push/pull_request triggers of their own, so | ||
| # nothing runs twice. `gate` is the required status check `CI/gate`: it passes | ||
| # only if every called workflow ended `success` (scripts/ci-gate.sh). A new | ||
| # gated workflow must be called here AND listed in the gate's `needs:`; | ||
| # tests/workflows/ci_gate_test.sh fails if it is not. | ||
| on: | ||
| push: | ||
| branches: [main, master] | ||
| pull_request: | ||
| permissions: | ||
| contents: read | ||
| jobs: | ||
| agda-proofs: | ||
| uses: ./.github/workflows/agda-proofs.yml | ||
| permissions: | ||
| contents: read | ||
| rust-ci: | ||
| # Called directly, not through rust-ci.yml: the suite reads the pin back | ||
| # from the top-level workflow file (this one). See rust-ci.yml's header. | ||
| # Keep this SHA identical to the one in rust-ci.yml. Its jobs ask for | ||
| # contents: read only; granting less is a startup_failure. | ||
| permissions: | ||
| contents: read | ||
| uses: hyperpolymath/proven-cicd-and-workflows/.github/workflows/rust-ci.yml@9eb0bbf9bd80b7964ce5b9957e75821b3cd4a55b # cicd-suite main | ||
| dashboard-check: | ||
| uses: ./.github/workflows/dashboard-check.yml | ||
| permissions: | ||
| actions: read | ||
| contents: read | ||
| gate: | ||
| name: CI/gate | ||
| needs: [agda-proofs, rust-ci, dashboard-check] | ||
| if: ${{ always() }} | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| permissions: | ||
| contents: read | ||
| steps: | ||
| - uses: actions/checkout@v7.0.1 | ||
| with: | ||
| persist-credentials: false | ||
| # The gate's own regression test: a job missing from `needs:`, or a | ||
| # called workflow that regains its own trigger, fails the gate here. | ||
| - name: Gate regression test | ||
| run: bash tests/workflows/ci_gate_test.sh | ||
| - name: All required jobs succeeded | ||
| env: | ||
| NEEDS_JSON: ${{ toJSON(needs) }} | ||
| run: bash scripts/ci-gate.sh | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,36 @@ | ||
| # This workflow is managed by gh actions-lock. | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
| # This workflow is managed by gh actions-lock. | ||
| # Rust CI — thin wrapper calling the shared estate reusable in | ||
| # hyperpolymath/standards. Configure once, propagate everywhere. | ||
| # See: docs/CI-REUSABLE-WORKFLOWS.adoc in standards. | ||
| # Rust CI — thin caller of the estate's strict Rust gate in | ||
| # hyperpolymath/proven-cicd-and-workflows (rust-ci.yml, a reusable workflow). | ||
| # This repository cannot call reusables owned by metadatastician (every such | ||
| # run ended startup_failure), so the previous call to | ||
| # metadatastician/standards rust-ci-reusable.yml is replaced. | ||
| # | ||
| # Weekly only: pull_request and push runs come from ci.yml, whose `rust-ci` | ||
| # job holds the same pin. The suite's gate scripts are selected by reading the | ||
| # TOP-LEVEL workflow file's `uses:` line back (GITHUB_WORKFLOW_REF), which is | ||
| # ci.yml under a ci.yml call, so a nested call through this file could not be | ||
| # verified and ci.yml calls the suite directly. Keep the two pins identical. | ||
| # | ||
| # The weekly run still catches a new RustSec advisory against an unchanged | ||
| # Cargo.lock. The old `enable_audit: true` (cargo audit) is replaced by the | ||
| # suite's `deny` job (cargo-deny: advisories, bans, sources); the suite's | ||
| # `enable_audit` input is a documented no-op. | ||
| # | ||
| # De-onboarded from actions.lock on purpose, as the suite's caller template | ||
| # requires: an onboarded cross-repository reusable startup-fails with zero | ||
| # jobs under sha_pinning_required. No `secrets:`: the reusable consumes none. | ||
| name: Rust CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main, master] | ||
| pull_request: | ||
| # Weekly, so a new RustSec advisory against an unchanged Cargo.lock is still | ||
| # caught (the scheduled cargo-audit.yml was folded into this workflow). | ||
| schedule: | ||
| - cron: '0 6 * * 1' | ||
|
|
||
| permissions: | ||
| actions: read | ||
| contents: read | ||
|
|
||
| jobs: | ||
| rust-ci: | ||
| uses: metadatastician/standards/.github/workflows/rust-ci-reusable.yml@a797d308c0517d4e2d21cc7f1cb08d41f82b1a12 | ||
| permissions: | ||
| actions: read | ||
| contents: read | ||
| security-events: write | ||
| with: | ||
| # Replaces the retired cargo-audit.yml (standards CI regularisation spec: | ||
| # fold the audit into rust-ci through enable_audit). | ||
| enable_audit: true | ||
| uses: hyperpolymath/proven-cicd-and-workflows/.github/workflows/rust-ci.yml@9eb0bbf9bd80b7964ce5b9957e75821b3cd4a55b # cicd-suite main |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
| # SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell | ||
| # | ||
| # ci-gate.sh — the verdict behind the required status check `CI/gate`. | ||
| # | ||
| # Reads the `needs` context of a GitHub Actions job (toJSON(needs)) from | ||
| # $NEEDS_JSON and succeeds only if at least one job was aggregated and EVERY | ||
| # one ended `success`. `failure`, `cancelled` and `skipped` all fail: a skipped | ||
| # prover leg is a leg that proved nothing, and a gate that counts it as green is | ||
| # a rubber stamp (doctrine 3, fail loudly). An empty or unparseable context | ||
| # fails too, so a gate pointed at zero jobs cannot pass. | ||
| # | ||
| # Exit: 0 all aggregated jobs succeeded; 1 a job did not, or none were given; | ||
| # 2 setup error (no jq, no NEEDS_JSON). | ||
| set -euo pipefail | ||
|
|
||
| command -v jq >/dev/null 2>&1 || { echo "ci-gate: jq is required" >&2; exit 2; } | ||
| [ -n "${NEEDS_JSON:-}" ] || { echo "ci-gate: NEEDS_JSON is not set" >&2; exit 2; } | ||
|
Check failure on line 19 in scripts/ci-gate.sh
|
||
|
|
||
| jq -e 'type == "object"' <<<"$NEEDS_JSON" >/dev/null 2>&1 || { echo "::error::ci-gate: NEEDS_JSON is not a JSON object"; exit 1; } | ||
| total="$(jq -e 'length' <<<"$NEEDS_JSON")" || { echo "::error::ci-gate: NEEDS_JSON is not a JSON object"; exit 1; } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| if [ "$total" -eq 0 ]; then | ||
|
Check failure on line 23 in scripts/ci-gate.sh
|
||
| echo "::error::CI/gate aggregates no jobs (denominator = 0); refusing to pass." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "CI/gate: ${total} aggregated job(s)" | ||
| jq -r 'to_entries[] | " \(.key): \(.value.result)"' <<<"$NEEDS_JSON" | ||
|
|
||
| bad="$(jq -r 'to_entries[] | select(.value.result != "success") | "\(.key)=\(.value.result)"' <<<"$NEEDS_JSON")" | ||
| if [ -n "$bad" ]; then | ||
|
Check failure on line 32 in scripts/ci-gate.sh
|
||
| while IFS= read -r line; do echo "::error::CI/gate: required job did not succeed: ${line}"; done <<<"$bad" | ||
| exit 1 | ||
| fi | ||
| echo "CI/gate: all ${total} required job(s) succeeded" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
| # SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell | ||
| # CI/gate must be a verdict, not a rubber stamp. Positive control: all green | ||
| # passes. Negative cases: failure, cancelled, skipped, empty and malformed | ||
| # input each fail. Drift: the gate's `needs:` must list every other job of | ||
| # ci.yml; every workflow ci.yml calls must be reusable and must have no | ||
| # push/pull_request trigger of its own (else it would run twice). | ||
| # shellcheck disable=SC2015,SC2016 | ||
| set -uo pipefail | ||
| cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." || exit 2 | ||
| fail=0 | ||
| chk() { # chk NAME WANT-RC JSON | ||
| NEEDS_JSON="$3" bash scripts/ci-gate.sh >/dev/null 2>&1; rc=$? | ||
| if [ "$rc" -eq "$2" ]; then echo "ok $1"; else echo "FAIL $1: rc=$rc want $2"; fail=1; fi | ||
|
Check failure on line 15 in tests/workflows/ci_gate_test.sh
|
||
| } | ||
| chk "all success passes" 0 '{"a":{"result":"success"},"b":{"result":"success"}}' | ||
| chk "one failure fails" 1 '{"a":{"result":"success"},"b":{"result":"failure"}}' | ||
| chk "one cancelled fails" 1 '{"a":{"result":"success"},"b":{"result":"cancelled"}}' | ||
| chk "one skipped fails" 1 '{"a":{"result":"success"},"b":{"result":"skipped"}}' | ||
| chk "empty needs fails" 1 '{}' | ||
| chk "malformed fails" 1 'not json' | ||
| chk "array input fails" 1 '[{"result":"success"}]' | ||
| chk "string input fails" 1 '"x"' | ||
| chk "number input fails" 1 '3' | ||
| chk "null input fails" 1 'null' | ||
| chk "underscore job passes" 0 '{"integration_tests":{"result":"success"}}' | ||
|
|
||
| wf=.github/workflows/ci.yml | ||
| # drift WORKFLOW: prints "jobs|needs"; equal and non-empty means no drift. | ||
| drift() { | ||
| local j n | ||
| j="$(sed -n '/^jobs:/,$ s/^ \([A-Za-z_][A-Za-z0-9_-]*\):[[:space:]]*\(#.*\)\{0,1\}$/\1/p' "$1" | grep -vx 'gate' | sort | tr '\n' ' ')" | ||
| n="$(sed -n 's/^ needs: \[\(.*\)\]$/\1/p' "$1" | tr -d ',' | tr ' ' '\n' | sort | tr '\n' ' ')" | ||
| echo "$j|$n" | ||
| } | ||
| d="$(drift "$wf")"; jobs="${d%%|*}"; needs="${d#*|}" | ||
| if [ -n "$jobs" ] && [ "$jobs" = "$needs" ]; then echo "ok gate needs every other job ($needs)"; else echo "FAIL needs drift: jobs=[$jobs] needs=[$needs]"; fail=1; fi | ||
|
Check failure on line 38 in tests/workflows/ci_gate_test.sh
|
||
| # Mutation: an underscore-named job absent from gate.needs must be detected. | ||
| mut="$(mktemp)" | ||
| sed 's/^ gate:$/ integration_tests:\n runs-on: ubuntu-latest\n gate:/' "$wf" > "$mut" | ||
| d="$(drift "$mut")"; rm -f "$mut" | ||
| if [ "${d%%|*}" != "${d#*|}" ]; then echo "ok drift check catches an underscore job missing from needs"; else echo "FAIL drift check missed integration_tests"; fail=1; fi | ||
|
Check failure on line 43 in tests/workflows/ci_gate_test.sh
|
||
| # Mutation: a job header with an inline comment (valid YAML) must be detected too. | ||
| mut="$(mktemp)" | ||
| sed 's/^ gate:$/ smoke: # quick suite\n runs-on: ubuntu-latest\n gate:/' "$wf" > "$mut" | ||
| d="$(drift "$mut")"; rm -f "$mut" | ||
| if [ "${d%%|*}" != "${d#*|}" ]; then echo "ok drift check catches a commented job header missing from needs"; else echo "FAIL drift check missed a commented job header"; fail=1; fi | ||
|
Check failure on line 48 in tests/workflows/ci_gate_test.sh
|
||
| grep -q '^ name: CI/gate$' "$wf" && echo "ok job name is exactly CI/gate" || { echo "FAIL job name"; fail=1; } | ||
| grep -q '^ if: \${{ always() }}$' "$wf" && echo "ok gate runs always()" || { echo "FAIL gate lacks always()"; fail=1; } | ||
|
|
||
| # Every workflow ci.yml calls: reusable, and no direct push/pull_request trigger. | ||
| called="$(sed -n 's/^ uses: \(\.\/\.github\/workflows\/[^ ]*\)$/\1/p' "$wf")" | ||
| [ -n "$called" ] || { echo "FAIL ci.yml calls no local workflow"; fail=1; } | ||
|
Check failure on line 54 in tests/workflows/ci_gate_test.sh
|
||
| for f in $called; do | ||
| f="${f#./}" | ||
| # the top-level `on:` block: from `on:` to the next unindented key | ||
| on_block="$(sed -n '/^on:/,/^[a-z]/p' "$f" | sed '$d')" | ||
| grep -q '^ workflow_call:' <<<"$on_block" && echo "ok $f is reusable" || { echo "FAIL $f lacks workflow_call"; fail=1; } | ||
| if grep -qE '^ (push|pull_request|pull_request_target):' <<<"$on_block"; then | ||
| echo "FAIL $f has its own push/pull_request trigger: it would run twice"; fail=1 | ||
| else echo "ok $f has no push/pull_request trigger of its own"; fi | ||
| done | ||
| # The gated jobs the owner named must still be reachable from the called workflows. | ||
| for j in proofs recheck receipt; do | ||
| grep -q "^ $j:" .github/workflows/agda-proofs.yml && echo "ok agda-proofs.yml still has job $j" || { echo "FAIL agda-proofs.yml lost job $j"; fail=1; } | ||
| done | ||
| grep -q '^ dashboard-check:' .github/workflows/dashboard-check.yml && echo "ok dashboard-check job present" || { echo "FAIL dashboard-check job lost"; fail=1; } | ||
| grep -q '^ rust-ci:' .github/workflows/rust-ci.yml && echo "ok rust-ci job present" || { echo "FAIL rust-ci job lost"; fail=1; } | ||
| exit $fail | ||
Uh oh!
There was an error while loading. Please reload this page.