git clone https://garage44.eu/jeroen/cartopolis.git.. /.forgejo/workflows/ci.yml
name: CI
# Test cartopolis on every pull request, and gate the expensive things on `main`.
# Runs on the self-hosted Forgejo runner (code.garage44.eu) in the prebuilt
# `cartopolis-ci` image, which already carries the Rust toolchain + Bevy build
# deps (clang/lld/wayland/xkbcommon), so no per-run apt/rustup setup.
#
# **No `push` on branches.** This used to be a bare `on: push` plus
# `pull_request`, which meant a branch that had a PR open was compiled *twice
# from the same commit* — once for `refs/heads/<branch>`, once for
# `refs/pull/N/head` — and then a third time as the merge commit on `main`. Three
# full Bevy builds per change on a runner with capacity 3, two of them proving
# something the third already proved. `concurrency` cannot collapse them: a
# branch ref and a PR ref are different strings, so they land in different
# groups by construction. The only fix is not to start them.
#
# The cost is that a branch with no PR gets no CI. That is the intended trade:
# open the PR, which is where a verdict is actually read.
#
# `.claude/` is on the same footing as `docs/`: skills, prompts and settings, no
# compiled byte among them. It was added when the landing path moved into
# .claude/skills/finish-branch (since 2026-10-23 a skill midas installs, with
# the gate in tools/verify-branch) — a change to the script that runs the gate
# should not itself cost a run of the gate.
#
# `paths-ignore` because a Markdown change should not compile Bevy. Eight of the
# forty commits on `main` before 2026-08-16 touched nothing but `docs/` and
# `*.md`, and each of those bought two full runs — the PR lane and the merge —
# to prove that prose did not break a renderer. The filter is a *suffix and
# directory* rule rather than a list of files so a new note needs no edit here,
# and it deliberately does not cover `assets/`, `crates/`, `Cargo.lock` or
# `.forgejo/` — anything that can change a byte of the binary still runs.
#
# **There is no draft gate here, and it is not an oversight.** Skipping CI on a
# draft pull request is the obvious way to stop an agent fleet's half-finished
# branches from taking runner slots, and it was written, tried and removed the
# same afternoon: Forgejo 16.0.1 fires **no Actions run at all** on the
# draft→ready transition. Measured on PR #94 — `ready_for_review` was declared in
# `types`, the title's `WIP:` prefix was removed, the API confirmed `draft:
# false`, and no run row was created. (Forgejo derives a PR's draft state from
# that title prefix, so the transition arrives as an `edited` event or as
# nothing; putting `edited` in `types` would then rebuild the world every time
# somebody fixed a typo in a description, which is worse than what it fixes.)
#
# A gate whose release condition never fires is not a gate, it is a branch that
# silently never gets a verdict. So the per-push lever is Forgejo's own instead,
# and it needs nothing here: the `SKIP_WORKFLOW_STRINGS` markers (`[skip` `ci]`
# and `[ci` `skip]`, on by default) anywhere in the commit message. It is under
# the pusher's control at the moment of pushing, which a draft flag set an hour
# earlier is not, and there is no state to get stuck in.
#
# It works on a pull-request push, which was confirmed the hard way: a commit
# whose *body* mentioned the marker while explaining all this was silently not
# built. The match is a plain substring over the whole message, not a prefix and
# not a line — so a commit that merely talks about skipping CI skips CI. Split
# the brackets when writing about it, as above.
#
# `types` is likewise left at its defaults — `opened`, `synchronize`, `reopened`.
# Naming it at all replaces the whole set, and the one addition worth making
# turned out not to work.
#
# `workflow_dispatch` is the override for all of the above, and it is not
# decoration: the gates below can between them produce a `main` run that compiles
# nothing, which is fine for a verdict and *not* fine for the cache. rust-cache
# entries written on `main` are what every pull request restores, so a merge that
# skips both the suite and the smokes also skips the save — and after a key
# change (a `Cargo.lock` bump, a toolchain bump, a variable added to `env:`)
# every PR then runs cold until some later merge happens to touch the client.
# Dispatching this workflow on `main` runs it whole and re-warms the store.
# **Nightly on `main`, not on every push to it** (2026-10-16). Every commit
# reaches `main` through the finish-branch skill, which runs this file's own commands on a
# midas node first and records the receipt at the hub (`midas verified`); a run
# here on the push proved the same tree again, ~10 minutes on the 3-slot runner
# every landing shares, and the deploys no longer wait on it (`midas deploy`
# asks for the receipt instead). What a nightly run still catches is what a
# landing cannot: a workshop that verified wrongly, and the world moving under an
# unchanged tree (a crate yanked, a toolchain bumped).
on:
schedule:
- cron: '17 3 * * *'
pull_request:
paths-ignore:
- 'docs/**'
- '**/*.md'
- '.claude/**'
workflow_dispatch:
# One run per ref: a new push cancels the run its predecessor is still doing.
#
# The runner has capacity 3 and a full run is 15-25 minutes. Without this, a PR
# pushed three times puts three runs in the queue, two of them testing code
# nobody is waiting on, and a merge to `main` then waits behind all of them. That
# is not hypothetical: it is what starved this repo's first APK publish.
#
# `main` is excluded deliberately — every commit there is a merge someone wants a
# verdict on, and cancelling one to start the next loses the verdict.
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
env:
# CI-tuned compile: no incremental (useless on fresh runners), and
# line-tables-only debuginfo — keeps panic backtraces but cuts LLVM codegen
# work and shrinks target/ a lot (faster cache save/restore).
CARGO_INCREMENTAL: "0"
CARGO_PROFILE_DEV_DEBUG: line-tables-only
CARGO_TERM_COLOR: always
CARGO_NET_RETRY: "3"
# The job count is `$JOBS` below, on each cargo command line, and **not a
# `CARGO_BUILD_JOBS` in this block** — which is where it lived until it was
# moved here, one cold run later.
#
# `Swatinem/rust-cache` hashes every environment variable whose name begins
# with `CARGO`, `CC`, `CFLAGS`, `CXX`, `CMAKE` or `RUST` into its key. A job
# count is not an input to a single compilation and changes not one byte of the
# output, but changing it from 3 to 2 still invalidated the entire store: the
# run that did it restored in **1 second** instead of ~70 and rebuilt Bevy from
# nothing. Worse, the merge that would have re-saved a warm entry under the new
# key touched only `docs/` and `.forgejo/`, so both gates below correctly
# skipped every step that compiles — and the cache would have stayed cold for
# every pull request until some later merge happened to touch the client.
#
# So: anything that is a knob rather than a compilation input belongs on the
# command line. The variables left in this block are all real inputs (they
# change the artifact), and each of them *should* move the key.
#
# Moving it here does not undo the one-time cost, and the run that proved it
# said `No cache found`: *removing* a variable changes the hash exactly as
# adding one does, and `main` — which still carries the old file until this
# merges — keeps writing under the old key. The store realigns on the first
# `main` run that actually compiles under the new one, which is what the
# `workflow_dispatch` trigger above exists to guarantee rather than wait for.
JOBS: "2"
# sccache, reading and writing the bind-mounted host directory above. It is the
# **second** layer, underneath `Swatinem/rust-cache`, and the distinction is
# worth stating because getting it wrong nearly cost this repo its CI cache.
#
# rust-cache is the fast path and it works: measured across two consecutive
# `main` runs, warm restores took the test job from 2058 s to ~320 s. What it
# cannot do is survive a key change, and it has two that bite here. Its cache
# *version* hashes the workspace path, so the `viberfox` → `cartopolis` rename
# invalidated every entry in the store at a stroke (32.8 GB of them, later
# deleted by hand). And caches carry a `writeIsolationKey` of the ref that wrote
# them, so one written by a PR run is invisible to every other branch.
#
# Both of those are exactly the case sccache covers: it is keyed on the compiler
# invocation and its inputs, with no ref scope and no workspace path in the key,
# so a fresh branch — or the whole repo the day after a rename — still gets its
# objects back instead of recompiling Bevy from nothing. The two compose: on a
# rust-cache hit sccache is nearly idle, and on a miss it is the difference
# between a 5-minute run and a 35-minute one.
#
# `CARGO_INCREMENTAL: "0"` above is not merely a CI tuning any more — it is a
# requirement. sccache cannot cache an incremental compilation and silently
# declines to, so leaving incremental on would turn this off without saying so.
#
# The 20 GB ceiling is sccache's own LRU eviction, chosen against the host: the
# disk is 193 GB and was at 87% before this work.
#
# One caveat, written down because it is invisible until it matters: the two
# jobs run in separate containers, so each starts its *own* sccache server
# against the same directory. Entries are content-addressed and written by
# atomic rename, so a build cannot be corrupted by this — but each server keeps
# its own in-memory LRU index, so the two can evict each other's entries and the
# 20 GB ceiling is enforced per-server rather than in total. The failure mode is
# a cache miss and a directory somewhat larger than the cap, neither of which is
# worth a second cache directory and the halved hit rate that would come with it.
RUSTC_WRAPPER: sccache
SCCACHE_DIR: /sccache
SCCACHE_CACHE_SIZE: 20G
jobs:
# The default lane, and on a pull request the *only* lane. Compiles the
# workspace once for the host and runs every suite in it.
#
# There is no separate `cargo check --workspace --all-targets` job any more.
# It ran in parallel with the tests, which sounds free on a capacity-3 runner
# and is not: each job carries its own `rust-cache` key, so the two were two
# independent cold Bevy builds, and `cargo check` only produces metadata — none
# of that work is reusable by the codegen the tests need. What it uniquely
# covered was targets the tests do not build, and this workspace has none: there
# are no benches and no examples, both `[[bin]]`s are compiled as test targets,
# and the one crate with no tests (`cartopolis_android`) is empty off Android and
# checked by the `targets` job below.
test:
name: test cartopolis
runs-on: ubuntu-latest
container:
image: cartopolis-ci:latest
# A host directory, not the Actions cache. `/data/ci-cache` is in the
# runner's `valid_volumes` (mount anything else and the job is refused), and
# the runner is a single self-hosted machine, so a plain bind mount is both
# available and strictly better than an archive that has to be uploaded and
# downloaded: there is no key, so there is nothing to miss.
volumes:
- /data/ci-cache/sccache:/sccache
# The registry, for the half of the problem sccache does not solve: it
# caches *compilation*, so without this every run still re-downloads and
# re-extracts the whole dependency tree from crates.io before it can get a
# cache hit on any of it. `/root/.cargo/registry` is this image's cargo
# home. There are no git dependencies in the workspace (`big_space` is
# vendored as a path dep), so the registry is the whole of it — add
# `/root/.cargo/git` here the day that stops being true.
#
# The `test` job's own copy, and nothing else mounts it: `targets` has
# `cargo-registry-targets`, and each `deploy-*` lane and `release.yml`
# have theirs. `targets`' volume list has the race that cost this one,
# and why a bind mount of `registry/` cannot be shared at all.
- /data/ci-cache/cargo-registry:/root/.cargo/registry
env:
# mold instead of lld, which `.cargo/config.toml` has invited in a comment
# since it was written. Set here rather than there because it is only true
# of this container: mold is baked into `cartopolis-ci:latest`, and a
# workstation that has not installed it would fail to link.
#
# `RUSTFLAGS` *replaces* `[target.x86_64-unknown-linux-gnu].rustflags`
# wholesale rather than adding to it, so `target-cpu=x86-64-v3` has to be
# repeated here or this job would silently drop the SIMD baseline that the
# step below asserts the runner can execute. It does not replace `linker`,
# so clang still drives the link and merely hands off to mold.
#
# Job-scoped, not workflow-scoped: the `targets` job cross-compiles to wasm32
# and aarch64-linux-android, and both of these flags are nonsense there.
RUSTFLAGS: "-C link-arg=-fuse-ld=mold -C target-cpu=x86-64-v3"
steps:
- uses: actions/checkout@v4
with:
# Required, not an optimisation: the font, app icon, star catalog and
# map fixtures are `include_bytes!`-ed, so without the smudge filter
# this job compiles 130-byte LFS pointers into the binary and only
# finds out at runtime. See `.gitattributes`.
lfs: true
# Two, not the default one, so the scope step below can see the commit's
# parents: a merge on `main` has the previous `main` as `HEAD^1` and the
# branch that was merged as `HEAD^2`, and both of those questions are
# about comparing this commit against them. A depth-1 clone cannot even
# name them.
fetch-depth: 2
# The fast path, and it is worth 6× on a warm run: 2058 s cold versus ~320 s
# restored, measured on consecutive `main` runs 302 and 304. It very nearly
# got deleted from this file on the evidence of run 302 alone, which was cold
# for a reason that had nothing to do with the cache — see the env block.
# Never conclude a cache is broken from a single run; compare two.
#
# **Restore everywhere, save only on `main`**, which costs nothing and saves
# about 90 seconds per pull-request job — measured as the gap between a job's
# duration and the sum of its steps, across every green run since 2026-08-05
# (PR `test`: 518 s of job against 429 s of steps). That gap is this action's
# post step writing a 1.2 GB archive, and a PR-written entry carries a
# `writeIsolationKey` of its own ref: no other branch can read it, and the
# workspace crates are pruned out of it before it is written, so even a
# second push to the same PR gets back only the dependencies `main`'s entry
# already had. It was paying tar and zstd for a copy of something it already
# has. The host disk was at 82% while it did it.
- uses: https://github.com/Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref == 'refs/heads/main' }}
# And save it even when the job goes red, which is not the usual
# default for a good reason that does not apply here: normally a failed
# job might have produced junk worth not keeping, but this action caches
# *dependencies* — it prunes the workspace crates out before writing —
# and a dependency graph does not become wrong because a test did.
#
# Nothing in this repo gates a merge, so `main` is allowed to be red;
# tying the cache to green therefore ties it to something this project
# has deliberately decided not to require. The first `main` run under
# the new key proved the cost: 909 s of compiling, every one of the 764
# tests passed, `cargo fmt` failed on code merged earlier that day, and
# the post step logged `Skipping … due to success()`. One formatting
# error, and every pull request afterwards would have run cold.
cache-on-failure: ${{ github.ref == 'refs/heads/main' }}
# ALSA headers and the `aarch64-linux-android` std used to be installed here
# per run and are baked into `cartopolis-ci:latest` now.
#
# `.cargo/config.toml` builds x86_64 at `target-cpu=x86-64-v3` (AVX2+FMA)
# to light up the SIMD already present in tiny-skia and the pixel loops.
# Cross-compiling to it is always fine, but this job *runs* what it builds,
# so a runner older than Haswell would die on an illegal instruction
# somewhere deep in a test. Fail here instead, with a legible reason.
# Two questions worth asking before spending twenty minutes answering them,
# and both are answerable from the commit graph alone — no API call, no
# token, no state carried between runs.
#
# **Has this exact tree already been tested?** A merge commit's `HEAD^2` is
# the branch head the pull-request lane just compiled. When the branch was
# rebased onto current `main` before merging — which this repo's workflow
# requires — the merge is a fast-forward in content and `HEAD^{tree}` is
# *bit-identical* to `HEAD^2^{tree}`. Running the suite again on that is not
# a weaker verdict repeated, it is the same verdict repeated: the same
# sources, the same lockfile, the same compiler. Skipping it takes the merge
# lane's `cargo test` — 255 to 659 seconds, and the single largest step in
# this file — off every ordinary merge.
#
# What is knowingly given up: the PR run may have been red, and this does
# not check. Nothing here gates a merge anyway (`main` is allowed to be red
# and there are no required status checks), so the person merging has
# already read that verdict; what would be new is a green `main` whose
# tests nobody ran, which is why the skip prints the tree and the commit it
# is trusting instead of passing silently.
#
# **Does anything here reach the renderer?** The two scene smokes below cost
# 163-568 s and are the only steps that render. A merge that touches only
# the simulator, the docs or this file cannot change a frame, so it should
# not pay for one. The test is a *deny*-list matched against every changed
# path, so the default for an unrecognised path — `assets/`, `crates/geo/`,
# `Cargo.lock`, anything new — is to run the smokes. Fail safe, not silent.
#
# `tools/` is on the list for the same reason `crates/simulator/` is: it is
# Python, TypeScript and bash — the extractors, the authoring client, the
# deploy script — and not one byte of it is compiled into
# the client. It is deliberately *not* in the `paths-ignore` above: a
# change there should still get a suite, it just cannot change a frame.
- name: What is worth running for this commit
id: scope
# Through the environment rather than interpolated into the script: a ref
# is a branch name, and branch names here are generated by agents.
env:
REF: ${{ github.ref }}
EVENT: ${{ github.event_name }}
run: |
tested=false
render=true
# A hand-started run is a request for the whole thing — see the
# `workflow_dispatch` note at the top of this file. Both answers are
# already the run-everything ones, so this just declines to narrow them.
# So is the nightly run: it answers for the whole of `main` as it stands,
# not for the last commit, so the narrowing below does not apply to it.
if [ "$EVENT" = "workflow_dispatch" ] || [ "$EVENT" = "schedule" ]; then
echo "Dispatched by hand or nightly: running every step, gates not consulted."
echo "tested=$tested" >> "$GITHUB_OUTPUT"
echo "render=$render" >> "$GITHUB_OUTPUT"
exit 0
fi
# `main` only. On a pull-request ref `HEAD^2` is either absent or the
# `main` that was merged *into* the branch, and neither answers the
# question this is asking.
if [ "$REF" = "refs/heads/main" ] &&
[ "$(git rev-parse HEAD^{tree})" = "$(git rev-parse -q --verify HEAD^2^{tree} 2>/dev/null)" ]; then
tested=true
echo "This tree ($(git rev-parse --short HEAD^{tree})) was already compiled and tested"
echo "on the pull-request lane at $(git rev-parse --short HEAD^2). Skipping the suite."
fi
if changed=$(git diff --name-only HEAD^1 HEAD 2>/dev/null) && [ -n "$changed" ]; then
if ! printf '%s\n' "$changed" | grep -qvE '^(docs/|crates/simulator/|tools/|\.forgejo/|\.claude/|[^/]*\.md$)'; then
render=false
echo "Nothing that reaches the renderer changed. Skipping the scene smokes:"
printf '%s\n' "$changed" | sed 's/^/ /'
fi
fi
echo "tested=$tested" >> "$GITHUB_OUTPUT"
echo "render=$render" >> "$GITHUB_OUTPUT"
- name: Runner supports the x86-64-v3 baseline
run: |
grep -qw avx2 /proc/cpuinfo && grep -qw fma /proc/cpuinfo || {
echo "::error::Runner CPU lacks AVX2/FMA, but .cargo/config.toml builds for x86-64-v3."
echo "Either move the runner to newer hardware or drop the target-cpu flag."
exit 1
}
# **One invocation, not five**, and that is worth about a third of this job.
#
# These used to be five `cargo test -p …` steps, ordered cheapest-first so a
# geodata regression failed in seconds rather than after the client's full
# codegen. The ordering was real but the price was not visible until the steps
# were timed: with resolver v2 each invocation unifies features over only the
# packages *it* selects, so five invocations meant five different feature sets
# for the shared Bevy dependencies and five rebuilds of them. `big_space` — a
# small vendored crate, run immediately after a step that had just compiled
# the entire Bevy stack — took 439 seconds. That is not its own code.
#
# What one invocation costs is the fail-fast ordering: a `cartopolis_geo`
# break now surfaces after the whole workspace compiles. Accepted knowingly.
#
# `--workspace` rather than the old package list, having checked what that
# changes: `cartopolis_geo` and `cartopolis_simulator` carry `tests/`
# directories that a `--lib` would have dropped, and `big_space`'s only doc
# fences are ```ignore, so the `--lib` it used to be given was conservatism
# rather than a needed exclusion. `cartopolis_android` is excluded because it
# is empty off Android — the `targets` job below is what covers it.
#
# The suites, for the record, since the step names no longer list them:
# `cartopolis_geo` (the geodata regressions), `cartopolis_core` and
# `cartopolis_simulator` (the wire and the server — neither was run here until
# 2026-08-10, which is how `message_kind_wire_is_a_bijection` sat red after six
# message kinds were added), `cartopolis`, and `big_space`, whose
# floating-origin correctness tests are the reason a change there can be
# trusted at all.
#
# `--locked` on every cargo invocation in this repo's workflows, because
# `Cargo.lock` being committed is only half of a policy. Without it, a
# `Cargo.toml` edit that arrives without its lockfile update does not fail —
# cargo quietly re-resolves to whatever is newest that afternoon, builds
# *that*, and discards the result, so the artifact does not match the
# lockfile and nothing anywhere says so. With it, the same situation is a
# one-line error naming the crate, and picking up a new version stays what it
# should be: a deliberate `cargo update` in a commit someone reviewed.
#
# Skipped when the scope step above found this tree already tested on the
# branch it came from — see the reasoning there.
- if: steps.scope.outputs.tested != 'true'
run: cargo test --locked -j "$JOBS" --workspace --exclude cartopolis_android
# The only check anywhere that renders anything. Everything above proves the
# code compiles and its units behave; this one launches the app, streams a
# world and asserts the frame had a planet in it — the class of failure that
# type-checks perfectly and ships a black screen.
#
# **`main` only, and it is the one true *build* in this file**: `cargo run`
# links the client binary and then spends up to 15 minutes rendering on a CPU
# rasteriser. A step in this job rather than a job of its own, deliberately —
# it reuses the dependency graph the tests above just compiled, where a
# separate job means a second cold Bevy build against its own cache.
#
# Four constraints, all measured in docs/notes/headless-shots-software-renderer.md:
# * Orbit only. The image has no GPU — Mesa lavapipe is baked into
# `cartopolis-ci:latest` and `WGPU_BACKEND=vulkan` with it — and a 400 m
# ground view never settles on a CPU rasteriser (~5 min). Orbit settles
# in 6.7 s at 250 ms/frame. Ground level is triage, not a gate: raising
# `--wait` does not fix it, it just fails slower.
# * Geometry, placement, culling and visibility are the same picture on
# llvmpipe as on a GPU. **Colour, exposure, bloom and lighting are not**,
# so nothing here may assert on them; that tuning belongs on a
# workstation. `software_renderer` is in the dump so a capture says which
# it was.
# * `--wait` counts *virtual* seconds, clamped at 0.25 s/frame, so on a
# slow renderer it runs several times longer than it reads. 60 is the
# ceiling, not the plan — a settled shot leaves immediately.
# * The tile source is pinned. A scripted run gets no server handshake and
# the built-in fallback is the public raster basemap; the globe should be
# imaged off our own mirror, not a third party's.
# `draws` is a *workload* ceiling, and it is the one performance number this
# job may honestly assert. A draw count is a property of what the client
# selected — culling, LOD and visibility run the same code on the runner's
# software rasteriser as on a phone — where a frame time here is a property
# of a shared 8-core VPS. `docs/notes/render-performance-survey.md` has the
# full table of what is and is not gateable.
#
# 200 against a measured 123 (2026-08-16), which is far looser than the ~2%
# the allocation budgets use, and deliberately: those are bit-identical run
# to run, while this one moves with which globe tiles have arrived by the
# settle verdict. It is sized to catch a regression of the kind that matters
# — something switching the clipmap occlusion culling off, or a tier losing
# its radius bias — not to pin the exact number.
- name: Headless scene smoke (orbit)
if: github.ref == 'refs/heads/main' && steps.scope.outputs.render == 'true'
timeout-minutes: 15
env:
CARTO_TILE_URL: https://tiles.cartopolis.org/tiles/osm/{z}/{x}/{y}
run: |
cargo run --locked -j "$JOBS" -p cartopolis -- \
--shot /tmp/orbit.png --dump-state /tmp/orbit.json \
--at 53.2194,6.5665,180000 --look=-90,0 \
--size 640x360 --settle 2 --wait 60 \
--expect 'settled==true' --expect 'globe_rendered>0' \
--expect 'draws<=200' --expect 'upload_peak_asset_kb<=8192' || {
echo "::error::scene smoke failed — the metrics behind it:"
cat /tmp/orbit.json 2>/dev/null || echo "(no dump: the run died before it captured)"
exit 1
}
# The same frame on the tier Android actually runs, because the one above
# cannot see the phone's scene at all.
#
# `CARTO_QUALITY=phone` is not a performance variation of the run above — it
# takes a different sky (`quality::Budget::sky_dome`), and a different sky
# means `setup_camera` inserts no `AtmosphereSettings` on the camera. That
# single absent component is what silently deleted the planet: the sole
# writer of the globe surface's visibility asked for it by value in its
# camera query, matched nothing, and returned before setting a single
# `Visibility`. The globe streamed all 228 of its tiles and drew none of
# them, leaving the handset a grey ground disc with a cloud shell floating
# over it — while this job, one tier up, kept passing `globe_rendered>0`.
#
# So the assertion is deliberately identical to the one above. What is being
# gated is not a new property of the scene; it is that the property already
# gated still holds on the tier where nobody is watching. Any future "the
# phone doesn't need this component" gate has to survive it.
#
# No `draws` ceiling here: the phone tier's radius bias and halved per-frame
# budgets make its draw count a different number with a different meaning,
# and one loose bound per job is enough.
- name: Headless scene smoke (orbit, phone tier)
if: github.ref == 'refs/heads/main' && steps.scope.outputs.render == 'true'
timeout-minutes: 15
env:
CARTO_TILE_URL: https://tiles.cartopolis.org/tiles/osm/{z}/{x}/{y}
CARTO_QUALITY: phone
run: |
cargo run --locked -j "$JOBS" -p cartopolis -- \
--shot /tmp/orbit_phone.png --dump-state /tmp/orbit_phone.json \
--at 53.2194,6.5665,180000 --look=-90,0 \
--size 640x360 --settle 2 --wait 60 \
--expect 'settled==true' --expect 'globe_rendered>0' \
--expect 'upload_peak_asset_kb<=8192' || {
echo "::error::phone-tier scene smoke failed — the metrics behind it:"
cat /tmp/orbit_phone.json 2>/dev/null || echo "(no dump: the run died before it captured)"
exit 1
}
# Formatting is a convention (d5c301d) and needs a gate or it decays back
# into per-change churn. `crates/big_space` is excluded on purpose — it is a
# vendored fork kept diff-comparable with upstream.
#
# **Last, not first.** It used to be step one, on the reasoning that it is
# cheap and needs no compilation. The cost of that ordering was two months of
# Android releases: a step failing ends the job, so an unformatted merge
# meant every lane below it never ran at all — and one of those was the only
# thing that compiles the APK configuration. It had a real compile error
# sitting behind the formatting one, `deploy-android.yml` fell over on it
# every single push, and the fast red X read as "someone forgot rustfmt".
# Whatever gates last cannot hide anything.
- run: cargo fmt -p cartopolis -p cartopolis_geo -p cartopolis_core -p cartopolis_simulator -p cartopolis_android --check
# What the cache actually did, in the job that used it. Without this the only
# way to know whether sccache is working is to compare wall-clock against a
# run from another day — which is how `Swatinem/rust-cache` sat here for
# weeks saving a gigabyte a run and restoring nothing. A hit rate is one line
# and it is never ambiguous.
#
# `if: always()` so a failing build still reports it: a run that fails slowly
# is exactly when you want to know the cache was cold.
- name: sccache stats
if: always()
# **A diagnostic may not fail a deploy.** On 2026-09-05 this exact
# command ended a web publish: the wasm build had finished and trunk had
# written the distribution, and `--show-stats` then answered "Failed to
# read response header … Mismatch of client/server versions?" and exited
# 2 — so the threading check, the pre-compression and the publish never
# ran, and a good artifact was thrown away over the answer to "how did
# the cache do?".
#
# Why the server stopped answering is **not established**. It is not a
# stale server shared between lanes: each container has its own network
# namespace, so each has its own. What is established is that every
# compile had already succeeded, so whatever happened to the server
# happened after the work. Print the stats, say so when they cannot be
# printed, and let the checks that actually inspect the artifact decide.
run: sccache --show-stats || echo "sccache could not report its stats — the build above is unaffected"
# The cross-target rot gates: two more full dependency graphs, for two platforms
# this runner cannot execute.
#
# **`main` only, which is a deliberate weakening.** Both lanes exist because a
# `cfg(target_arch = "wasm32")` or `cfg(target_os = "android")` block is
# invisible to every host-target lane in this file, and both were added after
# exactly that went wrong: `platform::location` shipped wasm code that had never
# once compiled, and the Android crate's target-gated dependencies make it
# *empty* in a host `cargo check --workspace`.
#
# Running them per-PR would have been the stronger gate. It is not worth its
# price here: each is a cold compile of the whole Bevy stack for a third and
# fourth target, on a capacity-3 runner shared with everything else, and
# **nothing in this repo gates a merge on CI anyway** — `main` is allowed to be
# red, so a PR lane informs the person merging rather than stopping them. On
# `main` the same rot is caught within one merge instead of the two months it
# took last time, and that is the property that actually mattered.
#
# If a change is knowingly platform-shaped, run the lane locally before merging;
# `docs/notes/container-android-toolchain.md` has the two environment variables.
targets:
name: wasm & android targets
# **After `test`, not beside it**, and that ordering is about the queue rather
# than about this job. A `main` run used to hold both of a capacity-3 runner's
# slots for its whole length, so an agent's pull request behind it waited for
# the longer of the two (one targets job queued 967 s on 2026-08-16). Nobody
# waits on a `main` verdict — it is read after the fact — while somebody is
# always waiting on a PR, so serialising the lane nobody watches to keep a
# slot free for the lane somebody does is the trade worth making. It costs
# `main` its own wall clock and nothing else.
#
# `always()` because a red test run is exactly when this must still report:
# these two lanes exist to catch platform rot, and gating them behind the
# host suite would hide an Android break behind an unrelated test failure —
# the same mistake the `cargo fmt` step at the end of `test` documents.
needs: test
if: always() && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
container:
image: cartopolis-ci:latest
# A host directory, not the Actions cache. `/data/ci-cache` is in the
# runner's `valid_volumes` (mount anything else and the job is refused), and
# the runner is a single self-hosted machine, so a plain bind mount is both
# available and strictly better than an archive that has to be uploaded and
# downloaded: there is no key, so there is nothing to miss.
volumes:
- /data/ci-cache/sccache:/sccache
# The registry, for the half of the problem sccache does not solve: it
# caches *compilation*, so without this every run still re-downloads and
# re-extracts the whole dependency tree from crates.io before it can get a
# cache hit on any of it. `/root/.cargo/registry` is this image's cargo
# home. There are no git dependencies in the workspace (`big_space` is
# vendored as a path dep), so the registry is the whole of it — add
# `/root/.cargo/git` here the day that stops being true.
#
# **Its own copy, not the `test` job's**, and this is the one line in this
# file that was actively wrong. It used to mount the same
# `/data/ci-cache/cargo-registry` that `test` does, under a comment
# asserting that was "safe to share between the two concurrent jobs:
# cargo takes a file lock on the registry and the loser waits".
#
# It does not. Cargo's lock is `$CARGO_HOME/.package-cache` — a file
# directly under the cargo home, which is `/root/.cargo`. The mount is
# `/root/.cargo/registry`, one level *below* it. So the bind mount shared
# exactly the data that needs protecting and excluded the lock that
# protects it: each container took its own private `.package-cache` and
# neither could see the other's, leaving two concurrent jobs writing one
# registry with nothing serialising them.
#
# The damage is a half-extracted crate, and it does not look like a cache
# problem — it looks like your code, or like a broken dependency. Three
# signatures seen on `main` on 2026-08-13, all from this one cause:
#
# error: failed to unpack package `libc v0.2.178`
# failed to open …/libc-0.2.178/.cargo-ok: File exists (os error 17)
# error[E0583]: file not found for module `float` (in glam's own source)
# error: could not compile `uuid`
# could not execute process `sccache …` (never executed)
#
# `.cargo-ok` is written *last*, so an interrupted extract leaves a
# directory cargo can neither use nor replace, and a reader mid-extract
# sees a crate whose source is genuinely incomplete. It is intermittent by
# nature — it needs a crate that is not yet extracted, so it bites hardest
# right after a lockfile change, which is exactly when you are least
# inclined to suspect the cache.
#
# Two copies rather than one shared cargo home because the home cannot be
# shared: `/root/.cargo/bin` holds cargo and rustc themselves in this
# image, so mounting over it would hide the toolchain. The cost is ~310 MB
# of disk and a registry that warms twice; the two are independent, so
# they cannot race whatever order the runner starts them in.
#
# This paragraph used to end "not fixed, and worth knowing: the three
# `deploy-*.yml` lanes still mount the `test` job's registry … they are
# rare and manual, and four registries to keep warm is a worse trade
# than an occasional re-run". That trade was wrong, and it was called on
# 2026-08-21: `deploy-wasm`, `deploy-sim` and `deploy-android` were
# dispatched within twenty seconds of each other after a merge, all three
# mounted this job's registry, and the web deploy died on a
# half-extracted `toml_datetime 0.7.3` — the exact signature above. A
# deploy that needs a re-run to succeed is not "an occasional re-run",
# because nothing about the error says to re-run it. Every lane has its
# own copy now (`-web`, `-sim`, `-android`, `-release`), each also listed
# in the runner's `valid_volumes`. Cost: ~310 MB apiece and a registry
# that warms per lane, which `Swatinem/rust-cache` mostly pays anyway.
#
# A lock shared across lanes was considered instead — one registry, plus
# a bind-mounted `$CARGO_HOME/.package-cache` so the containers really
# do serialise — and rejected, because cargo is not the only writer:
# `rust-cache` extracts a ~570 MB archive over `/root/.cargo/registry`
# and prunes `registry/src` in its post step, and neither step takes
# cargo's lock. Isolation covers both writers; a shared lock covers one.
- /data/ci-cache/cargo-registry-targets:/root/.cargo/registry
steps:
- uses: actions/checkout@v4
with:
lfs: true
# `save-if` for the reason the `test` job's copy states at length: an entry
# written by a pull-request run is readable only from the ref that wrote it.
# This job is `main`-only today, so the guard changes nothing here — it is
# here so that the day someone runs this lane on a PR, it does not quietly
# start paying 90 seconds a run for an archive nobody can read.
- uses: https://github.com/Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref == 'refs/heads/main' }}
# No ALSA step here any more, and neither `rustup target add` is needed: the
# image carries wasm32 for the nightly toolchain and aarch64-linux-android
# for the default one, which is the toolchain each of the two lanes below
# actually uses.
#
# Deliberately a *check*: no `-Z build-std`, no atomics, no LTO, no link
# step, no wasm-bindgen. That skips the expensive half of the web build and
# still catches what actually rots — missing web-sys features, `!Send` types
# reaching a `Resource`, wasm-only paths referring to renamed items.
# `--cfg=web_sys_unstable_apis` is inherited from `.cargo/config.toml` here
# precisely because this does NOT set RUSTFLAGS.
# `--no-default-features --features audio,ui-dom` matches the web build
# exactly — see `crates/cartopolis/index.html`, which spells the same
# pair as `data-cargo-no-default-features` + `data-cargo-features`
# (`ui-dom`: the component library's screens as DOM, 2026-11-24). It
# stays spelled out so the lane and the real build cannot drift apart
# silently.
#
# Nightly is not optional and is *not* about `-Z build-std`, which this lane
# does not use: `wasm_thread` opens `feature(stdarch_wasm_atomic_wait)` under
# `cfg_attr(target_arch = "wasm32")`, so on stable this dies with E0554 in a
# dependency before reaching our code, and no flag disables it.
# `RUSTFLAGS` is not a detail here, it is *which web build this checks*.
#
# Without it, cargo falls back to `.cargo/config.toml`'s per-target entry
# (`+simd128` and the web-sys cfg, no threads) — and `deploy-wasm.yml` sets
# `RUSTFLAGS` explicitly, which **replaces** that entry rather than adding
# to it, with `+atomics,+bulk-memory,+mutable-globals`. So the two differed
# in the one dimension that changes which code exists: threads. This lane
# was compiling a single-threaded wasm nobody ships, and passing on it.
#
# That is not hypothetical. `platform::watchdog` landed with three
# native-only items that are live under threads and dead without them, so
# `-D unused` failed *here* while the shipped build was fine — a red gate
# accusing the wrong build, which is how a real failure gets fixed by
# silencing it. Matching the deploy is the fix in both directions: what
# this rejects is now something that would really break the site, and what
# it accepts is something that was really built.
#
# This is deliberately *not* full parity with the deploy, and the gap is
# the cheap half. `CARGO_UNSTABLE_BUILD_STD` and the eight `link-arg`s
# there are about linking a shared-memory module — and a `check` does not
# link, so they would buy this lane nothing but a from-source std build.
# What is copied is exactly the part that decides *which of our code
# exists*: `target-feature` reaches our crates as cfg, and that is the
# dimension the two lanes disagreed on.
#
# Keep these two in step. They are two copies of one configuration, and the
# only thing holding them together is this comment.
- name: Check the web target compiles
env:
RUSTUP_TOOLCHAIN: nightly
RUSTFLAGS: >-
--cfg=web_sys_unstable_apis
-C target-feature=+atomics,+bulk-memory,+mutable-globals,+simd128
run: |
rustup target add wasm32-unknown-unknown
cargo check --locked -j "$JOBS" -p cartopolis --no-default-features --features audio,ui-dom \
--target wasm32-unknown-unknown
# A check, not the APK: no link, no aapt2, no signing. That is the cheap half
# and it catches what rots — a renamed item behind an android cfg, a
# dependency that grows a backend Android does not have (`arboard` was
# exactly that), a Bevy bump that moves `bevy::android::ANDROID_APP`.
# `crates/cartopolis_android/build-apk.sh` is the other half, run by
# `deploy-android.yml` on demand — see docs/notes/android-build.md.
#
# Unlike wasm, this one cannot be a bare `rustup target add`: `blake3` (under
# `bevy_asset`) compiles `blake3_neon.c` for every little-endian aarch64
# target, and a build script's `cc` invocation runs at *check* time. So the
# lane needs a cross C compiler, and on Android that means the NDK — the
# blake3 `no_neon` feature would avoid it, but turning off SIMD in the
# shipped app to make CI cheaper is the trade `src/simd_baseline.rs` exists
# to prevent.
#
# Downloaded and cached here rather than baked into `cartopolis-ci:latest`
# because the image is a separate repo and this gate should not wait on it.
# Moving it into the image is the better end state: it would turn a ~660 MB
# cache restore into nothing at all, and this lane would become one `cargo
# check` pointed at `$ANDROID_NDK_HOME`.
#
# Per the "a step may only use a tool the image already has" rule in
# docs/guides/development.md: the two this relies on are `curl` and `unzip`,
# both present. It deliberately does *not* need a JDK, which the image has no
# reason to carry.
- name: Cache the Android NDK
id: ndk-cache
uses: https://github.com/actions/cache@v4
with:
path: /opt/android-ndk
key: android-ndk-r27c
- name: Fetch the Android NDK
if: steps.ndk-cache.outputs.cache-hit != 'true'
run: |
curl -fsSL -o /tmp/ndk.zip \
https://dl.google.com/android/repository/android-ndk-r27c-linux.zip
unzip -q /tmp/ndk.zip -d /tmp/ndk
mv /tmp/ndk/android-ndk-r27c /opt/android-ndk
rm -rf /tmp/ndk.zip /tmp/ndk
# Setting CC/AR by hand rather than installing cargo-ndk: a `cargo check` does
# not link, so the linker cargo-ndk would configure is never invoked, and
# these two variables are the entire difference. Saves compiling a cargo
# subcommand on every cold cache.
#
# `28` in the compiler name is the API level, and it must match the
# `minSdkVersion` in `crates/cartopolis_android/AndroidManifest.xml` — the NDK
# encodes the level into the `.so`'s symbol requirements, so a mismatch is a
# dynamic-linker failure at launch on the oldest device the manifest claims
# to support.
- name: Check the Android target compiles
env:
NDK_BIN: /opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin
run: |
rustup target add aarch64-linux-android
export CC_aarch64_linux_android="$NDK_BIN/aarch64-linux-android28-clang"
export AR_aarch64_linux_android="$NDK_BIN/llvm-ar"
cargo check --locked -j "$JOBS" -p cartopolis_android --target aarch64-linux-android
# What the cache actually did, in the job that used it. Without this the only
# way to know whether sccache is working is to compare wall-clock against a
# run from another day — which is how `Swatinem/rust-cache` sat here for
# weeks saving a gigabyte a run and restoring nothing. A hit rate is one line
# and it is never ambiguous.
#
# `if: always()` so a failing build still reports it: a run that fails slowly
# is exactly when you want to know the cache was cold.
- name: sccache stats
if: always()
# **A diagnostic may not fail a deploy.** On 2026-09-05 this exact
# command ended a web publish: the wasm build had finished and trunk had
# written the distribution, and `--show-stats` then answered "Failed to
# read response header … Mismatch of client/server versions?" and exited
# 2 — so the threading check, the pre-compression and the publish never
# ran, and a good artifact was thrown away over the answer to "how did
# the cache do?".
#
# Why the server stopped answering is **not established**. It is not a
# stale server shared between lanes: each container has its own network
# namespace, so each has its own. What is established is that every
# compile had already succeeded, so whatever happened to the server
# happened after the work. Print the stats, say so when they cannot be
# printed, and let the checks that actually inspect the artifact decide.
run: sccache --show-stats || echo "sccache could not report its stats — the build above is unaffected"