onionwire/.forgejo/workflows/android-ci.yml

343 lines
18 KiB
YAML
Raw Normal View History

name: android-ci
# Android changes had no CI at all: ci.yml's path allowlist (src/**, crates/**,
# tests/**, Cargo.toml, Cargo.lock, ci.yml) never matches android/**, and
# android-release.yml is dispatch/tag-driven — so an android-only PR ran zero
# jobs and merged on an empty check list. This is the android side of CI.
#
# It builds the same gradle targets the release builds through the same script
# android-release.yml calls (scripts/build-android-local.sh): `:sdk:assembleRelease`
# + `:app:assembleRelease`, Rust for aarch64-linux-android via cargo-ndk, UniFFI
# bindings, APK packaging with the .so. The only difference from a release is
# signing: ONIONWIRE_REQUIRE_RELEASE_KEY=false and no release keystore, so
# Gradle falls back to the debug key. Nothing here is signed for release,
# nothing is published, no tag is touched.
#
# Why a separate workflow instead of android/** added to ci.yml: the only way
# to keep the Rust jobs from running on android-only diffs is job-level change
# 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.
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
#
# 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]
paths:
- "android/**"
- "crates/**"
- "src/**"
- "Cargo.toml"
- "Cargo.lock"
- "scripts/build-android-local.sh"
- ".forgejo/workflows/android-ci.yml"
pull_request:
paths:
- "android/**"
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
- "crates/onionwire-sdk/**"
- "Cargo.toml"
- "Cargo.lock"
- "scripts/build-android-local.sh"
- ".forgejo/workflows/android-ci.yml"
workflow_dispatch:
# Deliberately the SAME group and the SAME volumes as android-release.yml: the
# APK build is ~9 min with warm volumes (SDK/NDK, cargo registry, cargo target,
# Gradle cache) and a cold copy of those is over a gigabyte of downloads per
# runner. Serializing the two workflows by group name is what keeps them off
# each other's volumes.
concurrency:
group: onionwire-android-release-v2
cancel-in-progress: false
env:
CARGO_TERM_COLOR: never
CARGO_BUILD_JOBS: "1"
ONIONWIRE_ANDROID_ABI: arm64-v8a
ANDROID_IMAGE: debian:bookworm
ANDROID_CMDLINE_TOOLS_URL: https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip
# Not the workspace MSRV (`rust-version = "1.91"`, and `ci.yml` stays on it): the
# cuprated graph needs more. `tapes` (a Cuprate dependency) calls
# `VecDeque::pop_front_if`, stable only from **1.93**, so 1.91 dies with
# `error[E0658]: use of unstable library feature 'vec_deque_pop_if'` — 15 minutes
# into the Android job, after 400-odd crates, in a dependency this repo cannot
# patch. 1.98 is the stable release this graph is built and tested with on the dev
# machine. Bumping `ci.yml` too is a separate decision (it would move the MSRV for
# the whole workspace) and is not this workflow's to make.
RUST_TOOLCHAIN: "1.98"
DOCKER_STATIC_URL: https://download.docker.com/linux/static/stable/x86_64/docker-27.5.1.tgz
# Distinct container prefix: run ids are per-workflow, so this workflow and
# android-release.yml can both be holding a container named "<prefix>-<n>".
BUILD_CONTAINER: onionwire-android-ci-${{ github.run_id }}
SDK_VOLUME: onionwire-android-sdk
CARGO_VOLUME: onionwire-android-cargo-registry
TARGET_VOLUME: onionwire-android-target
GRADLE_VOLUME: onionwire-android-gradle
jobs:
android:
runs-on: docker-amd64
timeout-minutes: 120
steps:
- name: Checkout
uses: https://code.forgejo.org/actions/checkout@v4
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: 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
- name: Record runner resources
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
if: steps.staleness.outputs.skip != 'true'
run: |
set -euo pipefail
cd "${GITHUB_WORKSPACE}"
echo "workspace=$GITHUB_WORKSPACE hostname=$(hostname) arch=$(uname -m)"
nproc || true
free -h || true
df -h || true
ls -l /var/run/docker.sock || true
- name: Ensure docker CLI
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
if: steps.staleness.outputs.skip != 'true'
run: |
set -euo pipefail
if ! command -v docker >/dev/null 2>&1; then
echo "docker CLI missing in job image; fetching static client"
curl -fsSL "$DOCKER_STATIC_URL" -o /tmp/docker.tgz
tar -xzf /tmp/docker.tgz -C /tmp
install -m 755 /tmp/docker/docker /usr/local/bin/docker
fi
export DOCKER_HOST="${DOCKER_HOST:-unix:///var/run/docker.sock}"
docker version
docker info >/tmp/docker-info.txt
grep -E 'Server Version|Operating System|Total Memory|Name' /tmp/docker-info.txt || true
- name: Build APK + AAR (debug-signed) in bookworm container
id: build
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
if: steps.staleness.outputs.skip != 'true'
run: |
set -euo pipefail
cd "${GITHUB_WORKSPACE}"
export DOCKER_HOST="${DOCKER_HOST:-unix:///var/run/docker.sock}"
start=$(date +%s)
cat > .ci-android-verify.sh <<'INNER'
#!/usr/bin/env bash
set -euo pipefail
export DEBIAN_FRONTEND=noninteractive
apt-get update
# `cmake` is for RandomX, the C++ half of the in-process chain daemon:
# without it `randomx-rs`'s build script panics with "failed to execute
# command: No such file or directory … is `cmake` not installed?" and the
# Gradle task dies on "cargo finished with non-zero exit value 101".
apt-get install -y --no-install-recommends \
openjdk-17-jdk-headless python3 unzip curl ca-certificates file build-essential pkg-config git \
cmake
if [ ! -x /opt/android-sdk/cmdline-tools/latest/bin/sdkmanager ]; then
mkdir -p /opt/android-sdk/cmdline-tools
curl -fsSL "$ANDROID_CMDLINE_TOOLS_URL" -o /tmp/cmdline-tools.zip
rm -rf /tmp/cmdline-tools
unzip -q /tmp/cmdline-tools.zip -d /tmp/cmdline-tools
mkdir -p /opt/android-sdk/cmdline-tools/latest
cp -a /tmp/cmdline-tools/cmdline-tools/. /opt/android-sdk/cmdline-tools/latest/
fi
yes | /opt/android-sdk/cmdline-tools/latest/bin/sdkmanager --sdk_root=/opt/android-sdk --licenses >/tmp/sdk-licenses.log || true
/opt/android-sdk/cmdline-tools/latest/bin/sdkmanager --sdk_root=/opt/android-sdk \
"platform-tools" "platforms;android-36" "build-tools;36.0.0" "ndk;28.2.13676358"
test -d /opt/android-sdk/ndk/28.2.13676358
export ANDROID_HOME=/opt/android-sdk ANDROID_SDK_ROOT=/opt/android-sdk
export ANDROID_NDK_HOME=/opt/android-sdk/ndk/28.2.13676358
export PATH="$ANDROID_HOME/build-tools/36.0.0:$ANDROID_HOME/platform-tools:$PATH"
if [ ! -x /cargo/bin/rustup ]; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain "$RUST_TOOLCHAIN" --no-modify-path --profile minimal
fi
export PATH="/cargo/bin:$PATH"
rustup toolchain install "$RUST_TOOLCHAIN"
rustup default "$RUST_TOOLCHAIN"
rustup target add aarch64-linux-android
command -v cargo-ndk >/dev/null || cargo install cargo-ndk --locked
echo "=== toolchain ==="
java -version
rustc --version
cargo ndk --version
du -sh /opt/android-sdk /cargo /cargo-target /gradle || true
# Shared /gradle volume: a killed container leaves journal-1.lock.
# android/gradle.properties also sets org.gradle.parallel=true, which
# is how two JVMs (PIDs ~5 apart) show up on one lock. Drop the
# stale locks and force one Gradle process for this container.
find /gradle -name '*.lock' -type f -delete 2>/dev/null || true
export GRADLE_OPTS="${GRADLE_OPTS:-} -Dorg.gradle.parallel=false -Dorg.gradle.daemon=false"
# No keystore here on purpose: this is a verification build, not a
# release build. The script warns that Gradle fell back to the debug
# key; that warning is expected in this job.
scripts/build-android-local.sh
version="$(python3 - <<'PY'
import re, pathlib
t = pathlib.Path('android/app/build.gradle.kts').read_text()
m = re.search(r'versionName\s*=.*?:\s*"([^"]+)"', t)
print(m.group(1) if m else '')
PY
)"
abi="${ONIONWIRE_ANDROID_ABI:-arm64-v8a}"
apk="dist/onionwire-$version-android-$abi.apk"
aar="dist/onionwire-sdk-$version.aar"
{
echo "=== file ==="
file "$apk" "$aar"
echo "=== unzip lib ==="
unzip -l "$apk" | grep -E 'lib/.+\.so' || true
unzip -l "$apk" | grep "lib/$abi/libonionwire_sdk.so"
# `unzip -l` shows the uncompressed size only; the *deflated* entry is
# what the download actually costs, and it is not visible anywhere else
# (v0.7.0's SDK lib was 33,481,336 B raw / 12,210,154 B deflated, which
# is the ratio a reader wants when this one grows).
echo "=== native lib entries (length / method / deflated) ==="
unzip -v "$apk" | grep -E 'lib/.+\.so$'
android: build the SDK with cuprate-daemon and offer the on-device node Part 3 of "cuprated built in": the chain daemon now ships inside the APK and the wallet screen can pick it. Build (android/sdk/build.gradle.kts) - `cargoBuildAndroid` runs `cargo ndk … build --release --lib --features cuprate-daemon`. The Android target only: `cargoHostLib` / `uniffiBindgen` stay feature-free, because the host cdylib exists only so `uniffi-bindgen --library` can dlopen it and the UniFFI surface does not fork on a cargo feature. - The link needs the NDK's libc++ and compiler-rt builtins explicitly (RandomX is C++ and its aarch64 JIT calls `__clear_cache`; `randomx-rs` links the NDK's stub `libstdc++.a`). `cargo ndk --link-builtins` covers the builtins only, so the whole set is spelled out as per-ABI `CARGO_TARGET_<TRIPLE>_RUSTFLAGS` — a global `RUSTFLAGS` would break the host build scripts. The linker is the NDK clang driver at the app's API level, named explicitly, because the dev machines pin the API 21 wrapper for `aarch64-linux-android` and API 21 fails this link. - `ANDROID_NDK` is exported alongside `ANDROID_NDK_HOME`/`NDK_HOME`: without it `cmake-rs` aborts and `randomx-rs`'s build script panics. - The task logs the feature it builds with, so CI carries the request, not just the task name. Wallet screen - Third chain source, **On-device node (Cuprate)**, beside the daemon field and Receive-only. Stored as `ChainChoice.InProcessCuprate` with an empty `monerod_datadir`, which the SDK resolves to `$ONIONWIRE_HOME/chain`. Existing Save daemon / Receive-only / Start / Stop behaviour is unchanged. - The status line grows `· node <word>` from `WalletChildStatus.node_state` for this source only, fail-closed on an unrecognised word. No sync height: the SDK exposes none, so the screen does not show a number it cannot get. - Storage honesty: free space on the chain store's filesystem, and Start is refused below a 3 GiB floor or when that filesystem cannot be read. The floor is a floor, not a sync estimate — nothing here exposes one. - The pre-production warning (quoted user book, testnet only, Cuprate issue #278) is a sentence above Start, assertable in a test. Opt-in, never a default. - The daemon field's hint no longer suggests a loopback daemon on the phone. CI - `android-ci.yml` extracts `lib/<abi>/libonionwire_sdk.so` from the built APK and fails the job unless it contains `target_max_memory`, a rodata literal compiled only under `cuprate-daemon`. v0.7.0's shipped `.so` has zero of them, so this separates "in the artifact" from "requested". Docs - `android/CUPRATE_DAEMON.md`: the build wiring, the link line, the CI gate, and an explicit "not verified on a device" section. `MONERO_BINARIES.md` points at it for the chain source that is not a binary.
2026-09-18 15:34:30 -04:00
echo "=== in-process chain daemon (cuprate-daemon) is IN this APK ==="
# The build log's "features=cuprate-daemon" line says the feature was
# *requested*; this says it is *in the artifact*. `target_max_memory` is
# a rodata literal from src/cuprate.rs's config TOML, compiled only under
# `#[cfg(feature = "cuprate-daemon")]` — v0.7.0's libonionwire_sdk.so
# contains zero occurrences of it (checked), so its presence is the
# difference between a build that carries the daemon and one that only
# claims to. A missing marker fails the job: an APK whose on-device node
# can only fail is the regression this gate exists to catch.
unzip -p "$apk" "lib/$abi/libonionwire_sdk.so" > /tmp/libonionwire_sdk.so
# `grep -c`, deliberately not `grep -q`: under `set -o pipefail` a `-q`
# match closes the pipe early, `strings` dies on SIGPIPE (141), and the
# pipeline then reports failure even though the marker was there — this
# gate failed its own green build once that way.
marker="$(strings -a /tmp/libonionwire_sdk.so | grep -c 'target_max_memory' || true)"
echo "target_max_memory occurrences: ${marker:-0}"
if [ "${marker:-0}" -lt 1 ]; then
android: build the SDK with cuprate-daemon and offer the on-device node Part 3 of "cuprated built in": the chain daemon now ships inside the APK and the wallet screen can pick it. Build (android/sdk/build.gradle.kts) - `cargoBuildAndroid` runs `cargo ndk … build --release --lib --features cuprate-daemon`. The Android target only: `cargoHostLib` / `uniffiBindgen` stay feature-free, because the host cdylib exists only so `uniffi-bindgen --library` can dlopen it and the UniFFI surface does not fork on a cargo feature. - The link needs the NDK's libc++ and compiler-rt builtins explicitly (RandomX is C++ and its aarch64 JIT calls `__clear_cache`; `randomx-rs` links the NDK's stub `libstdc++.a`). `cargo ndk --link-builtins` covers the builtins only, so the whole set is spelled out as per-ABI `CARGO_TARGET_<TRIPLE>_RUSTFLAGS` — a global `RUSTFLAGS` would break the host build scripts. The linker is the NDK clang driver at the app's API level, named explicitly, because the dev machines pin the API 21 wrapper for `aarch64-linux-android` and API 21 fails this link. - `ANDROID_NDK` is exported alongside `ANDROID_NDK_HOME`/`NDK_HOME`: without it `cmake-rs` aborts and `randomx-rs`'s build script panics. - The task logs the feature it builds with, so CI carries the request, not just the task name. Wallet screen - Third chain source, **On-device node (Cuprate)**, beside the daemon field and Receive-only. Stored as `ChainChoice.InProcessCuprate` with an empty `monerod_datadir`, which the SDK resolves to `$ONIONWIRE_HOME/chain`. Existing Save daemon / Receive-only / Start / Stop behaviour is unchanged. - The status line grows `· node <word>` from `WalletChildStatus.node_state` for this source only, fail-closed on an unrecognised word. No sync height: the SDK exposes none, so the screen does not show a number it cannot get. - Storage honesty: free space on the chain store's filesystem, and Start is refused below a 3 GiB floor or when that filesystem cannot be read. The floor is a floor, not a sync estimate — nothing here exposes one. - The pre-production warning (quoted user book, testnet only, Cuprate issue #278) is a sentence above Start, assertable in a test. Opt-in, never a default. - The daemon field's hint no longer suggests a loopback daemon on the phone. CI - `android-ci.yml` extracts `lib/<abi>/libonionwire_sdk.so` from the built APK and fails the job unless it contains `target_max_memory`, a rodata literal compiled only under `cuprate-daemon`. v0.7.0's shipped `.so` has zero of them, so this separates "in the artifact" from "requested". Docs - `android/CUPRATE_DAEMON.md`: the build wiring, the link line, the CI gate, and an explicit "not verified on a device" section. `MONERO_BINARIES.md` points at it for the chain source that is not a binary.
2026-09-18 15:34:30 -04:00
echo "lib/$abi/libonionwire_sdk.so carries no cuprated config string: the cuprate-daemon feature is NOT in this APK" >&2
exit 1
fi
echo "=== classes.dex + Compose entrypoints ==="
unzip -l "$apk" | grep -E 'classes[0-9]*\.dex' | head -n3
echo "=== sha256 ==="
# `sha256sum -c` proves each artifact matches the digest the build
# recorded, but prints neither number. The digest *is* the artifact's
# identity, and an APK is not byte-reproducible across machines, so it
# cannot be derived from the tree afterwards — echo both.
cat "dist/onionwire-$version-android-$abi.apk.sha256" "dist/onionwire-sdk-$version.aar.sha256"
( cd dist && sha256sum -c "onionwire-$version-android-$abi.apk.sha256" "onionwire-sdk-$version.aar.sha256" )
echo "=== apksigner (expect debug cert: this is a verification build) ==="
apksigner verify --print-certs "$apk" | sed -n '1,6p'
echo "=== aapt ==="
aapt dump badging "$apk" | sed -n '1,20p' || true
echo "=== sizes ==="
wc -c "$apk" "$aar"
# The cross-compile volume this build just grew. The cuprated graph is
# ~152 crates plus a C++ RandomX build, so the number is the disk cost
# of the feature on the runner, next to the wall clock above.
echo "=== cargo target volume (after this build) ==="
du -sh /cargo-target 2>/dev/null || true
du -sh /cargo-target/aarch64-linux-android/release 2>/dev/null || true
} | tee dist/android-ci-verify.log
INNER
chmod +x .ci-android-verify.sh
docker volume create "$SDK_VOLUME" >/dev/null
docker volume create "$CARGO_VOLUME" >/dev/null
docker volume create "$TARGET_VOLUME" >/dev/null
docker volume create "$GRADLE_VOLUME" >/dev/null
# Cancelled jobs never reach the trailing `docker rm`, so a previous
# onionwire-android-* container can still hold GRADLE_VOLUME. The next
# Gradle then dies LockTimeoutException on /gradle/caches/journal-1
# (owner PID vs our PID a few numbers apart — two JVMs, one volume).
trap 'docker rm -f "$BUILD_CONTAINER" >/dev/null 2>&1 || true' EXIT
docker ps -aq --filter name=onionwire-android- | xargs -r docker rm -f || true
docker rm -f "$BUILD_CONTAINER" >/dev/null 2>&1 || true
docker pull "$ANDROID_IMAGE"
# 2 GB of Gradle heap, not 1: the only budget in this build that is close
# is the single-use daemon's heap, which now has to package a 55 MB SDK
# lib (plus RandomX's 1.1 MB) through AGP's in-daemon packaging. Run 414
# died in `:app:packageRelease` with the cause hidden inside
# `PackageAndroidArtifact$IncrementalSplitterRunnable` — no "Caused by"
# line, nothing in the log — so give it room instead of guessing again.
# The runner has 15 GB and the job's peak RSS is ~3 GB.
docker create --name "$BUILD_CONTAINER" -i \
-e CARGO_TERM_COLOR=never \
-e CARGO_BUILD_JOBS="$CARGO_BUILD_JOBS" \
-e CARGO_HOME=/cargo \
-e CARGO_TARGET_DIR=/cargo-target \
-e GRADLE_USER_HOME=/gradle \
-e ANDROID_HOME=/opt/android-sdk \
-e ANDROID_SDK_ROOT=/opt/android-sdk \
-e ANDROID_NDK_HOME=/opt/android-sdk/ndk/28.2.13676358 \
-e ONIONWIRE_ANDROID_ABI="$ONIONWIRE_ANDROID_ABI" \
-e ONIONWIRE_REQUIRE_RELEASE_KEY=false \
-e RUST_TOOLCHAIN="$RUST_TOOLCHAIN" \
-e ANDROID_CMDLINE_TOOLS_URL="$ANDROID_CMDLINE_TOOLS_URL" \
-e GRADLE_OPTS="-Dorg.gradle.daemon=false -Dorg.gradle.parallel=false -Dorg.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8" \
-v "$SDK_VOLUME":/opt/android-sdk \
-v "$CARGO_VOLUME":/cargo \
-v "$TARGET_VOLUME":/cargo-target \
-v "$GRADLE_VOLUME":/gradle \
-w /src \
"$ANDROID_IMAGE" \
bash -euxc 'mkdir -p /src && tar xzf - -C /src && cd /src && bash /src/.ci-android-verify.sh'
tar czf - \
--exclude=./target --exclude=./.git --exclude=./.worktrees \
--exclude=./android/.gradle --exclude=./android/app/build \
--exclude=./android/sdk/build --exclude=./dist \
--exclude=./crates/onionwire-sdk/target \
. \
| docker start -a -i "$BUILD_CONTAINER"
mkdir -p dist
docker cp "$BUILD_CONTAINER:/src/dist/." dist/
end=$(date +%s)
echo "build_wall_clock_seconds=$((end - start))"
echo "wall_clock_seconds=$((end - start))" >> "$GITHUB_OUTPUT"
docker rm -f "$BUILD_CONTAINER" >/dev/null || true
ls -l dist/
- name: Verify artifacts
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
if: steps.staleness.outputs.skip != 'true'
run: |
set -euo pipefail
cd "${GITHUB_WORKSPACE}"
abi="$ONIONWIRE_ANDROID_ABI"
ls -l dist/
apk="$(ls dist/onionwire-*-android-$abi.apk)"
aar="$(ls dist/onionwire-sdk-*.aar)"
[ -s "$apk" ] || { echo "missing or empty $apk" >&2; exit 1; }
[ -s "$aar" ] || { echo "missing or empty $aar" >&2; exit 1; }
echo "apk=$apk bytes=$(wc -c < "$apk")"
echo "aar=$aar bytes=$(wc -c < "$aar")"
( cd dist && sha256sum -c ./*.sha256 )
echo "=== android-ci-verify.log (from build container) ==="
cat dist/android-ci-verify.log
echo "=== resources after build ==="
free -h || true
df -h || true