ci / lint the workflow and the shell (push) Successful in 10s
geo-freshness / the pinned geo database vs the vendor (push) Successful in 5s
ci / the operator page in a real browser (push) Successful in 3m42s
ci / build, test, smoke (push) Failing after 2m6s
ci / build the image and smoke it (push) Successful in 5m7s
The Dockerfile said "why not NativeAOT" on the authority of another repo's
Dockerfile. That claim is now this repo's own, and it is a measurement.
What was built to find out:
* Persistence/Schema/schema.sqlite.sql — the model's DDL, generated by
`dotnet ef dbcontext script`, embedded in the binary and read by
Persistence/EmbeddedSchema.cs. A NativeAOT build cannot ask EF to build a
model at run time, and EnsureCreated and GenerateCreateScript both go through
the design-time model, so the schema step has nowhere to get its SQL from.
OPENWAF_SCHEMA=script is the fourth strategy: same provider-shaped
statements, produced at build time instead of at start-up. The schema-script
CI step regenerates the file and fails the run when the committed copy is not
what the current model produces (5652 bytes today).
* SchemaUpgrader.ModelTables asks the runtime model, per entity type. The
design-time one is refused outright under NativeAOT, and GetRelationalModel()
on the runtime model of a compiled model throws
"The annotation 'Relational:DefaultMappings' cannot be added because an
annotation with the same name already exists on the object EntityType:
CountryRule" — building a compiled model's relational model a second time
collides with itself.
* The persistence layer's queries were rewritten into the shape EF's query
precompiler accepts: captured parameters copied to locals, conditional
IQueryable composition written as literal chains, aggregates that take a
predicate given their own Where. 40 of them were refused before that.
* dotnet-ef and EF Core moved 10.0.0 -> 10.0.12, because 10.0.0's design package
ships no build host and `--precompile-queries` cannot load a project without it.
What the measurement says, from scripts/aot-probe.sh on osx-arm64: the AOT build
compiles (48,797,072-byte native binary, 10 IL warnings, 0 errors), starts, and
creates all 12 tables from the DDL it carries. Then it never serves. EF refuses
every query at run time ("Query wasn't precompiled and dynamic code isn't
supported with NativeAOT"), and the precompiler that would fix that is not
usable on this model: after all 40 refusals were cleared it emitted 14
declarations with dots in the identifier
(`var openWaf.Domain.Security.BlockEntryPrimaryKeyProperties = …`) — 28 CS1002
and CS1003 errors, one per entity materialisation — with or without --nativeaot.
The refusals themselves trace to dotnet/efcore#35887, #38030 and #35494; the fix
landed in the 12.0-preview1 milestone, not in any 10.0.x.
Two things were not kept, and why:
* The atomic alert-queue claim and the claim release were rewritten as raw SQL
to dodge the precompiler's ExecuteUpdate failures. Reverted: with the
statement written as SQL, DateTimeOffset reaches sqlite as a provider
parameter instead of through the property's own mapping, the reclaim
comparison stops matching, and
AlertPushQueueTests.A_delivery_owed_by_a_process_that_stopped_is_owed_by_the_next_one
fails with the row still owed. A correctness risk here buys nothing when the
AOT build is blocked further along anyway.
* --nativeaot on the compiled model: its unsafe accessors do not compile
(CS1503 in BlockEntryEntityType.cs). The plain compiled model is what is
committed.
The compose gate's two escalation-count scenes also stopped being a coin toss.
They slept a fixed 2 s and then counted; on a loaded host the same tree read 3
rows once and 1 the next, and the assertion is about a settled number either
way. They now wait for three equal reads, bounded. The scene count is unchanged
at 368.
Gates at this commit: build 0 warnings / 0 errors, unit 378/378, integration
405/405, schema-script ok, smoke 256/0, compose-smoke 368/0, README counts
match (256, 368), lint clean (actionlint 1.7.12, shellcheck 0.11.0).
Not verified: the AOT image on linux-x64 — the probe ran on osx-arm64, and the
ILC failure mode that ends the attempt is a codegen bug in EF, not a
platform-specific one, but that is an inference rather than a measurement.
256 lines
12 KiB
Bash
Executable File
256 lines
12 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|image|compose-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)"
|
|
if ! dotnet tool restore >/dev/null 2>&1; then
|
|
printf 'the pinned dotnet-ef tool could not be restored: 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 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 ;;
|
|
compose-smoke) compose_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 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
|