name: CI
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
release-hygiene:
name: version bump + release notes
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
persist-credentials: false
- name: Shipped changes must bump the version and replace the notes
run: |
set -euo pipefail
base="$(git merge-base "origin/$GITHUB_BASE_REF" HEAD)"
# --no-renames: git collapses a rename to its destination alone, so
# `git mv 0.1.808.md 0.1.809.md` would look like "wrote this
# version's notes" while destroying the previous release's. Split
# into a delete plus an add, the stale guard below sees the delete.
changed="$(git diff --no-renames --name-only "$base" HEAD)"
# What ships in the binary: sources, baked-in assets, the build
# script, and the dependency set. src/app/tests.rs and tests/ are
# compiled out of release builds.
shipped="$(printf '%s\n' "$changed" \
| grep -E '^(src/|assets/|build\.rs$|Cargo\.toml$|Cargo\.lock$)' \
| grep -vE '^(src/app/tests\.rs|tests/)' || true)"
# A `.rs` file whose diff touches nothing outside a
# `#[cfg(test)] mod tests` produces a byte-identical binary, and
# croft keeps most unit tests beside the code they cover, so that
# is the ordinary shape of a test-only fix here (#461). The path
# list above only reaches whole test FILES. Anything the parse is
# unsure about counts as shipped: waiving a bump that was needed
# puts two binaries on one version, which is what this job exists
# to prevent.
# Read the list a line at a time rather than word-splitting it: an
# unquoted `for f in $shipped` also expands globs, so a path
# holding `[`, `*` or `?` would reach the filter as a pathspec git
# cannot resolve, and a path holding a space would arrive as two.
kept="$(mktemp)"
trap 'rm -f "$kept"' EXIT
while IFS= read -r f; do
[ -n "$f" ] || continue
if python3 scripts/ships_nothing.py "$base" HEAD "$f"; then
# The status says "ships nothing"; it does not say why, and the
# script has more than one way to reach it. Claiming the reason
# here asserted "confined to #[cfg(test)]" about files that had
# no test module at all.
echo "$f: ships nothing."
else
printf '%s\n' "$f" >> "$kept"
fi
done <<< "$shipped"
shipped="$(cat "$kept")"
if [ -z "$shipped" ]; then
echo "No shipped files changed; no release required."
exit 0
fi
echo "Shipped files changed:"
printf ' %s\n' "$shipped"
ver() { git show "$1:Cargo.toml" | sed -n 's/^version *= *"\([0-9.]*\)".*/\1/p' | head -n1; }
old="$(ver "$base")"
new="$(ver HEAD)"
fail=0
highest="$(printf '%s\n%s\n' "$old" "$new" | sort -t. -k1,1n -k2,2n -k3,3n | tail -n1)"
if [ "$new" = "$old" ] || [ "$highest" != "$new" ]; then
echo "::error file=Cargo.toml::This PR changes shipped files but the version is still $old. Bump it (base: $old, head: $new) - two binaries must never share a version and differ only in commit hash."
fail=1
fi
# Versions count like an odometer, the same rule as code-graph-rag:
# MINOR and PATCH stay below 1000, and a bump that reaches 1000
# carries into the next component and resets the lower ones, so
# 0.1.999 is followed by 0.2.0 and never by 0.1.1000. A base already
# past the cap carries on its next bump the same way.
if ! python3 scripts/next_version.py --check "$new"; then
next="$(python3 scripts/next_version.py "$old" 2>/dev/null || true)"
echo "::error file=Cargo.toml::Version $new has a component at or above 1000. MINOR and PATCH stay below 1000 and carry into the next component, like an odometer; the next version after $old is ${next:-unknown} (python3 scripts/next_version.py $old)."
fail=1
fi
# One notes file per version (#399): the check is that THIS version's
# file exists and says something, not that a shared file was touched.
# Two PRs adding different versions' notes then never collide.
notes="src/release_notes/$new.md"
# AUTHORSHIP, not merely existence. A file for this version can
# already be on main - left behind by a revert that dropped the
# code but not the notes - and a bump onto it would pass while the
# panel advertised a release the binary does not contain. This PR
# has to have written it.
if ! printf '%s\n' "$changed" | grep -qx "$notes"; then
echo "::error file=$notes::This PR changes shipped files but does not write $notes. Write this version's highlights there, one per line, each prefixed 'feature:' or 'fix:', so the welcome panel describes the binary it is in. A file left on main by an earlier revert does not count."
fail=1
elif ! git cat-file -e "HEAD:$notes" 2>/dev/null; then
echo "::error file=$notes::$notes was changed but does not exist at HEAD. This version's notes cannot be the file the PR deleted."
fail=1
elif [ -z "$(git show "HEAD:$notes" | tr -d '[:space:]')" ]; then
echo "::error file=$notes::$notes is empty. Write this version's highlights there, one per line, each prefixed 'feature:' or 'fix:'."
fail=1
fi
# A shipped release describes itself and nothing else: editing an
# older version's notes rewrites what a binary already out there
# claims to be.
stale="$(printf '%s\n' "$changed" | grep -E '^src/release_notes/[0-9.]+\.md$' | grep -v "^$notes$" || true)"
if [ -n "$stale" ]; then
echo "Notes for other versions were modified:"
printf ' %s\n' $stale
echo "::error::A release's notes describe that release. Only $notes may change in this PR."
fail=1
fi
exit $fail
doc-ownership:
name: doc comments stay with their function
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
persist-credentials: false
- name: No function may lose its doc comment
run: |
set -euo pipefail
base="$(git merge-base "origin/$GITHUB_BASE_REF" HEAD)"
python3 scripts/check_doc_ownership.py "$base" HEAD
- name: No module may lose its reasoning
run: |
set -euo pipefail
base="$(git merge-base "origin/$GITHUB_BASE_REF" HEAD)"
python3 scripts/check_arch_content.py "$base"
- name: binstall metadata must match what release.yml builds
run: python3 scripts/check_binstall_contract.py
test:
name: clippy + tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Install suite runtime dependencies
run: |
set -euo pipefail
# `apt-get update && apt-get install` looked equivalent and was not
# (#549). A command on the LEFT of an `&&` is exempt from `set -e`
# by design, so when `update` failed on a THIRD-PARTY index the
# runner image ships and croft does not need (a Chrome repo hash
# mismatch), the install was skipped, this step still went green,
# and eight PDF tests failed minutes later with "these tests need a
# PDF rasteriser" on a PR that touches no PDF code.
#
# A partial index failure must not decide whether the install runs:
# apt resolves these two packages from the indexes it did fetch.
# A transient mirror hiccup is what set #549 off in the first
# place, and the install below is what actually gates the step, so
# retry before giving up on the index refresh.
for attempt in 1 2 3; do
sudo apt-get update && break
echo "::warning::apt-get update failed (attempt $attempt)"
sleep 5
done
sudo apt-get install -y --no-install-recommends zsh poppler-utils
# Without this the step can only report that it RAN, not that it
# worked, and those are the same colour.
#
# Each tool is probed the way ITS CONSUMER resolves it, which is not
# the same question for the two of them. `pdf::which` walks PATH, so
# `command -v` is right (and stricter: it also wants the executable
# bit). The terminal tests take `/bin/zsh` by literal path and SKIP
# when it is missing, so a zsh present only elsewhere on PATH would
# pass a `command -v` probe and leave those tests silently
# uncovered - the same false green this step exists to remove, moved
# one level up. It holds today only because usrmerge symlinks /bin.
command -v pdftoppm >/dev/null \
|| { echo "::error::pdftoppm is missing after the install step"; exit 1; }
[ -x /bin/zsh ] \
|| { echo "::error::/bin/zsh is missing after the install step"; exit 1; }
for d in /usr/share/zsh /usr/local/share/zsh; do
if [ -d "$d" ]; then sudo chmod -R go-w "$d"; fi
done
- name: Install the pinned toolchain
run: rustup show
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 - name: Formatting (pinned rustfmt, zero diffs)
run: cargo fmt --check
- name: Clippy (zero warnings)
run: cargo clippy --all-targets -- -D warnings
- name: Issue-vetting script tests (stdlib, no venv)
run: python3 -m unittest discover -s scripts/tests -v
- name: Tests
run: cargo test --locked
env:
RUST_TEST_THREADS: 4
- name: fs-sync 200 ms invariant (serial, wall clock)
run: |
set -euo pipefail
cargo test --locked --bin croft fs_sync_reflects -- --ignored --test-threads=1 2>&1 | tee target/fs-sync.log
grep -q '^running 1 test$' target/fs-sync.log \
|| { echo "::error::fs_sync_reflects selected no test: the filter and the test name have drifted"; exit 1; }
cross-musl:
name: ship-path build (${{ matrix.target }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target:
- x86_64-unknown-linux-musl
- aarch64-unknown-linux-musl
steps:
- uses: actions/checkout@v7
- name: Install the pinned toolchain
run: rustup show
- name: Add the target to the PINNED toolchain
run: rustup target add ${{ matrix.target }}
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 with:
key: ${{ matrix.target }}
- name: Install zig and cargo-zigbuild
run: |
python3 -m pip install --break-system-packages ziglang \
|| python3 -m pip install ziglang
python3 -m ziglang version
cargo install cargo-zigbuild --locked
- name: cargo zigbuild --profile remote-fast
run: cargo zigbuild --profile remote-fast --locked --bin croft --target ${{ matrix.target }}
- name: The shipped artifact must exist and be a Linux ELF for its target
run: |
set -euo pipefail
bin="target/${{ matrix.target }}/remote-fast/croft"
test -x "$bin" || { echo "::error::no artifact at $bin"; exit 1; }
file "$bin"
case "${{ matrix.target }}" in
x86_64-unknown-linux-musl) file "$bin" | grep -qE 'ELF 64-bit LSB.*x86-64' ;;
aarch64-unknown-linux-musl) file "$bin" | grep -qE 'ELF 64-bit LSB.*aarch64' ;;
# A `case` with no match exits 0; a new matrix target must add
# its own assertion rather than pass unchecked.
*) echo "::error::no artifact-kind assertion for ${{ matrix.target }}"; exit 1 ;;
esac
android:
name: Android build (aarch64-linux-android)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Install the pinned toolchain
run: rustup show
- name: Add the Android target to the PINNED toolchain
run: rustup target add aarch64-linux-android
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 with:
key: aarch64-linux-android
- name: Install cargo-ndk
run: cargo install cargo-ndk --locked
- name: cargo ndk build
run: |
export ANDROID_NDK_HOME="$ANDROID_NDK_LATEST_HOME"
echo "Using NDK at $ANDROID_NDK_HOME"
test -d "$ANDROID_NDK_HOME"
cargo ndk --target arm64-v8a --platform 24 build --locked --bin croft