ci / lint the workflow and the shell (push) Successful in 8s
ci / build, test, smoke (push) Successful in 1m45s
ci / the operator page in a real browser (push) Successful in 2m12s
ci / the same smoke on an image with no base (push) Successful in 4m20s
ci / build the image and smoke it (push) Successful in 4m20s
a8f440b wrote that the gate's admin writes go through `admin_write`. Measured
against the same file an hour later: of its 60 writes that do not go through
`admin`, 34 did — 25 still answered through the un-retried `code` and one went
straight to `curl`. The other 91 writes and 157 reads went through `admin`, which
carried no part of OPEN-39's rule at all: a read that reached nothing answered
NO_JSON_BODY and the log said nothing about why, because the sentinel names the
missing body, not the missing request. The dead-edge scene asserted the opposite
of the fix — that those dead reads write no line to stderr — so the gate was not
only un-instrumented there, it was guarding the missing instrument.
Call sites, counted on this file with comment lines excluded: 261 `admin` (91
writes, 157 reads, 8 carrying -D/-o/-w), 59 `admin_write`, 139 `code`.
What changed:
* `curl_retry` puts OPEN-39's rule under the body-returning helpers. A transport
failure is retried three times and each retry prints the container it sampled;
an HTTP answer — 400, 403, 500 — is an answer and comes back after one attempt.
`admin` and a new `body`, for the scenes that carry their own token, sit on it.
* the body comes back byte for byte. `$(curl ...)` strips trailing newlines and
the six-parallel-POSTs scene writes six `%{http_code}` lines into one shared
file; a wrapper that re-printed carelessly would have turned that assertion
into "204204204204204204". The exit status rides in on a marker suffix instead
of riding on the output.
* the 25 and the 1 joined `admin_write`.
* the dead-edge assertion asks for the nine diagnosis lines and for the absence
of a traceback instead of for silence. It also carried the bug that hid the gap
for one run: `a | b 2>f` captures only b's stderr, so the first version read
back an empty file while the nine lines went to the terminal.
* the claim is now a gate: the file greps its own source and goes red, printing
the count, if any write answers through the un-retried status helper or goes
straight to curl — and fails closed when it cannot read itself.
Three assertions added, one removed: 375 -> 379.
Measured. compose-smoke 379 passed / 0 failed at load average 12 (21:07,
/tmp/compose-retry2.log); that run is one comment rewrap away from this text, and
the two self-audit greps were re-run against the committed file and answer 0 and 0.
readme-counts agrees against that run's totals (379=379, exit 0). shellcheck 0.11.0
and bash -n clean. The retry was again proved against a stub rather than a caught
flake: unreachable twice then a body -> two diagnosis lines and the body's trailing
newline intact (xxd: 610a 620a); always unreachable -> three lines and an empty
body; a 400 -> none; a body ending in `x` -> returned unchanged.
Not measured green: this text against the scratch image. The shared host has held
load average 26-72 since 21:10 and four runs of this tree went red on it — 375/4
at load 31, 377/2 at load 39, 378/1 at load 48 — with every failure in a scene that
reads a projection right after a write that was answered: the two alert-escalation
scenes, and once "the shipped story names the block, the covering range and the
exemption, oldest first" in a run where both alert scenes were green. No `000` near
any of them, and the same tree at load 10-12 was 379/0. That is OPEN-78, filed
today; the README's Gates section now carries those red numbers instead of a green
one it does not have.
291 lines
14 KiB
Bash
Executable File
291 lines
14 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# One file says what each gate *is*, so "what CI runs" and "what an operator ran
|
|
# before pushing" stop being two different claims. CI calls one gate per step, so
|
|
# the job log still names the gate that failed; `all` runs them in order and
|
|
# stops at the first failure.
|
|
#
|
|
# scripts/ci-gates.sh restore|build|unit|integration|schema-script|smoke
|
|
# scripts/ci-gates.sh image|scratch-image|compose-smoke|scratch-smoke|all
|
|
# scripts/ci-gates.sh console (needs a real Chromium; not part of `all`)
|
|
# scripts/ci-gates.sh readme-counts scripts/<gate> (compares the README's
|
|
# assertion count with what that gate printed
|
|
# in this run; needs GATE_TOTALS_DIR)
|
|
# scripts/ci-gates.sh lint (the workflow and shell lint CI runs. Not in
|
|
# `all` for the console gate's reason: a machine
|
|
# that has neither the pinned tools nor a
|
|
# supported platform exits 2 — "cannot run" —
|
|
# which is a different answer from "clean".)
|
|
#
|
|
# Not here on purpose: scripts/geo-db-freshness.sh. It asks the vendor what the
|
|
# newest geo database is, so it is the one gate that talks to the internet, and
|
|
# putting it behind `all` would make the offline claim below false. It has its own
|
|
# scheduled job (.github/workflows/geo-freshness.yml).
|
|
#
|
|
# OPENWAF_ADMIN_TOKEN defaults below to the same throwaway CI uses; set it to
|
|
# override. Nothing here talks to anything outside the run.
|
|
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
|
|
# The compose gate needs an admin token for the stack it starts. It is not a
|
|
# secret — that stack exists only inside this run and is torn down on exit — but
|
|
# requiring it meant `ci-gates.sh all` stopped at the last gate for anyone who
|
|
# forgot to export one, which made the one-command entry point a lie. Same value
|
|
# CI uses, overridable by the caller.
|
|
export OPENWAF_ADMIN_TOKEN="${OPENWAF_ADMIN_TOKEN:-ci-only-throwaway}"
|
|
|
|
banner() { printf '\n\033[1m=== gate: %s ===\033[0m\n' "$1"; }
|
|
|
|
restore() { banner restore; dotnet restore dotnet/OpenWaf.slnx; }
|
|
|
|
# TreatWarningsAsErrors is set in Directory.Build.props, so this is also the
|
|
# warning gate.
|
|
build() { banner build; dotnet build dotnet/OpenWaf.slnx -c Release --no-restore; }
|
|
|
|
unit() { banner unit; dotnet test dotnet/OpenWaf.Tests.Unit/OpenWaf.Tests.Unit.csproj -c Release --no-build; }
|
|
|
|
integration() { banner integration; dotnet test dotnet/OpenWaf.Tests.Integration/OpenWaf.Tests.Integration.csproj -c Release --no-build; }
|
|
|
|
smoke() { banner smoke; ./scripts/smoke.sh; }
|
|
|
|
# The DDL the shipped binary carries (Persistence/Schema/schema.sqlite.sql) is
|
|
# generated from the EF model, not written by hand. This gate regenerates it and
|
|
# refuses the run when the committed copy is not what the current model produces,
|
|
# which is what keeps "the image creates the schema the model describes" a
|
|
# checked claim. It exists because the NativeAOT build cannot ask EF to build a
|
|
# model at run time at all, so for that build the file *is* the schema step.
|
|
schema_script() {
|
|
banner schema-script
|
|
local committed=dotnet/OpenWaf.Infrastructure/Persistence/Schema/schema.sqlite.sql
|
|
local regenerated
|
|
regenerated="$(mktemp)"
|
|
# --tool-manifest: the manifest lives in dotnet/, and `dotnet tool restore`
|
|
# from the repo root finds no manifest, prints "No tools were restored." and
|
|
# still exits 0 — measured on the runner at 7c5e1ef, where the gate then died
|
|
# on "Run \"dotnet tool restore\" to make the \"dotnet-ef\" command available."
|
|
# A successful restore is therefore checked by asking the tool for its version,
|
|
# not by trusting the restore's exit code.
|
|
if ! dotnet tool restore --tool-manifest dotnet/dotnet-tools.json >/dev/null 2>&1 \
|
|
|| ! (cd dotnet && dotnet ef --version) >/dev/null 2>&1; then
|
|
printf 'the pinned dotnet-ef tool is not available: cannot check the schema script\n' >&2
|
|
return 2
|
|
fi
|
|
# OPENWAF_MIGRATE_PROVIDER=sqlite: the design-time factory defaults to postgres,
|
|
# and a postgres DDL checked against a sqlite file would fail for the wrong
|
|
# reason.
|
|
if ! (cd dotnet && OPENWAF_MIGRATE_PROVIDER=sqlite dotnet ef dbcontext script \
|
|
-c OpenWafDbContext -p OpenWaf.Infrastructure -s OpenWaf.Infrastructure \
|
|
-o "$regenerated" >/dev/null); then
|
|
printf 'dotnet ef dbcontext script could not run: cannot check the schema script\n' >&2
|
|
return 2
|
|
fi
|
|
if cmp -s "$committed" "$regenerated"; then
|
|
printf ' ok the committed schema script is what the current model generates (%s bytes)\n' \
|
|
"$(wc -c < "$committed" | tr -d ' ')"
|
|
else
|
|
printf ' FAIL the committed schema script is not what the current model generates\n' >&2
|
|
diff -u "$committed" "$regenerated" | head -40 >&2
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# The plain build the README shows, plus its size: the compose path would hide a
|
|
# Dockerfile regression that this step catches.
|
|
image() { banner image; docker build -t openwaf:ci .; docker image ls openwaf:ci --format '{{.Repository}}:{{.Tag}} {{.Size}}'; }
|
|
|
|
compose_smoke() { banner compose-smoke; ./scripts/compose-smoke.sh; }
|
|
|
|
# The same program on a base of nothing at all: scratch, plus the shared objects
|
|
# it was linked against, plus the CA bundle. Its size is printed next to the
|
|
# chiseled one's because the difference between the two is the claim being made.
|
|
scratch_image() {
|
|
banner scratch-image
|
|
docker build -f Dockerfile.scratch -t openwaf-scratch:ci .
|
|
# One argument per `docker image ls` — two is a usage error, exit 1. The
|
|
# chiseled line prints nothing in a job that never built it (the scratch job
|
|
# is its own job), which is why it is a separate call rather than a failure.
|
|
docker image ls --format 'scratch {{.Repository}}:{{.Tag}} {{.Size}}' openwaf-scratch:ci
|
|
docker image ls --format 'chiseled {{.Repository}}:{{.Tag}} {{.Size}}' openwaf:ci
|
|
}
|
|
|
|
# The production smoke, unchanged, against the scratch image. COMPOSE_FILE is
|
|
# appended to rather than replaced, so a caller that already names the CI
|
|
# overlay (the workflow does) keeps it and gains only the dockerfile swap.
|
|
scratch_smoke() {
|
|
banner scratch-smoke
|
|
COMPOSE_FILE="${COMPOSE_FILE:-docker-compose.yml}:docker-compose.scratch.yml" ./scripts/compose-smoke.sh
|
|
}
|
|
|
|
# The browser gate over the operator page. It is a gate, so it lives here too and
|
|
# CI calls it by the same name. It is NOT part of `all`: it needs a real
|
|
# Chromium, and a machine without one exits 2 ("cannot run"), which is a
|
|
# different answer from 1 ("the page is wrong") and would otherwise make the
|
|
# one-command entry point unrunnable. Run it explicitly before pushing a change
|
|
# to the console.
|
|
console() { banner console; ./scripts/console-smoke.sh; }
|
|
|
|
# Checksum helper: sha256sum on Linux, shasum on a macOS host, and a refusal to
|
|
# check nothing when neither is present.
|
|
sha256_verify() {
|
|
if command -v sha256sum >/dev/null 2>&1; then
|
|
printf '%s %s\n' "$2" "$1" | sha256sum -c -
|
|
elif command -v shasum >/dev/null 2>&1; then
|
|
printf '%s %s\n' "$2" "$1" | shasum -a 256 -c -
|
|
else
|
|
printf 'no sha256 tool on this host: refusing to download an unverified binary\n' >&2
|
|
return 2
|
|
fi
|
|
}
|
|
|
|
# The lint CI runs. It lives here because until this stage existed the workflow
|
|
# files and the smoke scripts were checked by exactly one caller — a CI job — and
|
|
# `ci-gates.sh all` could be green on a tree CI would refuse (OPEN-44). The
|
|
# versions and checksums are pinned here rather than in the workflow, and the CI
|
|
# job now calls this function, so the two callers cannot drift into linting
|
|
# different versions of the same gate.
|
|
#
|
|
# A tool already on PATH is used as it is, and the version it prints is the
|
|
# version that did the linting — that is the number the README quotes. Otherwise
|
|
# the pinned release is downloaded, which is supported on linux x86_64 and arm64.
|
|
# Anywhere else this says so and exits 2: a lint stage that silently passes on a
|
|
# machine where it never ran is the defect OPEN-44 is about.
|
|
lint() {
|
|
banner lint
|
|
local workdir; workdir=$(mktemp -d)
|
|
if command -v actionlint >/dev/null 2>&1; then
|
|
actionlint --version | head -1
|
|
actionlint -no-color .github/workflows/*.yml
|
|
elif [ "$(uname -s)" = Linux ]; then
|
|
local version=1.7.12
|
|
local sha=8aca8db96f1b94770f1b0d72b6dddcb1ebb8123cb3712530b08cc387b349a3d8
|
|
local arch
|
|
case "$(uname -m)" in
|
|
x86_64) arch=amd64 ;;
|
|
aarch64) arch=arm64 ;;
|
|
*) printf 'actionlint: unsupported architecture %s — cannot run (exit 2), not a pass\n' "$(uname -m)" >&2; return 2 ;;
|
|
esac
|
|
curl -fsSL -o "$workdir/actionlint.tar.gz" \
|
|
"https://github.com/rhysd/actionlint/releases/download/v${version}/actionlint_${version}_linux_${arch}.tar.gz"
|
|
sha256_verify "$workdir/actionlint.tar.gz" "$sha"
|
|
tar xzf "$workdir/actionlint.tar.gz" -C "$workdir" actionlint
|
|
"$workdir/actionlint" --version | head -1
|
|
"$workdir/actionlint" -no-color .github/workflows/*.yml
|
|
else
|
|
printf 'actionlint is not installed and this is not Linux: the lint gate cannot run (exit 2), which is not a pass\n' >&2
|
|
return 2
|
|
fi
|
|
|
|
if command -v shellcheck >/dev/null 2>&1; then
|
|
shellcheck --version | sed -n 's/^version: //p'
|
|
shellcheck -s bash scripts/*.sh
|
|
elif [ "$(uname -s)" = Linux ]; then
|
|
local sv=0.11.0
|
|
local sv_x86_64=8c3be12b05d5c177a04c29e3c78ce89ac86f1595681cab149b65b97c4e227198
|
|
local sv_aarch64=12b331c1d2db6b9eb13cfca64306b1b157a86eb69db83023e261eaa7e7c14588
|
|
local sarch ssha
|
|
case "$(uname -m)" in
|
|
x86_64) sarch=x86_64; ssha=$sv_x86_64 ;;
|
|
aarch64) sarch=aarch64; ssha=$sv_aarch64 ;;
|
|
*) printf 'shellcheck: unsupported architecture %s — cannot run (exit 2), not a pass\n' "$(uname -m)" >&2; return 2 ;;
|
|
esac
|
|
curl -fsSL -o "$workdir/shellcheck.tar.xz" \
|
|
"https://github.com/koalaman/shellcheck/releases/download/v${sv}/shellcheck-v${sv}.linux.${sarch}.tar.xz"
|
|
sha256_verify "$workdir/shellcheck.tar.xz" "$ssha"
|
|
tar xJf "$workdir/shellcheck.tar.xz" -C "$workdir"
|
|
"$workdir/shellcheck-v${sv}/shellcheck" --version | sed -n 's/^version: //p'
|
|
"$workdir/shellcheck-v${sv}/shellcheck" -s bash scripts/*.sh
|
|
else
|
|
printf 'shellcheck is not installed and this is not Linux: the lint gate cannot run (exit 2), which is not a pass\n' >&2
|
|
return 2
|
|
fi
|
|
}
|
|
|
|
# The README names an assertion count per gate. Those numbers were copied by
|
|
# hand out of a log, and they drift: OPEN-46 measured the README claiming
|
|
# scripts/compose-smoke.sh had 229 assertions while that gate was printing 356.
|
|
# A number nobody checks is not a measurement, so this gate compares what the
|
|
# README claims with what the gate recorded in this run. Each gate writes its own
|
|
# total into $GATE_TOTALS_DIR when that variable is set — CI sets it once per
|
|
# job, `all` sets it for a local run. With nothing to compare this gate exits 2
|
|
# ("cannot verify"), because a check that reports a pass because it had no input
|
|
# is the defect this is about.
|
|
readme_counts() {
|
|
local gate="${1:-}"
|
|
banner "readme-counts $gate"
|
|
if [ -z "$gate" ]; then
|
|
printf 'usage: %s readme-counts scripts/<gate>\n' "$0" >&2
|
|
return 2
|
|
fi
|
|
if [ ! -f README.md ]; then
|
|
printf 'no README.md to read: cannot verify (exit 2), not a pass\n' >&2
|
|
return 2
|
|
fi
|
|
local claimed
|
|
claimed=$(awk -v g="$gate" '$1==g && $3=="assertions" { print $2; exit }' README.md)
|
|
if [ -z "$claimed" ]; then
|
|
printf 'README.md names no assertion count for %s: nothing to verify (exit 2)\n' "$gate" >&2
|
|
return 2
|
|
fi
|
|
if [ -z "${GATE_TOTALS_DIR:-}" ]; then
|
|
printf 'GATE_TOTALS_DIR is not set, so %s recorded no total this run: cannot verify (exit 2)\n' "$gate" >&2
|
|
return 2
|
|
fi
|
|
local measured_name
|
|
measured_name=$(printf '%s' "$gate" | tr '/' '_')
|
|
local measured_file="$GATE_TOTALS_DIR/$measured_name.txt"
|
|
if [ ! -f "$measured_file" ]; then
|
|
printf '%s did not record a total in %s: cannot verify (exit 2)\n' "$gate" "$GATE_TOTALS_DIR" >&2
|
|
return 2
|
|
fi
|
|
local measured failed
|
|
read -r _ measured failed < "$measured_file"
|
|
printf 'README claims %s assertions for %s; the gate printed %s (%s failed)\n' \
|
|
"$claimed" "$gate" "$measured" "$failed"
|
|
if [ "$claimed" != "$measured" ]; then
|
|
printf 'the README is stale by %s assertions. Either the gate changed and the README did not, or the README was never measured.\n' \
|
|
"$((measured - claimed))" >&2
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
case "${1:-all}" in
|
|
restore) restore ;;
|
|
build) build ;;
|
|
unit) unit ;;
|
|
integration) integration ;;
|
|
smoke) smoke ;;
|
|
schema-script) schema_script ;;
|
|
image) image ;;
|
|
scratch-image) scratch_image ;;
|
|
compose-smoke) compose_smoke ;;
|
|
scratch-smoke) scratch_smoke ;;
|
|
console) console ;;
|
|
lint) lint ;;
|
|
readme-counts) readme_counts "${2:-}" ;;
|
|
all)
|
|
# Set here rather than requiring the caller: the totals only mean something
|
|
# if the gates that produced them and the check that reads them ran in the
|
|
# same invocation.
|
|
export GATE_TOTALS_DIR="${GATE_TOTALS_DIR:-$(mktemp -d)}"
|
|
restore; build; unit; integration; schema-script; smoke; image; compose_smoke
|
|
# The scratch image and the same 379 assertions against it. It is in `all`
|
|
# because it is the shipped shape, not an experiment: the only difference a
|
|
# caller can see is what is under the program.
|
|
scratch_image; scratch_smoke
|
|
# The two gates `all` actually ran. console is not among them, so its README
|
|
# number is verified by the console job (or by an operator who ran it and
|
|
# then calls readme-counts with the same GATE_TOTALS_DIR).
|
|
readme_counts scripts/smoke.sh
|
|
readme_counts scripts/compose-smoke.sh
|
|
printf '\nall gates passed\n'
|
|
printf 'NOT included above: console (needs a real Chromium; exits 2 without one),\n'
|
|
printf 'and lint (needs actionlint and shellcheck; exits 2 without them).\n'
|
|
printf 'If the console changed, run: %s console\n' "$0"
|
|
printf 'If a workflow or script changed, run: %s lint\n' "$0"
|
|
;;
|
|
*)
|
|
printf 'usage: %s restore|build|unit|integration|schema-script|smoke|image|compose-smoke|console|lint|readme-counts|all\n' "$0" >&2
|
|
exit 2
|
|
;;
|
|
esac
|