diff --git a/.forgejo/workflows/android-ci.yml b/.forgejo/workflows/android-ci.yml index d080d17..b9e8ba7 100644 --- a/.forgejo/workflows/android-ci.yml +++ b/.forgejo/workflows/android-ci.yml @@ -18,22 +18,6 @@ name: android-ci # detection, and a gate that mis-detects hands out a green check for a suite # that never ran. Here the runner's own paths filter decides — same mechanism # ci.yml already uses. -# -# The two triggers differ on purpose, and the asymmetry is the whole point of -# the `src/**` entry below: -# -# pull_request — the client and the SDK binding surface. NOT `src/**`. A -# Rust-only PR does change the bytes in `libonionwire_sdk.so`, but proving -# that costs a ~11 minute full APK build, and 95 of 143 recorded runs -# touched no `android/` file at all. The in-APK checks that actually earn -# their keep (the `target_max_memory` marker gate, the `.so` listing, the -# sha256 round-trip) still run on every merge via the push trigger, so -# nothing reaches a release untested — a Rust PR just finds out at merge -# instead of before it. If a Rust change ever breaks the Android build -# specifically, add its path here rather than re-adding all of `src/**`. -# -# push: [main] — every Rust or Android change, every merge. This is the -# safety net, and it is why the trigger cannot simply mirror the PR one. on: push: branches: [main] @@ -48,7 +32,8 @@ on: pull_request: paths: - "android/**" - - "crates/onionwire-sdk/**" + - "crates/**" + - "src/**" - "Cargo.toml" - "Cargo.lock" - "scripts/build-android-local.sh" @@ -95,30 +80,10 @@ jobs: steps: - name: Checkout uses: https://code.forgejo.org/actions/checkout@v4 - - - name: Skip superseded run - id: staleness - run: | - set -uo pipefail - # Same gate as ci.yml: a newer commit on this branch while this run - # sat in the shared android concurrency queue makes the ~11 minute - # APK build a proof of nothing. `origin` is anonymously readable - # here, and a failed lookup runs the job rather than skipping it. - ref="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME:-}}" - remote="" - if [ -n "$ref" ]; then - remote="$(git ls-remote origin "refs/heads/$ref" 2>/dev/null | cut -f1)" - fi - if [ -n "$remote" ] && [ "$remote" != "$GITHUB_SHA" ]; then - echo "::notice::superseded: refs/heads/$ref is at ${remote:0:12}, this run is ${GITHUB_SHA:0:12} — skipping" - echo "skip=true" >> "$GITHUB_OUTPUT" - else - echo "tip=${remote:-unknown} sha=${GITHUB_SHA} ref=${ref:-none} — running" - echo "skip=false" >> "$GITHUB_OUTPUT" - fi + with: + fetch-depth: 0 - name: Record runner resources - if: steps.staleness.outputs.skip != 'true' run: | set -euo pipefail cd "${GITHUB_WORKSPACE}" @@ -129,7 +94,6 @@ jobs: ls -l /var/run/docker.sock || true - name: Ensure docker CLI - if: steps.staleness.outputs.skip != 'true' run: | set -euo pipefail if ! command -v docker >/dev/null 2>&1; then @@ -145,7 +109,6 @@ jobs: - name: Build APK + AAR (debug-signed) in bookworm container id: build - if: steps.staleness.outputs.skip != 'true' run: | set -euo pipefail cd "${GITHUB_WORKSPACE}" @@ -323,7 +286,6 @@ jobs: ls -l dist/ - name: Verify artifacts - if: steps.staleness.outputs.skip != 'true' run: | set -euo pipefail cd "${GITHUB_WORKSPACE}" diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml index 6cb4f58..438cf03 100644 --- a/.forgejo/workflows/ci.yml +++ b/.forgejo/workflows/ci.yml @@ -7,12 +7,6 @@ name: ci # build (docs, android, scripts, sibling workflows, markdown). No required # status checks on main, so a missing run is not a merge trap. # workflow_dispatch has no path filter — it always runs the suite. -# -# The nightly cargo-fuzz job used to be a third job here. It had its own -# workflow (`.forgejo/workflows/fuzz.yml`, `schedule` only) because a job -# cannot narrow a workflow-level path filter: `fuzz/**` sat in the list -# alongside `src/**` and `crates/**`, so 80 of 84 recorded fuzz runs touched -# nothing in `fuzz/`. on: push: branches: [main] @@ -23,6 +17,8 @@ on: - "Cargo.toml" - "Cargo.lock" - ".forgejo/workflows/ci.yml" + - "fuzz/**" + - "scripts/run-fuzz.sh" pull_request: paths: - "src/**" @@ -31,20 +27,12 @@ on: - "Cargo.toml" - "Cargo.lock" - ".forgejo/workflows/ci.yml" + - "fuzz/**" + - "scripts/run-fuzz.sh" workflow_dispatch: -# One cargo job on the Pi at a time. Overlapping runs share the -# `onionwire-cargo-registry` and `onionwire-target-ci` volumes, and two -# writers to one cargo target dir produce `Permission denied (os error 13)` -# on /target/debug/deps binaries. The per-run container name (below) is no -# longer shared, so the docker Conflict is gone — but the volume race is not, -# and the serialization is what prevents it. -# -# `cancel-in-progress` stays false: cancelling a *queued* run would release -# this group and let the next run start a second cargo job against the same -# volume. Superseded runs are instead skipped by the staleness gate at the -# top of each job, which costs seconds instead of the minutes a full build -# spends proving something nobody will look at. +# One cargo job on the Pi at a time. Overlapping PR+main runs shared the +# container name `onionwire-ci` (docker Conflict) and OOM-killed with 137. concurrency: group: onionwire-ci-pi cancel-in-progress: false @@ -60,6 +48,14 @@ env: # sharing a target dir with the root job would thrash both. SDK_CARGO_TARGET_VOLUME: onionwire-target-ci-sdk SDK_BUILD_CONTAINER: onionwire-ci-sdk-${{ github.run_id }} + # The fuzz job builds on nightly with a release profile + debug=line-tables-only; + # 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 jobs: test: @@ -69,36 +65,7 @@ jobs: - name: Checkout uses: https://code.forgejo.org/actions/checkout@v4 - - name: Skip superseded run - id: staleness - run: | - set -uo pipefail - # A force-push, or a merge of another PR, can put a newer commit on - # this branch while this run sits in the concurrency queue above. - # Testing it then proves nothing about the tree that is actually on - # the branch. 279 of 353 runs in a two-week window were on an - # already-superseded sha — the single largest source of wasted Pi - # time, and `cancel-in-progress: true` cannot fix it without letting - # two cargo jobs share the target volume. - # - # For a pull_request, GITHUB_HEAD_REF is the PR's source branch (the - # ref itself is refs/pull/N/merge); for a push it is empty, so fall - # back to GITHUB_REF_NAME. - ref="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME:-}}" - remote="" - if [ -n "$ref" ]; then - remote="$(git ls-remote origin "refs/heads/$ref" 2>/dev/null | cut -f1)" - fi - if [ -n "$remote" ] && [ "$remote" != "$GITHUB_SHA" ]; then - echo "::notice::superseded: refs/heads/$ref is at ${remote:0:12}, this run is ${GITHUB_SHA:0:12} — skipping" - echo "skip=true" >> "$GITHUB_OUTPUT" - else - echo "tip=${remote:-unknown} sha=${GITHUB_SHA} ref=${ref:-none} — running" - echo "skip=false" >> "$GITHUB_OUTPUT" - fi - - name: cargo test + clippy on aarch64 - if: steps.staleness.outputs.skip != 'true' run: | set -euo pipefail cd "${GITHUB_WORKSPACE}" @@ -144,26 +111,7 @@ jobs: - name: Checkout uses: https://code.forgejo.org/actions/checkout@v4 - - name: Skip superseded run - id: staleness - run: | - set -uo pipefail - # Same gate as the `test` job above — see the comment there. - ref="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME:-}}" - remote="" - if [ -n "$ref" ]; then - remote="$(git ls-remote origin "refs/heads/$ref" 2>/dev/null | cut -f1)" - fi - if [ -n "$remote" ] && [ "$remote" != "$GITHUB_SHA" ]; then - echo "::notice::superseded: refs/heads/$ref is at ${remote:0:12}, this run is ${GITHUB_SHA:0:12} — skipping" - echo "skip=true" >> "$GITHUB_OUTPUT" - else - echo "tip=${remote:-unknown} sha=${GITHUB_SHA} ref=${ref:-none} — running" - echo "skip=false" >> "$GITHUB_OUTPUT" - fi - - name: cargo test + clippy for crates/onionwire-sdk on aarch64 - if: steps.staleness.outputs.skip != 'true' run: | set -euo pipefail cd "${GITHUB_WORKSPACE}" @@ -190,3 +138,58 @@ jobs: --exclude=./crates/onionwire-sdk/target . \ | docker start -a -i "$SDK_BUILD_CONTAINER" docker rm -f "$SDK_BUILD_CONTAINER" > /dev/null + + # 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 in CI ever compiles this crate, so the targets bit-rot silently: this + # job catches it. It only does something useful after PR #103 merges to main. + fuzz: + runs-on: docker + timeout-minutes: 120 + # The cold fuzz build (~12 min locally for the full Arti + SQLCipher + + # vendored-OpenSSL graph) can SERIALIZE other PRs with the same concurrency + # group. Give it its own group so a long fuzz build does not block the test/sdk + # jobs and the PRs that trigger them. + concurrency: + group: onionwire-ci-pi-fuzz + cancel-in-progress: false + 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 + 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=15 \ + -e FUZZ_JOBS=2 \ + -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' + tar czf - --exclude=./target --exclude=./.git --exclude=./.worktrees . \ + | docker start -a -i "$FUZZ_BUILD_CONTAINER" + docker rm -f "$FUZZ_BUILD_CONTAINER" > /dev/null diff --git a/.forgejo/workflows/fuzz.yml b/.forgejo/workflows/fuzz.yml deleted file mode 100644 index e714fcc..0000000 --- a/.forgejo/workflows/fuzz.yml +++ /dev/null @@ -1,96 +0,0 @@ -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 diff --git a/docs/RELEASING.md b/docs/RELEASING.md index d8a09f2..206ff39 100644 --- a/docs/RELEASING.md +++ b/docs/RELEASING.md @@ -119,42 +119,15 @@ long pole of a release — the Linux binaries land first. ### Android CI (not a release) -`android-ci.yml` runs the same gradle targets on the same amd64 runner, so an -android-only PR is no longer merged on an empty check list. It signs with the -**debug** key (`ONIONWIRE_REQUIRE_RELEASE_KEY=false`, no keystore) and -publishes nothing — `apksigner` in that job reports the debug cert, which is -expected there and never in `android-release`. It shares -`android-release.yml`'s concurrency group and volumes, so the PR build is warm -(~9 min) instead of re-downloading a gigabyte of SDK/NDK. - -The two triggers are deliberately **not** the same, because the APK embeds the -root crate as `libonionwire_sdk.so` and a full build costs ~11 minutes: - -- **`pull_request`** — `android/**`, `crates/onionwire-sdk/**`, `Cargo.toml`, - `Cargo.lock`, `scripts/build-android-local.sh`. Client and binding-surface - changes get the pre-merge signal. -- **`push: [main]`** — the above plus `src/**` and `crates/**`. Every merge of - a Rust change still runs the full build, including the in-APK checks that - earn their keep (the `target_max_memory` marker gate, the `.so` listing, the - sha256 round-trip). Nothing reaches a release untested; a Rust-only PR finds - out at merge rather than before it. - -Both `ci.yml` and `android-ci.yml` open with a **staleness gate**: they compare -`GITHUB_SHA` against the remote branch tip and skip the build if a newer commit -landed while the run sat in the concurrency queue. `cancel-in-progress` is -deliberately `false` on both (cancelling a queued run would let two cargo jobs -share the Pi's target volume, which produces `Permission denied (os error 13)` -on `/target/debug/deps`), so the gate is what removes superseded work. A -`git ls-remote` failure runs the job rather than skipping it. - -The `ci / fuzz` job is **not** in `ci.yml` any more — it is -`.forgejo/workflows/fuzz.yml`, `schedule`-only at 03:30 UTC plus -`workflow_dispatch`. A job cannot narrow a workflow-level path filter, so -`fuzz/**` sat beside `src/**` in `ci.yml`'s list and the job ran on nearly -every push (80 of 84 recorded runs touched nothing in `fuzz/`), each paying a -nightly toolchain install and `cargo install cargo-fuzz` for 15 seconds of -fuzzing. Fuzz output is not attached to any PR; check the `fuzz` workflow's -run history for it. +`android-ci.yml` runs the same gradle targets on the same amd64 runner for every +PR and `main` push that touches `android/`, `src/`, `crates/`, `Cargo.toml`, +`Cargo.lock` or `scripts/build-android-local.sh`, so an android-only PR is no +longer merged on an empty check list. It signs with the **debug** key +(`ONIONWIRE_REQUIRE_RELEASE_KEY=false`, no keystore) and publishes nothing — +`apksigner` in that job reports the debug cert, which is expected there and +never in `android-release`. It shares `android-release.yml`'s concurrency group +and volumes, so the PR build is warm (~9 min) instead of re-downloading a +gigabyte of SDK/NDK. ## Rebuilding an existing tag