onionwire/.forgejo/workflows/fuzz.yml

96 lines
4.3 KiB
YAML
Raw Normal View History

ci: skip superseded runs, move fuzz to nightly, trim the android PR trigger Three sources of wasted Pi time, measured over a two-week window (353 workflow runs, 694 job runs): ~78% of CI wall-clock was spent on work that did not need to happen. 1. Nothing was ever cancelled. Every `concurrency:` block in the repo had `cancel-in-progress: false`, and 279 of 353 runs sat in the queue behind a newer commit on the same branch. The comment justifying it ("shared the container name `onionwire-ci`") was stale — the name has been per-run-id for a while — but the real constraint is the shared cargo target volume, which two concurrent writers corrupt (`Permission denied (os error 13)` on /target/debug/deps). So the flag stays false and superseded runs instead stand down at a new gate: compare GITHUB_SHA against the remote branch tip and skip. Seconds, not minutes, and it cannot release the concurrency group into a volume race. Added to ci.yml (test, sdk) and android-ci.yml (android). Verified against the run history: Forgejo's pull_request GITHUB_SHA is the branch head, never a synthetic merge commit (245/245 recorded PR runs match a refs/pull/*/head tip), so the gate cannot skip a live run. It fails open — an unresolvable ref runs the job. 232 of 477 historical PR runs would have been skipped. 2. `fuzz` ran on almost every push. A job cannot narrow a workflow-level path filter, so `fuzz/**` sat in ci.yml's list beside `src/**` and `crates/**`: 80 of 84 recorded runs touched nothing in fuzz/, each paying a nightly toolchain install and `cargo install cargo-fuzz` for 15 seconds of actual fuzzing. Moved to its own workflow, schedule-only (03:30 UTC, off the arti-watch slot) plus workflow_dispatch. The build/run single-container fix and the PATH export from #106/#107 come along unchanged. 3. android-ci built a full APK for commits that touched no android/ file — 95 of 143 runs, at ~11 minutes each. The PR trigger now covers android/**, crates/onionwire-sdk/**, Cargo.toml, Cargo.lock and the build script. The push-to-main trigger keeps src/** and crates/**, so every merge still runs the in-APK checks that earn their keep (the target_max_memory marker gate, the .so listing, the sha256 round-trip) — a Rust-only PR now finds out at merge instead of before it, and nothing reaches a release untested. Also drops `fetch-depth: 0` from android-ci: nothing in the build reads git history (PUBLISH_TAG comes from the environment). ci.yml's `push: [main]` trigger is unchanged. It re-tests trees a PR already tested identically (73 job runs in the window), but branch protection is empty, so it is not a merge gate — it is the "CI green on main" signal docs/RELEASING.md's readiness gate reads, and a merge commit has a different sha so statuses do not carry over. The staleness gate already removes most of its cost. docs/RELEASING.md describes all of the above; its android-ci path list and its fuzz-job account were both wrong after this change.
2026-09-27 15:34:58 -04:00
name: fuzz
# Nightly cargo-fuzz harness. The `fuzz/` crate (PR #103) is a detached
# workspace with four libFuzzer targets over the untrusted-input parsers —
# RatchetState::from_bytes/decrypt, qr::decode, dispatch::classify, file::decode.
# Nothing else in CI compiles this crate, so the targets bit-rot silently.
#
# This used to be a job in `ci.yml`, which meant it inherited that workflow's
# PR path filter (`src/**`, `crates/**`, `tests/**`, `Cargo.lock`, …) and ran
# on almost every push: 80 of 84 recorded runs touched neither `fuzz/` nor
# `scripts/run-fuzz.sh`. Each one also paid `rustup toolchain install nightly`
# plus `cargo install cargo-fuzz --locked` before it could do 15 seconds of
# fuzzing. Bit-rot is a slow signal; a PR gate is the wrong shape for it.
#
# It is a scheduled job now. `workflow_dispatch` is the manual escape hatch
# (a parser change deserves a longer run than the 15s below — raise FUZZ_SECS
# in the dispatch env for that).
on:
schedule:
# 03:30 UTC nightly. Forgejo cron is UTC; off the hour on purpose so it
# does not pile onto the 06:17 arti-watch slot.
- cron: "30 3 * * *"
workflow_dispatch:
# Never two fuzz runs at once: they hold the shared fuzz registry and target
# volumes, and a second one is a `docker Conflict` plus a cold rebuild.
concurrency:
group: onionwire-ci-pi-fuzz
cancel-in-progress: false
env:
CARGO_TERM_COLOR: never
RUST_IMAGE: rust:1.91-bookworm
# The build needs a release profile + debug=line-tables-only, so it must not
# thrash the test/sdk target volumes and needs its own registry cache.
FUZZ_REGISTRY_VOLUME: onionwire-cargo-registry-fuzz
FUZZ_TARGET_VOLUME: onionwire-target-ci-fuzz
FUZZ_BUILD_CONTAINER: onionwire-ci-fuzz-${{ github.run_id }}
# libFuzzer writes its -fork dir into TMPDIR; point it at the target volume so
# a host tmpfs quota can't OOM-kill the builder.
FUZZ_TMP_DIR: /target/tmp
# Per-build CPU budget. The Pi has 4 cores shared with whatever CI run is
# live, so 2 is what leaves headroom.
FUZZ_SECS: "15"
FUZZ_JOBS: "2"
jobs:
build:
runs-on: docker
timeout-minutes: 120
steps:
- name: Checkout
uses: https://code.forgejo.org/actions/checkout@v4
- name: build + run fuzz targets
run: |
set -euo pipefail
cd "${GITHUB_WORKSPACE}"
echo "workspace: $GITHUB_WORKSPACE"
docker volume create "$FUZZ_REGISTRY_VOLUME" > /dev/null
docker volume create "$FUZZ_TARGET_VOLUME" > /dev/null
docker rm -f "$FUZZ_BUILD_CONTAINER" > /dev/null 2>&1 || true
# Build AND run in ONE container. Splitting them into two
# `docker create` calls gives the second one a fresh image, and the
# cargo-fuzz binary installed in the first is gone with it
# (PR #106 fixed this; PR #106/#107 added the PATH export too).
docker create --name "$FUZZ_BUILD_CONTAINER" -i \
-e CARGO_TARGET_DIR=/target \
-e CARGO_BUILD_JOBS=2 \
-e CARGO_TERM_COLOR=never \
-e TMPDIR=/target/tmp \
-e RUSTUP_HOME=/usr/local/rustup \
-e CARGO_HOME=/usr/local/cargo \
-e FUZZ_SECS="$FUZZ_SECS" \
-e FUZZ_JOBS="$FUZZ_JOBS" \
-v "$FUZZ_REGISTRY_VOLUME":/usr/local/cargo/registry \
-v "$FUZZ_TARGET_VOLUME":/target \
-w /src \
"$RUST_IMAGE" \
sh -euxc 'mkdir -p /src /target/tmp && tar xzf - -C /src && cd /src \
&& apt-get update \
&& apt-get install -y --no-install-recommends pkg-config libssl-dev \
&& rustup toolchain install nightly --profile minimal \
&& rustup default nightly \
&& cargo install cargo-fuzz --locked \
&& export PATH="/usr/local/cargo/bin:$PATH" \
&& cd /src/fuzz \
&& cargo +nightly fuzz build \
&& cargo +nightly fuzz list \
&& bash /src/scripts/run-fuzz.sh'
# A fresh Docker volume has no tmp/ subdirectory, and rustup fails
# with "error creating temp directory: No such file or directory" if
# TMPDIR points into one that does not exist yet.
tar czf - --exclude=./target --exclude=./.git --exclude=./.worktrees . \
| docker start -a -i "$FUZZ_BUILD_CONTAINER"
docker rm -f "$FUZZ_BUILD_CONTAINER" > /dev/null