From 7c33c14f61d420a7f7c101f1fa0a7519919cec37 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Nov 2026 02:34:13 +0000 Subject: [PATCH 1/3] fix(ci-gate): drop 4-byte characters from status descriptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GitHub's statuses API refuses a description holding any 4-byte UTF-8 character ("Description doesn't accept 4-byte Unicode"). Required job names can carry one (e.g. "🔴 GATE: ..."), so the publisher's POST failed and no CI/gate verdict was posted on resource-algebra#55 and rsr-template-repo#451. clip() now drops every code point above U+FFFF before the 140-character clip. The test fake gh rejects 4-byte descriptions as GitHub does, and new cases cover failure and pending verdicts for an emoji job name. Tests: ci-gate 546/0 on jq 1.6, 1.7.1, 1.8.0, 1.8.1 and system jq (old clip: 544/2); ci-gate-tamper-guard 125/0. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01J4QvDg8YzLVHtwwDfcY3J9 --- scripts/ci-gate-publish.sh | 5 ++++- tests/ci-gate.sh | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/scripts/ci-gate-publish.sh b/scripts/ci-gate-publish.sh index a3f1b707..968980a6 100644 --- a/scripts/ci-gate-publish.sh +++ b/scripts/ci-gate-publish.sh @@ -61,7 +61,10 @@ published=0 declare -A completed_keys=() completed_jobs=() poll_cost=10 -clip() { jq -rn --arg d "$1" 'if ($d | length) > 140 then $d[0:139] + "…" else $d end'; } # by characters, whatever the locale +# GitHub's statuses API refuses a description that holds any 4-byte UTF-8 character ("Description +# doesn't accept 4-byte Unicode"), and required job names can carry one (e.g. "🔴 GATE: ..."), so +# every code point above U+FFFF is dropped before the 140-character clip. Every POST goes through here. +clip() { jq -rn --arg d "$1" '($d | explode | map(select(. < 65536)) | implode | sub("^ +"; "") | gsub(" +"; " ")) as $s | if ($s | length) > 140 then $s[0:139] + "…" else $s end'; } # by characters, whatever the locale current_matches() { # -> prints "same" only if the combined status holds exactly this for $CONTEXT local r diff --git a/tests/ci-gate.sh b/tests/ci-gate.sh index 677a9774..4b796b6f 100644 --- a/tests/ci-gate.sh +++ b/tests/ci-gate.sh @@ -250,6 +250,8 @@ if [[ " $* " == *" -X POST "* ]]; then state=''; desc=''; psha=''; ctx='' for a in "$@"; do case $a in state=*) state=${a#state=} ;; description=*) desc=${a#description=} ;; context=*) ctx=${a#context=} ;; repos/*/statuses/*) psha=${a##*/} ;; esac; done [[ ! -f $D/failpost ]] || { echo "gh: HTTP 500 (post)" >&2; exit 1; } + # GitHub refuses a status description with any 4-byte UTF-8 character; so does this fake. + if printf '%s' "$desc" | LC_ALL=C grep -q $'[\xF0-\xF4]'; then echo "gh: Validation failed: Description doesn't accept 4-byte Unicode (Validation Failed)" >&2; exit 1; fi # a newer evaluator's write that lands just before this one (deterministic pause control) if [[ -f $D/prepost ]]; then cat "$D/prepost" >> "$D/posts.log" @@ -377,6 +379,21 @@ publish chk "stale failure not written when the runs moved; re-evaluated: failure on settled data" "$(post_n 1 | cut -f1)" failure chk "failure verdict: exit 1" "$RC" 1 chk "failure verdict: names the job" "$(post_n 1 | cut -f2 | grep -c 'Test (failure)')" 1 +echo "-- a required job name with a 4-byte character (GitHub refuses those in a status description) --" +cp "$SUITE_DIR/profiles/ci-gate/example/repo.json" "$WORK/repo.profile.bak" +jq -c '.checks |= map(if .job == "Test" then .job = "🔴 Test" else . end)' "$WORK/repo.profile.bak" > "$SUITE_DIR/profiles/ci-gate/example/repo.json" +pubreset; snap 1 "$DONE" +jq 'map(if .name == "Test" then .name = "🔴 Test" | .conclusion = "failure" else . end)' "$FX/jobs.json" > "$FAKEGH/jobs.json" +publish +chk "emoji job failing: the failure verdict is published, not refused" "$(post_n 1 | cut -f1)/$NPOSTS" "failure/1" +chk "emoji job failing: exit 1 (the verdict), not a publish error" "$RC/$(grep -c 'could not publish' <<<"$PUBOUT")" "1/0" +chk "emoji job failing: the description still names the job" "$(post_n 1 | cut -f2 | grep -c 'Test (failure)')" 1 +chk "emoji job failing: no 4-byte character reaches the description" "$(post_n 1 | cut -f2 | LC_ALL=C grep -c $'[\xF0-\xF4]')" 0 +pubreset; snap 1 "map(if .id == 12 then .status = \"in_progress\" else . end)" +jq 'map(if .name == "Test" then .name = "🔴 Test" else . end)' "$FX/jobs.json" > "$FAKEGH/jobs.json" +publish +chk "emoji job pending: the pending verdict is published, not refused" "$(post_n 1 | cut -f1)/$(grep -c 'could not publish' <<<"$PUBOUT")" "pending/0" +cp "$WORK/repo.profile.bak" "$SUITE_DIR/profiles/ci-gate/example/repo.json" echo "-- errors fail closed --" pubreset; snap 1 "$DONE"; touch "$FAKEGH/fail.1"; publish chk "gh error on the first runs fetch: a failure POST" "$(post_n 1 | cut -f1)" failure From 3e904a451e8ec36801b4f5f1073cd172d4258847 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Nov 2026 03:03:20 +0000 Subject: [PATCH 2/3] feat(ci-gate): trigger on an explicit list of workflow names, not a glob workflow_run.workflows "**" started one gate run per completed workflow of the repository (about 22 per push), which with the polling exhausted the GitHub App installation's API quota on 2026-11-18. The suite's caller now lists the name: of each workflow in its profile; the template ships a placeholder that must be replaced. scripts/ci-gate-trigger-names.sh derives the list from a profile and fails (exit 2) on a missing file, a missing name, a glob character or the gate's own name. tests/ci-gate.sh pins the caller to the script's output, rejects globs in callers and template, and carries a control that the pin fails on the old glob. docs/CI-GATE.adoc documents the list and its liveness consequence. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01J4QvDg8YzLVHtwwDfcY3J9 --- .github/workflows/ci-gate-caller.yml | 8 ++++- docs/CI-GATE.adoc | 10 +++++- scripts/ci-gate-trigger-names.sh | 27 ++++++++++++++++ templates/ci-gate-caller.yml | 10 +++++- tests/ci-gate.sh | 36 ++++++++++++++++++++++ tests/fixtures/ci-gate/bad-glob-caller.yml | 6 ++++ tests/fixtures/ci-gate/bad-template.yml | 2 +- 7 files changed, 95 insertions(+), 4 deletions(-) create mode 100755 scripts/ci-gate-trigger-names.sh create mode 100644 tests/fixtures/ci-gate/bad-glob-caller.yml diff --git a/.github/workflows/ci-gate-caller.yml b/.github/workflows/ci-gate-caller.yml index 3dbb6556..bb26fe2f 100644 --- a/.github/workflows/ci-gate-caller.yml +++ b/.github/workflows/ci-gate-caller.yml @@ -15,13 +15,19 @@ # (repository, context, head SHA; cancel-in-progress) so that every consumer gets it with the pin, and # its sweep group is separate. The pull_request job at the end is permanent # (docs/CI-GATE.adoc, "The pull_request start"); tests/ci-gate.sh pins its shape. +# `workflow_run.workflows` is an EXPLICIT list, with no globs: it is the `name:` of every workflow file in +# the profile (profiles/ci-gate/hyperpolymath/proven-cicd-and-workflows.json), so a push starts one evaluation +# per listed workflow, not one per workflow of the repository. Regenerate it whenever the profile changes: +# scripts/ci-gate-trigger-names.sh profiles/ci-gate/hyperpolymath/proven-cicd-and-workflows.json . +# tests/ci-gate.sh pins it to that output. A required workflow missing from the list never triggers an +# evaluation (the sweep or a pull_request event still evaluates the commit; docs/CI-GATE.adoc, "Liveness"). # No `secrets:` line: the reusable consumes none. name: CI gate on: pull_request: workflow_run: - workflows: ["**", "!CI gate"] + workflows: ["Bounded secret scanner controls", "Central Estate CI/CD Audit", "Proven lock gate", "Secret Scanner", "Supplemental secret checks"] types: [completed] schedule: - cron: "7,22,37,52 * * * *" diff --git a/docs/CI-GATE.adoc b/docs/CI-GATE.adoc index a377d3f4..f20e53c1 100644 --- a/docs/CI-GATE.adoc +++ b/docs/CI-GATE.adoc @@ -15,7 +15,7 @@ A3 `estate-gate` replaces it by changing one pin and one context name in each ca == Design in one paragraph -The caller starts `gate-pr` on `pull_request` for same-repository branches (see "Bootstrap" and "The pull_request start"). Its default-branch `gate` job triggers on `workflow_run` (type `completed` only, any workflow but its own), on `schedule` (minutes 7, 22, 37 and 52 of every hour) and on `workflow_dispatch`; see "Sweep" below for the last two. Every evaluation reads the head commit with *two* requests, whatever the number of workflows: the workflow runs of the head SHA (`GET /repos/{repo}/actions/runs?head_sha=`) and the latest check runs of the commit (`GET /repos/{repo}/commits/{sha}/check-runs?filter=latest`), each over its pages of 100. The check runs are joined to their workflow run on check suite id (`check_suite_id` of the run, `check_suite.id` of the check run), which rebuilds the same per-job records the verdict has always read; the profile format and the verdict rules are unchanged except for the pending rules below. The reusable's job has a `concurrency` group keyed on repository, context and head SHA with `cancel-in-progress`, so the newest event for a commit replaces an evaluation of it that is still queued or running; the sweep has its own group. GitHub runs `workflow_run` workflows from the default branch, so a pull request cannot edit the caller, its pin or its list. The reusable reads the profile for `github.repository` from this suite at `job.workflow_sha`, runs the verdict script and posts one commit status. It is a commit status, not a check run, because a job in a reusable workflow gets the check-run name ` / `, which can never equal `CI/gate`. +The caller starts `gate-pr` on `pull_request` for same-repository branches (see "Bootstrap" and "The pull_request start"). Its default-branch `gate` job triggers on `workflow_run` (type `completed` only, and only for the workflows listed by name in `workflow_run.workflows`: an explicit list, with no globs, that must be the `name:` of each workflow in the profile; the gate's own workflow is never in it), on `schedule` (minutes 7, 22, 37 and 52 of every hour) and on `workflow_dispatch`; see "Sweep" below for the last two. Every evaluation reads the head commit with *two* requests, whatever the number of workflows: the workflow runs of the head SHA (`GET /repos/{repo}/actions/runs?head_sha=`) and the latest check runs of the commit (`GET /repos/{repo}/commits/{sha}/check-runs?filter=latest`), each over its pages of 100. The check runs are joined to their workflow run on check suite id (`check_suite_id` of the run, `check_suite.id` of the check run), which rebuilds the same per-job records the verdict has always read; the profile format and the verdict rules are unchanged except for the pending rules below. The reusable's job has a `concurrency` group keyed on repository, context and head SHA with `cancel-in-progress`, so the newest event for a commit replaces an evaluation of it that is still queued or running; the sweep has its own group. GitHub runs `workflow_run` workflows from the default branch, so a pull request cannot edit the caller, its pin or its list. The reusable reads the profile for `github.repository` from this suite at `job.workflow_sha`, runs the verdict script and posts one commit status. It is a commit status, not a check run, because a job in a reusable workflow gets the check-run name ` / `, which can never equal `CI/gate`. *Why it works this way (resource-algebra#50).* One push started 22 workflows. The previous design started an evaluation per started and per completed workflow, and each evaluation listed the jobs of every run (one request per run), again on every poll of a waiting pull request, plus a sweep every 15 minutes. That exhausted the installation token quota (`HTTP 403 API rate limit exceeded`), after which the gate published a failure for a commit whose every required check had passed, and a status stands until something overwrites it. Reading in bulk and coalescing remove most of that load. Neither can promise that the API stays available, so an unavailable API now ends in `pending`, never in a failure. @@ -87,6 +87,14 @@ On `schedule` and `workflow_dispatch` there is no triggering run, so the reusabl The reusable accepts `workflow_run`, `pull_request`, `schedule` and `workflow_dispatch`; only the last two sweep. The job needs `pull-requests: read` in addition to `statuses: write`, `actions: read`, `checks: read` and `contents: read`: *the caller must grant them*, or the pull request listing or the check-run read fails. A sweep writes statuses for pull request heads from forks too (the statuses API is keyed by commit in the base repository); it reads metadata only and never checks out or runs their code. +== Liveness: the trigger list + +`workflow_run.workflows` matches workflow *names* (the top-level `name:` of a workflow file), not file paths, while a profile lists workflow *files*. The caller therefore carries an explicit list, with no globs: the `name:` of each distinct workflow file in the profile. `scripts/ci-gate-trigger-names.sh PROFILE.json REPO-ROOT` prints that array (sorted, unique, one line) and exits 2, with a message, if a listed file is missing, has no `name:`, has a name containing `*`, `?`, `[`, `]` or `!`, or is named `CI gate`. Regenerate the list whenever the profile changes. `tests/ci-gate.sh` pins the suite's own caller to the script's output for the suite's profile. The consumers' list must be the profile's names: the template ships a placeholder that matches no workflow and must be replaced. + +A glob (`"**"`) was replaced because it started one gate run per completed workflow of the repository (about 22 per push on some repositories), which together with the polling exhausted the installation's API quota. + +*Consequence.* A required workflow that is missing from the list never triggers an evaluation. The commit then stays pending until the sweep (every 15 minutes) or a `pull_request` event evaluates it. Safety is unaffected: pending is never success, and a check that never reports fails after `timeout_minutes`. Only promptness is lost, so a stale list shows up as a slow gate, not as a false green. + == Workflow acceptance contract [cols="1,4",options="header"] diff --git a/scripts/ci-gate-trigger-names.sh b/scripts/ci-gate-trigger-names.sh new file mode 100755 index 00000000..d79e9062 --- /dev/null +++ b/scripts/ci-gate-trigger-names.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +# The `workflow_run.workflows` list of a CI/gate caller, derived from its profile. +# Usage: ci-gate-trigger-names.sh PROFILE.json REPO-ROOT +# `workflow_run.workflows` matches workflow NAMES (the top-level `name:` of a workflow file), not paths; +# a profile (profiles/ci-gate//.json) lists workflow FILES. This prints the JSON array +# (sorted, unique, one line) of the `name:` of each distinct workflow file the profile names. +# Exit 0 = printed; 2 = usage/tool error or an unusable workflow (file missing, no `name:`, a glob +# character in the name, or the name of the gate itself). Fail-closed: it never prints a partial list. +set -euo pipefail +GATE_NAME='CI gate' +[[ $# -eq 2 && -f $1 && -d $2 ]] || { echo 'usage: ci-gate-trigger-names.sh PROFILE.json REPO-ROOT' >&2; exit 2; } +command -v jq >/dev/null || { echo 'jq required' >&2; exit 2; } +command -v yq >/dev/null || { echo 'yq (mikefarah v4) required' >&2; exit 2; } +profile=$1 root=$2 +files=$(jq -r '.checks[].workflow' "$profile") || { echo "cannot read workflow files from $profile" >&2; exit 2; } +[[ -n $files ]] || { echo "profile $profile names no workflow" >&2; exit 2; } +names=() +while IFS= read -r wf; do + [[ -f $root/$wf ]] || { echo "workflow file missing: $wf" >&2; exit 2; } + name=$(yq -r '.name // ""' "$root/$wf") || { echo "cannot parse $wf" >&2; exit 2; } + [[ -n $name && $name != null ]] || { echo "workflow has no name: $wf" >&2; exit 2; } + [[ $name != *[\*\?\[\]\!]* ]] || { echo "workflow name contains a glob character (* ? [ ] !): '$name' in $wf" >&2; exit 2; } + [[ $name != "$GATE_NAME" ]] || { echo "workflow name is the gate's own ('$GATE_NAME'): $wf" >&2; exit 2; } + names+=("$name") +done < <(sort -u <<<"$files") +printf '%s\n' "${names[@]}" | jq -Rn -c '[inputs] | unique' diff --git a/templates/ci-gate-caller.yml b/templates/ci-gate-caller.yml index f35ac4f7..4be56070 100644 --- a/templates/ci-gate-caller.yml +++ b/templates/ci-gate-caller.yml @@ -51,13 +51,21 @@ # reusable also re-reads the runs just before it writes and re-evaluates when they moved # (scripts/ci-gate-publish.sh; tests/ci-gate.sh asserts the template has no concurrency of its own). # +# ⚠ REPLACE `workflow_run.workflows` below. It matches workflow NAMES (the top-level `name:` of a workflow +# file), never paths, and it must be an EXPLICIT list, with no globs: it is the `name:` of every workflow +# file in your profile. Generate it from a checkout of this suite and of your repository: +# proven-cicd-and-workflows/scripts/ci-gate-trigger-names.sh \ +# proven-cicd-and-workflows/profiles/ci-gate//.json +# and paste the printed array. Left unchanged, the placeholder matches no workflow, the gate is never +# triggered by a workflow_run, and any check that compares the list with this script's output (as +# tests/ci-gate.sh does for the suite's own caller) fails on it. Do not leave the placeholder. # No `secrets:` line: the reusable consumes none. name: CI gate on: pull_request: workflow_run: - workflows: ["**", "!CI gate"] + workflows: ["Replace with the name: of each workflow in your profile"] # PLACEHOLDER: see the comment above types: [completed] schedule: - cron: "7,22,37,52 * * * *" diff --git a/tests/ci-gate.sh b/tests/ci-gate.sh index ab5bbb7c..b20dbc55 100644 --- a/tests/ci-gate.sh +++ b/tests/ci-gate.sh @@ -1272,6 +1272,42 @@ for wf in $(jq -r '.checks[].workflow' "$SELFPROFILE" | sort -u); do [ -f "$ROOT/$wf" ] && ok "the suite's profile names an existing workflow $wf" || bad "the suite's profile names a missing workflow $wf" done + +echo "== the explicit workflow_run list (scripts/ci-gate-trigger-names.sh) ==" +NAMES="$ROOT/scripts/ci-gate-trigger-names.sh" +wfl() { yq -o=json -I=0 "$ON.workflow_run.workflows" "$1" 2> /dev/null; } # -> the list as JSON (null if absent) +list_of() { wfl "$1" | jq -c 'if type == "array" then sort else null end'; } # order-insensitive +globbad() { wfl "$1" | jq -c '[.[] | select(type != "string" or test("[*?\\[\\]!]") or . == "CI gate")] | length'; } # glob or gate name +want=$(bash "$NAMES" "$SELFPROFILE" "$ROOT" 2>/dev/null | jq -c 'sort') +[ -n "$want" ] && ok "the script prints a list for the suite's profile: $want" || bad "the script printed nothing for the suite's profile" +chk "the suite's caller workflow_run.workflows equals the script's output for the suite's profile" "$(list_of "$SELF")" "$want" +# The control: the same comparison must FAIL for the retired glob, so the check above can fail. +GLOBCALLER="$WORK/glob-caller.yml"; sed 's|^ workflows: \[.*\]$| workflows: ["**", "!CI gate"]|' "$SELF" > "$GLOBCALLER" +[ "$(wfl "$GLOBCALLER")" = '["**","!CI gate"]' ] && ok "control: the temporary caller really carries [\"**\", \"!CI gate\"]" || bad "control: the glob caller was not built" +[ "$(list_of "$GLOBCALLER")" != "$want" ] && ok "control: the equality check FAILS for a caller that still has [\"**\", \"!CI gate\"]" || bad "control: the equality check passed for the retired glob" +for f in "$SELF" "$TEMPLATE"; do + n=$(basename "$f") + chk "$n: workflow_run.workflows has no glob character and not the gate's own name" "$(globbad "$f")" 0 + chk "$n: workflow_run.workflows is a non-empty list" "$(wfl "$f" | jq -c 'type == "array" and length > 0')" true +done +chk "control: the glob check sees the retired glob in a planted caller" "$(globbad "$FX/bad-glob-caller.yml")" 2 +chk "the template's list is a placeholder that is not any profile's output (a consumer must replace it)" "$(wfl "$TEMPLATE" | jq -c 'length == 1 and (.[0] | startswith("Replace with"))')" true +echo "-- negative cases of the script: each exits 2 --" +NR="$WORK/names-root"; mkdir -p "$NR/.github/workflows" +printf 'name: Alpha build\non: push\n' > "$NR/.github/workflows/a.yml" +printf 'on: push\n' > "$NR/.github/workflows/noname.yml" +printf 'name: "Build *"\non: push\n' > "$NR/.github/workflows/glob.yml" +printf 'name: "!Alpha"\non: push\n' > "$NR/.github/workflows/bang.yml" +printf 'name: CI gate\non: push\n' > "$NR/.github/workflows/gate.yml" +np() { printf '{"checks":[%s],"repository":"example/repo","schema_version":2}\n' "$(jq -nr --args '$ARGS.positional | map("{\"job\":\"j\",\"workflow\":\".github/workflows/\(.)\"}") | join(",")' "$@")" > "$WORK/np.json"; } +np a.yml a.yml; OUT=$(bash "$NAMES" "$WORK/np.json" "$NR" 2>&1); RC=$? +chk "positive control: two jobs of one workflow give one name, exit 0" "$RC/$OUT" '0/["Alpha build"]' +for spec in missing.yml:missing noname.yml:'has no name' glob.yml:'glob character' bang.yml:'glob character' gate.yml:"gate's own"; do + wf=${spec%%:*}; msg=${spec#*:} + np a.yml "$wf"; OUT=$(bash "$NAMES" "$WORK/np.json" "$NR" 2>&1); RC=$? + [ "$RC" = 2 ] && [[ $OUT == *"$msg"* ]] && [ "$(grep -c '^\[' <<<"$OUT")" = 0 ] && ok "script: $wf exits 2 with '$msg' and prints no list" || bad "script: $wf gave exit $RC: $OUT" +done +bash "$NAMES" "$WORK/np.json" >/dev/null 2>&1; [ $? = 2 ] && ok "script: a missing argument exits 2" || bad "script: a missing argument did not exit 2" echo printf 'ci-gate: %d passed, %d failed\n' "$PASS" "$FAIL" [ "$FAIL" -eq 0 ] diff --git a/tests/fixtures/ci-gate/bad-glob-caller.yml b/tests/fixtures/ci-gate/bad-glob-caller.yml new file mode 100644 index 00000000..197b5769 --- /dev/null +++ b/tests/fixtures/ci-gate/bad-glob-caller.yml @@ -0,0 +1,6 @@ +# Negative control: a caller whose workflow_run list is the retired glob. +name: CI gate +on: + workflow_run: + workflows: ["**", "!CI gate"] + types: [completed] diff --git a/tests/fixtures/ci-gate/bad-template.yml b/tests/fixtures/ci-gate/bad-template.yml index fe5d7ac8..2c1e1f2b 100644 --- a/tests/fixtures/ci-gate/bad-template.yml +++ b/tests/fixtures/ci-gate/bad-template.yml @@ -3,7 +3,7 @@ name: CI gate on: pull_request: workflow_run: - workflows: ["**"] + workflows: ["Example check"] types: [completed] concurrency: group: ci-gate-x From db4d73ec8f8d0338335b36027dc4db322f14f378 Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Wed, 18 Nov 2026 19:12:25 +0000 Subject: [PATCH 3/3] fix(ci-gate): reject plus signs in trigger names and document stale-success risks --- docs/CI-GATE.adoc | 4 ++-- scripts/ci-gate-trigger-names.sh | 2 +- tests/ci-gate.sh | 7 +++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/CI-GATE.adoc b/docs/CI-GATE.adoc index 70e7a046..b21406f8 100644 --- a/docs/CI-GATE.adoc +++ b/docs/CI-GATE.adoc @@ -100,11 +100,11 @@ The reusable accepts `workflow_run`, `pull_request`, `schedule` and `workflow_di == Liveness: the trigger list -`workflow_run.workflows` matches workflow *names* (the top-level `name:` of a workflow file), not file paths, while a profile lists workflow *files*. The caller therefore carries an explicit list, with no globs: the `name:` of each distinct workflow file in the profile. `scripts/ci-gate-trigger-names.sh PROFILE.json REPO-ROOT` prints that array (sorted, unique, one line) and exits 2, with a message, if a listed file is missing, has no `name:`, has a name containing `*`, `?`, `[`, `]` or `!`, or is named `CI gate`. Regenerate the list whenever the profile changes. `tests/ci-gate.sh` pins the suite's own caller to the script's output for the suite's profile. The consumers' list must be the profile's names: the template ships a placeholder that matches no workflow and must be replaced. +`workflow_run.workflows` matches workflow *names* (the top-level `name:` of a workflow file), not file paths, while a profile lists workflow *files*. The caller therefore carries an explicit list, with no globs: the `name:` of each distinct workflow file in the profile. `scripts/ci-gate-trigger-names.sh PROFILE.json REPO-ROOT` prints that array (sorted, unique, one line) and exits 2, with a message, if a listed file is missing, has no `name:`, has a name containing `*`, `?`, `[`, `]`, `!` or `+`, or is named `CI gate`. Regenerate the list whenever the profile changes. `tests/ci-gate.sh` pins the suite's own caller to the script's output for the suite's profile. The consumers' list must be the profile's names: the template ships a placeholder that matches no workflow and must be replaced. A glob (`"**"`) was replaced because it started one gate run per completed workflow of the repository (about 22 per push on some repositories), which together with the polling exhausted the installation's API quota. -*Consequence.* A required workflow that is missing from the list never triggers an evaluation. The commit then stays pending until the sweep (every 15 minutes) or a `pull_request` event evaluates it. Safety is unaffected: pending is never success, and a check that never reports fails after `timeout_minutes`. Only promptness is lost, so a stale list shows up as a slow gate, not as a false green. +*Consequence.* A required workflow that is missing from the list never triggers an evaluation. A pending commit may stay pending until the sweep (every 15 minutes) or another event evaluates it. An incomplete list can also leave stale success: after a sweep posts `success`, a re-run of the omitted workflow may fail without triggering reevaluation, leaving that success in place until another event or sweep evaluates the commit. Safety depends on keeping the required-workflow trigger list complete. == Workflow acceptance contract diff --git a/scripts/ci-gate-trigger-names.sh b/scripts/ci-gate-trigger-names.sh index d79e9062..350486ec 100755 --- a/scripts/ci-gate-trigger-names.sh +++ b/scripts/ci-gate-trigger-names.sh @@ -20,7 +20,7 @@ while IFS= read -r wf; do [[ -f $root/$wf ]] || { echo "workflow file missing: $wf" >&2; exit 2; } name=$(yq -r '.name // ""' "$root/$wf") || { echo "cannot parse $wf" >&2; exit 2; } [[ -n $name && $name != null ]] || { echo "workflow has no name: $wf" >&2; exit 2; } - [[ $name != *[\*\?\[\]\!]* ]] || { echo "workflow name contains a glob character (* ? [ ] !): '$name' in $wf" >&2; exit 2; } + [[ $name != *[\*\?\[\]\!+]* ]] || { echo "workflow name contains a glob character (* ? [ ] ! +): '$name' in $wf" >&2; exit 2; } [[ $name != "$GATE_NAME" ]] || { echo "workflow name is the gate's own ('$GATE_NAME'): $wf" >&2; exit 2; } names+=("$name") done < <(sort -u <<<"$files") diff --git a/tests/ci-gate.sh b/tests/ci-gate.sh index 9bbc6e25..33bd3a51 100644 --- a/tests/ci-gate.sh +++ b/tests/ci-gate.sh @@ -1654,7 +1654,7 @@ echo "== the explicit workflow_run list (scripts/ci-gate-trigger-names.sh) ==" NAMES="$ROOT/scripts/ci-gate-trigger-names.sh" wfl() { yq -o=json -I=0 "$ON.workflow_run.workflows" "$1" 2> /dev/null; } # -> the list as JSON (null if absent) list_of() { wfl "$1" | jq -c 'if type == "array" then sort else null end'; } # order-insensitive -globbad() { wfl "$1" | jq -c '[.[] | select(type != "string" or test("[*?\\[\\]!]") or . == "CI gate")] | length'; } # glob or gate name +globbad() { wfl "$1" | jq -c '[.[] | select(type != "string" or test("[*?\\[\\]!+]") or . == "CI gate")] | length'; } # glob or gate name want=$(bash "$NAMES" "$SELFPROFILE" "$ROOT" 2>/dev/null | jq -c 'sort') [ -n "$want" ] && ok "the script prints a list for the suite's profile: $want" || bad "the script printed nothing for the suite's profile" chk "the suite's caller workflow_run.workflows equals the script's output for the suite's profile" "$(list_of "$SELF")" "$want" @@ -1668,6 +1668,8 @@ for f in "$SELF" "$TEMPLATE"; do chk "$n: workflow_run.workflows is a non-empty list" "$(wfl "$f" | jq -c 'type == "array" and length > 0')" true done chk "control: the glob check sees the retired glob in a planted caller" "$(globbad "$FX/bad-glob-caller.yml")" 2 +printf 'on:\n workflow_run:\n workflows: ["Build C+"]\n' > "$WORK/plus-caller.yml" +chk "control: the glob check rejects Build C+ in a planted caller" "$(globbad "$WORK/plus-caller.yml")" 1 chk "the template's list is a placeholder that is not any profile's output (a consumer must replace it)" "$(wfl "$TEMPLATE" | jq -c 'length == 1 and (.[0] | startswith("Replace with"))')" true echo "-- negative cases of the script: each exits 2 --" NR="$WORK/names-root"; mkdir -p "$NR/.github/workflows" @@ -1675,11 +1677,12 @@ printf 'name: Alpha build\non: push\n' > "$NR/.github/workflows/a.yml" printf 'on: push\n' > "$NR/.github/workflows/noname.yml" printf 'name: "Build *"\non: push\n' > "$NR/.github/workflows/glob.yml" printf 'name: "!Alpha"\non: push\n' > "$NR/.github/workflows/bang.yml" +printf 'name: "Build C+"\non: push\n' > "$NR/.github/workflows/plus.yml" printf 'name: CI gate\non: push\n' > "$NR/.github/workflows/gate.yml" np() { printf '{"checks":[%s],"repository":"example/repo","schema_version":2}\n' "$(jq -nr --args '$ARGS.positional | map("{\"job\":\"j\",\"workflow\":\".github/workflows/\(.)\"}") | join(",")' "$@")" > "$WORK/np.json"; } np a.yml a.yml; OUT=$(bash "$NAMES" "$WORK/np.json" "$NR" 2>&1); RC=$? chk "positive control: two jobs of one workflow give one name, exit 0" "$RC/$OUT" '0/["Alpha build"]' -for spec in missing.yml:missing noname.yml:'has no name' glob.yml:'glob character' bang.yml:'glob character' gate.yml:"gate's own"; do +for spec in missing.yml:missing noname.yml:'has no name' glob.yml:'glob character' bang.yml:'glob character' plus.yml:'glob character' gate.yml:"gate's own"; do wf=${spec%%:*}; msg=${spec#*:} np a.yml "$wf"; OUT=$(bash "$NAMES" "$WORK/np.json" "$NR" 2>&1); RC=$? [ "$RC" = 2 ] && [[ $OUT == *"$msg"* ]] && [ "$(grep -c '^\[' <<<"$OUT")" = 0 ] && ok "script: $wf exits 2 with '$msg' and prints no list" || bad "script: $wf gave exit $RC: $OUT"