# SPDX-License-Identifier: MPL-2.0 # Governance checks for hyperpolymath repositories — Reusable Workflow name: Governance Reusable Workflow on: workflow_call: inputs: runs-on: description: Runner label for all governance jobs type: string required: false default: ubuntu-latest permissions: contents: read jobs: workflow-staleness: name: Check Workflow Staleness runs-on: ubuntu-latest timeout-minutes: 10 outputs: has_baseline: ${{ steps.check.outputs.has_baseline }} steps: - name: Checkout caller repository uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 - name: Check baseline existence id: check run: | if [ -f ".hypatia-baseline.json" ]; then echo "has_baseline=true" >> $GITHUB_OUTPUT else echo "has_baseline=false" >> $GITHUB_OUTPUT fi - name: Clone standards repository run: | # Treeless partial clone: full commit graph (needed by the staleness # gate's ancestry / commits-behind / age math) without paying for # every tree+blob in history. Falls back to a deep clone if the # server rejects the partial-clone filter. git clone --filter=tree:0 https://github.com/hyperpolymath/standards.git "$HOME/standards" \ || git clone --depth 200 https://github.com/hyperpolymath/standards.git "$HOME/standards" - name: Run staleness check env: # The gate confirms a pin server-side before ever accusing it of being # forged, and before accepting a deny-list negative from a clone it # cannot trust. Unauthenticated that is 60 requests/hour per runner IP; # exhausting it makes the gate degrade to ::warning (loudly — it never # silently passes, see check-workflow-staleness.sh). A token removes # the cliff entirely. Note this only reaches a consumer once it re-pins # past this commit: the script comes from standards HEAD, but the job # definition comes from whatever SHA the consumer pins. GITHUB_TOKEN: ${{ github.token }} run: | bash "$HOME/standards/scripts/check-workflow-staleness.sh" . validate-hypatia-baseline: name: Validate Hypatia Baseline needs: workflow-staleness if: needs.workflow-staleness.outputs.has_baseline == 'true' runs-on: ubuntu-latest timeout-minutes: 15 steps: - name: Checkout caller repository uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: fetch-depth: 0 - name: Setup Elixir for Hypatia scanner uses: erlef/setup-beam@54075bcc5e249e4758d363f27d099f55d843f124 # v1.24.1 with: elixir-version: '1.19.4' otp-version: '28.3' - name: Resolve Hypatia HEAD commit id: hypatia-rev run: | # Pin the cache to the *current* Hypatia main tip. Resolved before the # cache step because cache restore happens before the clone, so the key # cannot hash a not-yet-cloned tree — it must hash the remote ref. sha=$(git ls-remote https://github.com/hyperpolymath/hypatia.git HEAD | cut -f1) if [ -z "$sha" ]; then echo "ERROR: could not resolve hypatia HEAD via git ls-remote" >&2 exit 1 fi echo "sha=$sha" >> "$GITHUB_OUTPUT" echo "Resolved hypatia HEAD: $sha" - name: Cache Hex/Mix and Scanner Build uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: | ~/.mix ~/.hex ~/hypatia # Source-pinned key: when Hypatia main advances, the SHA changes, the # cache misses, and the clone + escript build below re-run instead of # restoring a stale binary. The old keyless `...-build` key meant the # first scanner ever cached was reused forever, so baseline validation # ran against a stale ruleset. No restore-keys on purpose — a partial # restore would repopulate ~/hypatia and the guards below would skip # the rebuild, reintroducing the staleness. key: hypatia-scanner-v3-${{ runner.os }}-${{ steps.hypatia-rev.outputs.sha }} - name: Clone Hypatia run: | if [ ! -d "$HOME/hypatia" ]; then git clone --depth 1 https://github.com/hyperpolymath/hypatia.git "$HOME/hypatia" fi - name: Build Hypatia scanner run: | cd "$HOME/hypatia" if [ ! -x hypatia ]; then mix deps.get && mix escript.build fi # A reusable workflow only auto-checks-out its own YAML, not sibling # scripts. Sparse-check-out standards' scripts/ to get apply-baseline.sh, # mirroring the language-policy job below. Pinned to main because # github.workflow_sha resolves to the *caller* repo's SHA (which would 404). - name: Check out standards for the baseline filter uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: repository: hyperpolymath/standards ref: main path: .standards-checkout sparse-checkout: | scripts sparse-checkout-cone-mode: false - name: Run Hypatia scan (Baseline validation) env: # Preserve the historical strictness: fail on ANY finding not # acknowledged by .hypatia-baseline.json (not just >= high). Set to # 'high' to only block on high/critical. BLOCKING_THRESHOLD: info run: | echo "Scanning repository: ${{ github.repository }} (checking baseline)" # Move the baseline filter OUT of the scanned tree, then delete the # standards checkout, so `hypatia scan .` only ever sees the CALLER's # own files. Without this, `.standards-checkout/` (the tooling we # checked out to get apply-baseline.sh) is itself scanned, and # standards' own files get reported as the caller's findings (a banned # `.ts`, `shell_download` bootstrap.sh scripts, etc.). cp .standards-checkout/scripts/apply-baseline.sh "$RUNNER_TEMP/apply-baseline.sh" rm -rf .standards-checkout # hypatia's `scan` exits non-zero whenever it finds anything — that is # by design, and under `bash -e` it would abort this step at this line, # before the baseline filter (the real gate) ever runs. Tolerate the # scan's own exit code… HYPATIA_FORMAT=json "$HOME/hypatia/hypatia-cli.sh" scan . > hypatia-findings.raw.json || true # …but never swallow a genuine scanner crash into a false pass: require a # valid JSON array before trusting the output as "the findings". if ! jq -e 'type == "array"' hypatia-findings.raw.json >/dev/null 2>&1; then echo "::error::hypatia scan did not produce a valid JSON findings array (scanner error, not a baseline result)" exit 1 fi # Relativize finding paths before matching. Hypatia's honest_completion # and code_safety modules emit ABSOLUTE host paths in `.file` # (Path.expand(repo)), while .hypatia-baseline.json uses repo-relative # paths per the schema + docs/HYPATIA-BASELINE-FORMAT.adoc. Strip the # workspace prefix so baseline file/file_pattern entries can match, and # map the repo root itself to "." so root-scoped findings (no_tests) # match. Upstream fix tracked in hypatia#566; this is the stopgap. jq --arg root "$PWD" ' map(if (.file? // "") == $root then .file = "." elif (.file? // "") | startswith($root + "/") then .file = (.file | ltrimstr($root + "/")) else . end) ' hypatia-findings.raw.json > hypatia-findings.json # Filter against the per-repo baseline. apply-baseline.sh KEEPS every # finding not matched by an active (non-expired) baseline entry — so a # genuinely new finding still fails the gate (no silent-green) — and # suppresses only exact matches. Exits non-zero iff a kept finding is at # or above BLOCKING_THRESHOLD. (Validated against synthetic fixtures; # see the PR description.) bash "$RUNNER_TEMP/apply-baseline.sh" \ hypatia-findings.json .hypatia-baseline.json blocking language-policy: name: Language / package anti-pattern policy runs-on: ${{ inputs.runs-on }} timeout-minutes: 10 permissions: contents: read steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: repository: ${{ github.repository }} # Pin to the concrete event SHA (the PR merge commit on # pull_request, the pushed commit on push). Do NOT use # `ref: ${{ github.ref }}`: in a reusable workflow called from a # pull_request, github.ref is the named merge ref # `refs/pull//merge`, which actions/checkout cannot fetch # ("couldn't find remote ref refs/pull//merge") — it broke 8/10 # governance jobs on every PR estate-wide. github.sha resolves to the # same merge commit but is always fetchable. ref: ${{ github.sha }} # Estate language policy bans Python with no exceptions (CLAUDE.md # Language Policy; SaltStack exception removed 2026-01-03). The # previous in-line `python3 << PYEOF` heredoc made this very gate a # self-referential violation — same structural class as the CSA001 # self-loop fixed in hypatia#328. Eradicated by porting the logic # to a Deno script that lives in this standards repo. # # Implementation note: a reusable workflow only auto-checks-out its # YAML, not sibling files in its repo. So we explicitly check out # this repo into `.standards-checkout/`, then run the script from # there. We pin to `main` because `github.workflow_sha` resolves to # the caller repo's commit SHA (not standards'), which makes the # fetch fail with exit 128 ("No commit found for SHA"). Caller # repos already pin the reusable's YAML by SHA, so the bounded # drift is just whatever's on standards/main between the reusable # version and the script version — acceptable since scripts here # are read-only governance checks. - name: Set up Deno uses: denoland/setup-deno@22d081ff2d3a40755e97629de92e3bcbfa7cf2ed # v2.0.5 with: deno-version: v2.x - name: Check out standards repo for shared scripts uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: repository: hyperpolymath/standards ref: main path: .standards-checkout # Sparse-checkout only the scripts dir to keep this fast. sparse-checkout: | scripts sparse-checkout-cone-mode: false - name: Check for TypeScript # Read-only execution; never writes outside the runner workspace. # `--no-lock` so an empty / stale / missing `deno.lock` doesn't fail # `deno run` before the file-walker even starts — the script does not # import anything, so the lockfile is irrelevant to its execution. # See standards#294. # # Runs the AffineScript-compiled `.deno.js` (source of truth: # `scripts/check-ts-allowlist.affine`). The .ts archetype is kept # alongside for the regression suite (`scripts/tests/check-ts- # allowlist-test.sh`) and for parallel-validation during the # TS→AffineScript migration (standards#239 / #241). Retirement of # the .ts is a separate follow-up after the dual-target window. run: deno run --allow-read --no-lock .standards-checkout/scripts/check-ts-allowlist.deno.js - name: check-ts-allowlist source/compile drift (informational) # Non-blocking — informational until the AffineScript compiler # output is hash-pinned per compiler version. The compiler header # currently stamps "Generated by AffineScript compiler" which is # a moving target as the codegen evolves, so spurious diff = # "compiler bumped" vs real diff = "someone edited .affine # without recompiling". Promotion to blocking is gated on a # compiler-version pin landing (see standards#312). continue-on-error: true run: | if ! command -v affinescript >/dev/null 2>&1; then echo "::notice::affinescript compiler unavailable on runner — skipping drift check" exit 0 fi tmp="$(mktemp /tmp/check-ts-allowlist-drift.XXXXXX.deno.js)" if ! affinescript compile --deno-esm -o "$tmp" .standards-checkout/scripts/check-ts-allowlist.affine; then echo "::warning::affinescript compile failed — drift check skipped" rm -f "$tmp" exit 0 fi if diff -u .standards-checkout/scripts/check-ts-allowlist.deno.js "$tmp"; then echo "✅ check-ts-allowlist .affine source and .deno.js compiled output are in sync" else echo "::warning::check-ts-allowlist.deno.js drifted from check-ts-allowlist.affine — re-run \`just check-ts-allowlist-drift\` locally and recommit the .deno.js" fi rm -f "$tmp" # Shared escape hatch for the banned-language-file checks below. # Honours three exemption mechanisms (see # standards/docs/EXEMPTION-MECHANISMS.adoc): # 1. `.hypatia-baseline.json` — array of acknowledged findings, # shape mirrors the Hypatia findings themselves. Schema is # `.machine_readable/hypatia-baseline.schema.json` in this # repo, enforced structurally by apply-baseline.sh itself # (jq mirror; a malformed baseline exits 2 instead of # silently matching nothing). Added 2026-05-25 as part of # the convergence on a single exemption mechanism. # 2. `.hypatia-ignore` flat-file — legacy single-rule-per-line # format (`cicd_rules/banned_language_file:`). # Will be retired in a follow-up PR once .hypatia-baseline.json # is in active use across the estate. # 3. Inline `# hypatia:ignore ...` pragma in the file's first # 8 lines — the same escape the Hypatia scanner itself # honours. - name: Check banned-language files (ReScript / Go / Python / Java / Kotlin / Groovy / Swift / Dart / V-lang / ATS2 / Makefile) run: | rule_module="cicd_rules" rule_type="banned_language_file" rule="${rule_module}/${rule_type}" # Baseline lookup: returns 0 (exempt) if the file appears in # .hypatia-baseline.json with a matching rule_module + type. # Honours both `file` (exact) and `file_pattern` (glob) entries. # The glob → regex translation mirrors apply-baseline.sh exactly: # `**` matches any depth (incl. `/`); `*` matches one segment. # Pattern support unblocks language-demo repos (absolute-zero # carries ~30 banned-language example files under `examples/`) # and any repo that vendors such subtrees, replacing per-file # `.hypatia-ignore` enumeration with one `file_pattern` entry. in_baseline() { local target="$1" [ -f .hypatia-baseline.json ] || return 1 command -v jq >/dev/null 2>&1 || return 1 # Note: the `as $pat` capture is essential — inside `test(...)` # the dot rebinds to test's input ($f, a string), so # `.file_pattern` would error with "Cannot index string". We # capture file_pattern in $pat first, then reference it inside # the test() argument. jq -e \ --arg rm "$rule_module" \ --arg rt "$rule_type" \ --arg f "$target" \ 'any(.[]; .rule_module == $rm and .type == $rt and ( (.file? // null) == $f or ( (.file_pattern? // null) as $pat | $pat != null and ($f | test( $pat | gsub("\\*\\*"; "DOUBLESTAR") | gsub("\\*"; "[^/]*") | gsub("DOUBLESTAR"; ".*") | "^" + . + "$" )) ) ))' \ .hypatia-baseline.json >/dev/null 2>&1 } is_exempt() { f="${1#./}" if in_baseline "$f"; then echo "⏭️ exempt (baseline): $f" return 0 fi if [ -f .hypatia-ignore ] && grep -qxF "${rule}:${f}" .hypatia-ignore; then return 0 fi if head -n 8 "$1" 2>/dev/null | grep -q "hypatia:ignore.*${rule}"; then return 0 fi return 1 } # $1 = human label, $2 = remediation hint, $3 = newline-separated # candidate paths (possibly empty). Reads via here-string so this # runs in the current shell — no subshell, exit propagates. enforce() { label="$1"; hint="$2"; candidates="$3"; violations="" while IFS= read -r f; do [ -z "$f" ] && continue if is_exempt "$f"; then echo "⏭️ exempt (${rule}): $f" continue fi violations="${violations}${f} " done <<< "$candidates" if [ -n "$(printf '%s' "$violations" | tr -d '[:space:]')" ]; then echo "❌ ${label} detected - ${hint}" printf '%s' "$violations" echo " (declare an exemption via .hypatia-ignore or an inline" echo " '# hypatia:ignore ${rule}' pragma if intentional)" exit 1 fi echo "✅ No non-exempt ${label}" } # Use `git ls-files` instead of `find` so only TRACKED files are # inspected. This respects .gitignore by definition — vendored # deps in deps/, node_modules/, _build/ etc. are never tracked # and cannot produce false-positives. Root cause for the switch: # developer-ecosystem@baab1534 had false-positive governance # failures because `find` crawled gitignored vendor directories. # `git ls-files` works correctly on fresh PR checkouts because # actions/checkout populates the index before running workflows. RES_FILES=$(git ls-files '*.res' || true) GO_FILES=$(git ls-files '*.go' || true) PY_FILES=$(git ls-files '*.py' \ | grep -v venv | grep -v __pycache__ || true) MAKE_FILES=$(git ls-files 'Makefile' 'Makefile.*' '*.mk' \ | grep -v '\.github/' || true) # Platform-required JVM shims carve-out 2026-06-02: # Java is permitted only in Android source trees # (android/**/src/**/*.java) because Android instantiates # Service/BroadcastReceiver/AppWidgetProvider/Activity classes by # name at platform boundaries — Rust/Zig cannot provide JVM # bytecode for these. Each Android Java shim must be a minimal # delegating wrapper (typically <10 LoC) that JNIs into Rust/Zig # immediately. # # Kotlin/Groovy: NO JVM-interop exemption (reverted 2026-06-24). # Kotlin is goodbye. There is NO carve-out for hand-written JVM # bindings: FFI/interop to other ecosystems MUST be authored as # Idris2-ABI → Zig FFI/API (Idris2 → C only as an absolute last # resort if Zig genuinely cannot reach the boundary), never as # Kotlin/Java/Groovy `bindings/*`. Mobile uses Tauri/Dioxus. The # only remaining Java carve-out is the minimal Android platform # shim above. `.groovy` is detected so it is banned everywhere. JAVA_FILES=$(git ls-files '*.java' '*.kt' '*.kts' '*.groovy' \ | grep -vE '(^|/)android/.*/src/.*\.java$' || true) SWIFT_FILES=$(git ls-files '*.swift' || true) DART_FILES=$(git ls-files '*.dart' 'pubspec.yaml' || true) # V-lang detected by manifest (v.mod / vpkg.json); the .v extension # collides with Verilog so we never key on it. VMOD_FILES=$(git ls-files 'v.mod' 'vpkg.json' || true) # ATS2 source extensions: rejected in favour of Idris2 / Rust/SPARK. ATS2_FILES=$(git ls-files '*.dats' '*.sats' '*.hats' || true) enforce "ReScript files" "use AffineScript instead" "$RES_FILES" enforce "Go files" "use Rust/WASM instead" "$GO_FILES" enforce "Python files" "Python is fully banned — use AffineScript/Rust/SPARK/Julia (SaltStack carveout removed 2026-01-03)" "$PY_FILES" enforce "Makefiles" "use Mustfile/justfile instead" "$MAKE_FILES" enforce "Java/Kotlin/Groovy files" "Kotlin is goodbye — apps use Tauri/Dioxus; FFI/interop must be Idris2-ABI -> Zig FFI (or Idris2 -> C as a last resort), NOT hand-written JVM bindings" "$JAVA_FILES" enforce "Swift files" "use Tauri/Dioxus instead" "$SWIFT_FILES" enforce "Flutter/Dart files" "use Tauri/Dioxus instead (Google lock-in)" "$DART_FILES" enforce "V-lang manifests (v.mod / vpkg.json)" "V-lang is banned since 2026-04-10 — migrate to Zig" "$VMOD_FILES" enforce "ATS2 files (.dats / .sats / .hats)" "use Idris2 or Rust/SPARK instead" "$ATS2_FILES" - name: Check for npm/bun artifacts # standards#67 — npm-avoidant: package-lock.json must never be tracked # estate-wide. Check recursively (not just root) to catch monorepo # sub-packages. See docs/JS-RUNTIME-POLICY.adoc. run: | LOCK_FILES=$(git ls-files 'package-lock.json' '**/package-lock.json' 2>/dev/null || true) BUN_FILES=$(find . -name "bun.lockb" -not -path "./.git/*" 2>/dev/null || true) YARN_FILES=$(find . -name "yarn.lock" -not -path "./.git/*" 2>/dev/null || true) NPMRC_FILES=$(find . -name ".npmrc" -not -path "./.git/*" 2>/dev/null || true) FAILED="" if [ -n "$LOCK_FILES" ]; then echo "❌ Tracked package-lock.json detected (standards#67 — npm-avoidant):" printf '%s\n' "$LOCK_FILES" FAILED=1 fi if [ -n "$BUN_FILES" ]; then echo "❌ bun.lockb detected. Use Deno instead." printf '%s\n' "$BUN_FILES" FAILED=1 fi if [ -n "$YARN_FILES" ]; then echo "❌ yarn.lock detected. Use Deno instead." printf '%s\n' "$YARN_FILES" FAILED=1 fi if [ -n "$NPMRC_FILES" ]; then echo "❌ .npmrc detected. Use Deno deno.json for JS config." printf '%s\n' "$NPMRC_FILES" FAILED=1 fi # Root package.json with runtime "dependencies" — moved here from # the now-deleted language-policy.yml. devDependencies-only is # tolerated for transitional tooling (e.g., a legacy bundler # invoked from Justfile), but a `"dependencies"` field # indicates Node.js runtime use, which Deno replaces. if [ -f package.json ] && grep -q '"dependencies"[[:space:]]*:[[:space:]]*{[^}]' package.json; then echo "❌ package.json with runtime \"dependencies\" detected. Use deno.json imports instead." FAILED=1 fi if [ -n "$FAILED" ]; then echo "See hyperpolymath/standards docs/JS-RUNTIME-POLICY.adoc for remediation." exit 1 fi echo "✅ No npm/bun violations" - name: Check for tsconfig / rescript config # Honours the same `.hypatia-ignore` exemption mechanism as the # banned-language-files step (standards#72, Explicit-Escape # Principle). A config file is exempt if either # * `.hypatia-ignore` contains the exact line # `cicd_rules/banned_config_file:`, OR # * the file carries an inline `# hypatia:ignore … banned_config_file` # pragma in its first 8 lines (works for JSONC-style configs; # not for strict JSON variants). # Required so repos that legitimately retain ReScript while in # mid-migration (per their `.claude/CLAUDE.md`, e.g. verisimdb) # can declare the exemption explicitly instead of being globally # blocked. Same pattern as the .res file step above. run: | rule="cicd_rules/banned_config_file" is_exempt() { f="$1" if [ -f .hypatia-ignore ] && grep -qxF "${rule}:${f}" .hypatia-ignore; then return 0 fi if head -n 8 "$f" 2>/dev/null | grep -q "hypatia:ignore.*${rule}"; then return 0 fi return 1 } check_config() { cfg="$1"; hint="$2" if [ -f "$cfg" ]; then if is_exempt "$cfg"; then echo "⏭️ exempt (${rule}): $cfg" return 0 fi echo "❌ ${cfg} detected - ${hint}" echo " (declare an exemption via .hypatia-ignore line" echo " '${rule}:${cfg}' if intentional)" exit 1 fi } check_config "tsconfig.json" "use AffineScript instead" check_config "rescript.json" "use AffineScript config instead" check_config "bsconfig.json" "use AffineScript config instead" echo "✅ No non-exempt tsconfig.json / rescript config" - name: Summary run: | echo "RSR language/package policy passed — allowed: AffineScript, Deno," echo "WASM, Rust, OCaml, Haskell, Guile/Scheme." package-policy: name: Guix primary / Nix fallback policy runs-on: ${{ inputs.runs-on }} timeout-minutes: 10 permissions: contents: read steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: repository: ${{ github.repository }} # Pin to the concrete event SHA (the PR merge commit on # pull_request, the pushed commit on push). Do NOT use # `ref: ${{ github.ref }}`: in a reusable workflow called from a # pull_request, github.ref is the named merge ref # `refs/pull//merge`, which actions/checkout cannot fetch # ("couldn't find remote ref refs/pull//merge") — it broke 8/10 # governance jobs on every PR estate-wide. github.sha resolves to the # same merge commit but is always fetchable. ref: ${{ github.sha }} # A reusable workflow only auto-checks-out its own YAML, not sibling # scripts. Sparse-check-out standards' scripts/ to get # check-package-policy.sh, mirroring the baseline-filter job above. - name: Check out standards for the package-policy gate uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: repository: hyperpolymath/standards ref: main path: .standards-checkout sparse-checkout: | scripts sparse-checkout-cone-mode: false - name: Enforce Guix primary / Nix fallback run: | # Move the checker OUT of the scanned tree and delete the standards # checkout before scanning: the gate walks the whole caller tree, so # a packaging file shipped inside .standards-checkout/ would satisfy # the policy on the caller's behalf (same trap as the baseline job). cp .standards-checkout/scripts/check-package-policy.sh "$RUNNER_TEMP/" rm -rf .standards-checkout bash "$RUNNER_TEMP/check-package-policy.sh" . security-policy: name: Security policy checks runs-on: ${{ inputs.runs-on }} timeout-minutes: 10 permissions: contents: read steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: repository: ${{ github.repository }} # Pin to the concrete event SHA (the PR merge commit on # pull_request, the pushed commit on push). Do NOT use # `ref: ${{ github.ref }}`: in a reusable workflow called from a # pull_request, github.ref is the named merge ref # `refs/pull//merge`, which actions/checkout cannot fetch # ("couldn't find remote ref refs/pull//merge") — it broke 8/10 # governance jobs on every PR estate-wide. github.sha resolves to the # same merge commit but is always fetchable. ref: ${{ github.sha }} - name: Security checks run: | FAILED=false WEAK_CRYPTO=$(grep -rE 'md5\(|sha1\(' --include="*.py" --include="*.rb" --include="*.js" --include="*.ts" --include="*.go" --include="*.rs" . 2>/dev/null | grep -v 'checksum\|cache\|test\|spec' | head -5 || true) if [ -n "$WEAK_CRYPTO" ]; then echo "⚠️ Weak crypto (MD5/SHA1) detected. Use SHA256+ for security:" echo "$WEAK_CRYPTO" fi HTTP_URLS=$(grep -rE 'http://[^l][^o][^c]' --include="*.py" --include="*.js" --include="*.ts" --include="*.go" --include="*.rs" --include="*.yaml" --include="*.yml" . 2>/dev/null | grep -v 'localhost\|127.0.0.1\|example\|test\|spec' | head -5 || true) if [ -n "$HTTP_URLS" ]; then echo "⚠️ HTTP URLs found. Use HTTPS:" echo "$HTTP_URLS" fi SECRETS=$(grep -rEi '(api_key|apikey|secret_key|password)\s*[=:]\s*["\x27][A-Za-z0-9+/=]{20,}' --include="*.py" --include="*.js" --include="*.ts" --include="*.go" --include="*.rs" --include="*.env" . 2>/dev/null | grep -v 'example\|sample\|test\|mock\|placeholder' | head -3 || true) if [ -n "$SECRETS" ]; then echo "❌ Potential hardcoded secrets detected!" FAILED=true fi if [ "$FAILED" = true ]; then exit 1 fi echo "✅ Security policy check passed" - name: SSH-remote policy (token-in-URL detection) # Estate Remote-URL policy (standards#69 / REMOTE-URL-POLICY.adoc). # Scans every .git/config present in the checkout tree for token-in-URL # remotes. Fails hard so a compromised credential cannot silently reach # a PR or main-branch push. run: | found=0 while IFS= read -r cfg; do if grep -qE "url[[:space:]]*=[[:space:]]*https://[^[:space:]]*(x-access-token:|:gho_|:ghp_|:ghs_|:github_pat_)" "$cfg" 2>/dev/null; then echo "❌ token-in-URL remote detected in: $cfg" grep -E "url[[:space:]]*=" "$cfg" \ | sed 's/\(x-access-token:\|gho_\|ghp_\|ghs_\|github_pat_\)[^@]*/\1****/g' found=$((found + 1)) fi done < <(find . -name "config" -path "*/.git/config" 2>/dev/null) if [ "$found" -gt 0 ]; then echo "" echo "Remediation: git remote set-url git@github.com:/.git" echo "Policy: REMOTE-URL-POLICY.adoc — SSH-only remotes; no PAT/token in URL ever." exit 1 fi echo "✅ SSH-remote policy: no token-in-URL remotes detected" - name: Tooling version integrity # Estate Tooling Version Integrity policy (root cause: burble#39). # Inline + dependency-free so it runs in any caller repo. # R0 just>=1.19.0 floor (blocking when just present) and R1 # unversioned family-tool install (blocking) are hard; R4 # unexplained continue-on-error is advisory-first per the # documented "advisory now, --strict later" gating doctrine. run: | set -uo pipefail FAMILY='just|must|trust|adjust|bust|dust|intend' if command -v just >/dev/null 2>&1; then jv=$(just --version 2>/dev/null | cut -d' ' -f2) maj=${jv%%.*}; rest=${jv#*.}; min=${rest%%.*} if [ -z "$jv" ] || ! { [ "${maj:-0}" -gt 1 ] || { [ "${maj:-0}" -eq 1 ] && [ "${min:-0}" -ge 19 ]; }; }; then echo "❌ [R0] just ${jv:-?} < 1.19.0 — import? unsupported"; exit 1 fi echo "✅ [R0] just $jv >= 1.19.0" else echo "ℹ️ [R0] just not on PATH — skipped" fi R1=0 if [ -d .github/workflows ]; then while IFS= read -r hit; do [ -n "$hit" ] || continue echo "❌ [R1] unversioned family-tool install: $hit" R1=$((R1+1)) done < <(grep -rnE "^[[:space:]]*tool:[[:space:]]*(${FAMILY})[[:space:]]*$" .github/workflows 2>/dev/null || true) fi [ "$R1" -gt 0 ] && { echo "❌ [R1] $R1 unversioned family-tool install(s) — pin tool: @"; exit 1; } echo "✅ Tooling version integrity passed (R1 clean; R4 advisory via standards/tasks/tooling-integrity-lint.sh)" - name: Documentation version-string drift (R5b) # Estate canonical-reference drift policy. Forbids pinned # `Version: x.y.z` strings in load-bearing top-level docs # because they reliably go stale and disagree with each other # (echidna had v1.5.0 in README.adoc, v2.3.0 in CLAUDE.md, # v2.1.0 in Cargo.toml simultaneously — cleared by echidna#169 # / #170 / #171). CHANGELOG.md is the canonical release-history # surface; Cargo.toml's [package].version is the canonical # semver pin; the git log carries dates. Duplicating either # in human prose invites drift. # # Scope: repo-root *.md + *.adoc only. Sub-tree historical # docs (docs/handover/, docs/decisions/, docs/releases/, # audit reports) are owner-managed snapshots and not in # scope. CHANGELOG.{md,adoc} explicitly skipped. # # Companion rule R5a (bare prover counts) is repo-local where # the count semantics are domain-specific — see # `echidna/.github/workflows/governance-doc-drift.yml`. run: | set -uo pipefail PATTERN='^[[:space:]]*[*_]{0,2}Version[*_]{0,2}[[:space:]]*[:=][[:space:]]*v?[0-9]+\.[0-9]+\.[0-9]+' R5B=0 shopt -s nullglob for doc in *.md *.adoc; do [ -f "$doc" ] || continue case "$doc" in CHANGELOG.md|CHANGELOG.adoc) continue ;; esac while IFS= read -r hit; do [ -n "$hit" ] || continue echo "❌ [R5b] pinned version string: $doc:$hit" R5B=$((R5B+1)) done < <(grep -nE "$PATTERN" "$doc" 2>/dev/null || true) done if [ "$R5B" -gt 0 ]; then echo "" echo "❌ [R5b] $R5B pinned version-string line(s) in load-bearing docs." echo "Fix: drop the embedded version; defer to CHANGELOG.md (release" echo "history) and Cargo.toml's [package].version (semver pin) or the" echo "equivalent package manifest. Git log carries dates." exit 1 fi echo "✅ [R5b] Documentation version-string drift: clean." - name: Canonical-reference drift (R5 generic) # Repo-local canonical-reference rules. Reads # `.github/canonical-references/*.{yml,yaml}` in the calling # repo; each file declares one drift pattern with its # canonical pointer. Skipped silently when the directory is # absent — repos opt in by creating it. # # Generalises echidna's R5a (bare prover counts → docs/PROVER_COUNT.md) # so sibling repos with their own canonical-reference cohorts # (lemma counts for proven, stdlib fn counts for affinescript, # proof-obligation counts for typed-wasm, rule counts for # ephapax, …) can declare their drift patterns without # carrying a per-repo workflow. # # Rule file shape: # id: short-slug # description: one-line summary # patterns: [POSIX-ERE strings] # canonical_pointer: path/to/single-source-of-truth.md # scope: # include: [list, of, files, to, scan] # # Patterns are POSIX-ERE (run through `grep -E`). Each # listed include path is scanned line-by-line; a match emits # a `::error::` annotation and the job fails non-zero. # CHANGELOG.{md,adoc} and the rule files themselves are # excluded automatically; the rule's own `canonical_pointer` # is also excluded so the canonical doc can name what it # is the canonical answer for. run: | set -uo pipefail DIR=.github/canonical-references if [ ! -d "$DIR" ]; then echo "ℹ️ [R5] no $DIR/ — skipped (repo has not opted in)" exit 0 fi if ! command -v python3 >/dev/null 2>&1; then echo "❌ [R5] python3 missing on runner — required for YAML rule parsing" exit 2 fi python3 - <<'PY' import os, sys, glob, subprocess try: import yaml except ImportError: sys.exit("❌ [R5] PyYAML not installed on runner; install python3-yaml") dir_ = ".github/canonical-references" files = sorted(glob.glob(f"{dir_}/*.yml") + glob.glob(f"{dir_}/*.yaml")) if not files: print(f"ℹ️ [R5] {dir_}/ has no .yml/.yaml rules — skipped") sys.exit(0) total = 0 for rf in files: with open(rf, encoding="utf-8") as fh: cfg = yaml.safe_load(fh) if not isinstance(cfg, dict): print(f"❌ [R5] {rf}: top-level must be a mapping"); total += 1; continue rid = cfg.get("id", os.path.basename(rf)) desc = cfg.get("description", "") pats = cfg.get("patterns") or [] canon = cfg.get("canonical_pointer", "") scope = (cfg.get("scope") or {}) includes = scope.get("include") or [] if not pats or not includes: print(f"❌ [R5:{rid}] missing patterns or scope.include in {rf}") total += 1; continue # exclude self-references skip = set(["CHANGELOG.md", "CHANGELOG.adoc", rf]) if canon: skip.add(canon) rule_hits = 0 for f_ in includes: if f_ in skip or not os.path.isfile(f_): continue for pat in pats: r = subprocess.run( ["grep", "-nE", pat, f_], capture_output=True, text=True, ) if r.returncode == 0: for line in r.stdout.splitlines(): ln_no, _, body = line.partition(":") tail = canon or "drop or move to a canonical source" print(f"::error file={f_},line={ln_no}::" f"[R5:{rid}] {body} → route to {tail}") rule_hits += 1 elif r.returncode > 1: print(f"❌ [R5:{rid}] grep error on {f_}: {r.stderr.strip()}") rule_hits += 1 if rule_hits: print(f"❌ [R5:{rid}] {rule_hits} hit(s). {desc}") total += rule_hits if total: print() print(f"❌ [R5] {total} canonical-reference drift hit(s) across {len(files)} rule(s).") sys.exit(1) print(f"✅ [R5] canonical-reference drift: clean across {len(files)} rule(s).") PY quality: name: Code quality + docs runs-on: ${{ inputs.runs-on }} timeout-minutes: 10 permissions: contents: read steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: repository: ${{ github.repository }} # Pin to the concrete event SHA (the PR merge commit on # pull_request, the pushed commit on push). Do NOT use # `ref: ${{ github.ref }}`: in a reusable workflow called from a # pull_request, github.ref is the named merge ref # `refs/pull//merge`, which actions/checkout cannot fetch # ("couldn't find remote ref refs/pull//merge") — it broke 8/10 # governance jobs on every PR estate-wide. github.sha resolves to the # same merge commit but is always fetchable. ref: ${{ github.sha }} - name: Check file permissions run: | find . -type f -perm /111 -name "*.sh" | head -10 || true # NOTE: the advisory trufflehog scan that used to sit here was removed # (standards#505). It was `continue-on-error: true`, so it never gated, # and it duplicated the estate's real secret gate — gitleaks in # secret-scanner-reusable.yml, which became genuinely blocking in #500 # (pinned + checksummed binary, `--exit-code 1`, no continue-on-error). # secret-scanner-reusable's own header already claimed "Trufflehog removed # as redundant"; keeping it here contradicted that across the same estate. # Removing a never-failing step cannot newly-red any caller. - name: Check TODO/FIXME run: | echo "=== TODOs ===" grep -rn "TODO\|FIXME\|HACK\|XXX" --include="*.rs" --include="*.res" --include="*.py" --include="*.ex" . | head -20 || echo "None found" - name: Check for large files run: | find . -type f -size +1M -not -path "./.git/*" | head -10 || echo "No large files" - name: EditorConfig check uses: editorconfig-checker/action-editorconfig-checker@840e866d93b8e032123c23bac69dece044d4d84c # v2.2.0 # advisory: formatting hygiene is reported from the reusable estate # bundle; repos opt into blocking formatter checks locally when ready. continue-on-error: true # Sparse-check-out standards' scripts/ for the docs gate (a reusable # workflow only auto-checks-out its own YAML, not sibling scripts). - name: Check out standards for the docs gate uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: repository: hyperpolymath/standards ref: main path: .standards-checkout sparse-checkout: | scripts sparse-checkout-cone-mode: false - name: Check documentation run: | # Split gate (standards#505): README + LICENSE block immediately — # measured 0/412 callers missing either, so arming them reds nobody. # CONTRIBUTING (54/412 missing) warns until the cutoff baked into the # script, then blocks. See scripts/check-docs-presence.sh. cp .standards-checkout/scripts/check-docs-presence.sh "$RUNNER_TEMP/" rm -rf .standards-checkout bash "$RUNNER_TEMP/check-docs-presence.sh" . wellknown: name: Well-Known (RFC 9116 + RSR) runs-on: ${{ inputs.runs-on }} timeout-minutes: 10 permissions: contents: read steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: repository: ${{ github.repository }} # Pin to the concrete event SHA (the PR merge commit on # pull_request, the pushed commit on push). Do NOT use # `ref: ${{ github.ref }}`: in a reusable workflow called from a # pull_request, github.ref is the named merge ref # `refs/pull//merge`, which actions/checkout cannot fetch # ("couldn't find remote ref refs/pull//merge") — it broke 8/10 # governance jobs on every PR estate-wide. github.sha resolves to the # same merge commit but is always fetchable. ref: ${{ github.sha }} - name: RFC 9116 security.txt validation run: | SECTXT="" [ -f ".well-known/security.txt" ] && SECTXT=".well-known/security.txt" [ -f "security.txt" ] && SECTXT="security.txt" if [ -z "$SECTXT" ]; then echo "::warning::No security.txt found." exit 0 fi grep -q "^Contact:" "$SECTXT" || { echo "::error::Missing Contact field"; exit 1; } if ! grep -q "^Expires:" "$SECTXT"; then echo "::error::Missing Expires field" exit 1 fi EXPIRES=$(grep "^Expires:" "$SECTXT" | cut -d: -f2- | tr -d ' ' | head -1) if date -d "$EXPIRES" > /dev/null 2>&1; then DAYS=$(( ($(date -d "$EXPIRES" +%s) - $(date +%s)) / 86400 )) if [ $DAYS -lt 0 ]; then echo "::error::security.txt EXPIRED" exit 1 elif [ $DAYS -lt 30 ]; then echo "::warning::security.txt expires in $DAYS days" else echo "✅ security.txt valid ($DAYS days)" fi fi - name: RSR well-known compliance run: | MISSING="" [ ! -f ".well-known/security.txt" ] && [ ! -f "security.txt" ] && MISSING="$MISSING security.txt" [ ! -f ".well-known/ai.txt" ] && MISSING="$MISSING ai.txt" [ ! -f ".well-known/humans.txt" ] && MISSING="$MISSING humans.txt" if [ -n "$MISSING" ]; then echo "::warning::Missing RSR recommended files:$MISSING" else echo "✅ RSR well-known compliant" fi - name: Mixed content check run: | MIXED=$(grep -rE 'src="http://|href="http://' --include="*.html" --include="*.htm" . 2>/dev/null | grep -vE 'localhost|127\.0\.0\.1|example\.com|lol/|node_modules/|third-party/|vendor/' | head -5 || true) if [ -n "$MIXED" ]; then echo "::error::Mixed content (HTTP in HTML)" echo "$MIXED" exit 1 fi echo "✅ No mixed content" workflow-lint: name: Workflow security linter runs-on: ${{ inputs.runs-on }} timeout-minutes: 10 permissions: contents: read steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: repository: ${{ github.repository }} # Pin to the concrete event SHA (the PR merge commit on # pull_request, the pushed commit on push). Do NOT use # `ref: ${{ github.ref }}`: in a reusable workflow called from a # pull_request, github.ref is the named merge ref # `refs/pull//merge`, which actions/checkout cannot fetch # ("couldn't find remote ref refs/pull//merge") — it broke 8/10 # governance jobs on every PR estate-wide. github.sha resolves to the # same merge commit but is always fetchable. ref: ${{ github.sha }} - name: Check SPDX headers + permissions run: | failed=0 for file in .github/workflows/*.yml .github/workflows/*.yaml; do [ -f "$file" ] || continue if ! head -1 "$file" | grep -q "^# SPDX-License-Identifier:"; then echo "ERROR: $file missing SPDX header"; failed=1 fi if ! grep -q "^permissions:" "$file"; then echo "ERROR: $file missing top-level 'permissions:' declaration"; failed=1 fi done [ $failed -eq 1 ] && { echo "Add SPDX header + permissions:"; exit 1; } echo "All workflows have SPDX headers + permissions" - name: Check SHA-pinned actions run: | unpinned=$(grep -rnE "^[[:space:]]+uses:" .github/workflows/ | \ grep -v "@[a-f0-9]\{40\}" | \ grep -v "uses: \./\|uses: docker://\|uses: actions/github-script\|uses: hyperpolymath/standards/" || true) if [ -n "$unpinned" ]; then echo "ERROR: Found unpinned actions:" echo "$unpinned" exit 1 fi echo "All actions are SHA-pinned" - name: Check for duplicate workflows run: | if [ -f .github/workflows/codeql.yml ] && [ -f .github/workflows/codeql-analysis.yml ]; then echo "ERROR: Duplicate CodeQL workflows found"; exit 1 fi echo "No critical duplicates found" trusted-base: name: Trusted-base reduction policy runs-on: ${{ inputs.runs-on }} timeout-minutes: 10 permissions: contents: read steps: - name: Checkout caller repository uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: repository: ${{ github.repository }} # Pin to the concrete event SHA (the PR merge commit on # pull_request, the pushed commit on push). Do NOT use # `ref: ${{ github.ref }}`: in a reusable workflow called from a # pull_request, github.ref is the named merge ref # `refs/pull//merge`, which actions/checkout cannot fetch # ("couldn't find remote ref refs/pull//merge") — it broke 8/10 # governance jobs on every PR estate-wide. github.sha resolves to the # same merge commit but is always fetchable. ref: ${{ github.sha }} path: caller - name: Checkout standards (for the check script) uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: repository: hyperpolymath/standards ref: main path: standards - name: Run trusted-base check on caller repo run: | bash standards/scripts/check-trusted-base.sh caller licence-consistency: timeout-minutes: 10 name: Licence consistency runs-on: ${{ inputs.runs-on }} permissions: contents: read steps: - name: Checkout caller repository uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: repository: ${{ github.repository }} # Pin to the concrete event SHA (the PR merge commit on # pull_request, the pushed commit on push). Do NOT use # `ref: ${{ github.ref }}`: in a reusable workflow called from a # pull_request, github.ref is the named merge ref # `refs/pull//merge`, which actions/checkout cannot fetch # ("couldn't find remote ref refs/pull//merge") — it broke 8/10 # governance jobs on every PR estate-wide. github.sha resolves to the # same merge commit but is always fetchable. ref: ${{ github.sha }} path: caller - name: Checkout standards (for the check script) uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: repository: hyperpolymath/standards ref: main path: standards - name: Run licence-consistency check on caller repo run: | bash standards/scripts/check-licence-consistency.sh caller