fix(ci): Android APK build in debian:bookworm sibling container #30

Merged
sirius merged 6 commits from wt/t_87d7245b into main 2026-09-12 13:43:38 +00:00
3 changed files with 56 additions and 40 deletions

View file

@ -4,19 +4,23 @@ name: android-release
# Forgejo release for the computed (or requested) tag.
#
# The runner job image is node:20-bullseye (EOL). Do not apt-get there.
# The toolchain runs in a sibling eclipse-temurin:17-jdk-bookworm container,
# toolchain runs in a sibling debian:bookworm container,
# the same stdin-tar + docker cp pattern as .forgejo/workflows/ci.yml.
#
# First automated version with zero tags: v0.1.0. Afterwards, patch+1 from the
# latest v*.*.* tag. Never move an existing tag. If this workflow creates a
# tag and then fails, it deletes that tag so the next run retries the same
# version instead of skipping.
# latest v*.*.* tag UNLESS that tag's release is missing the Android assets —
# then join it (core owns tag creation). Never move or delete a tag.
on:
push:
branches: [main]
paths:
- "android/**"
- "android/app/**"
- "android/sdk/**"
- "android/*.gradle.kts"
- "android/gradle/**"
- "android/gradle.properties"
- "android/settings.gradle.kts"
- "scripts/build-android-local.sh"
- ".forgejo/workflows/android-release.yml"
workflow_dispatch:
@ -41,7 +45,7 @@ on:
default: "false"
concurrency:
group: onionwire-android-release
group: onionwire-android-release-v2
cancel-in-progress: false
env:
@ -49,7 +53,7 @@ env:
CARGO_BUILD_JOBS: "1"
ONIONWIRE_ANDROID_ABI: arm64-v8a
ONIONWIRE_REQUIRE_RELEASE_KEY: "true"
ANDROID_IMAGE: eclipse-temurin:17-jdk-bookworm
ANDROID_IMAGE: debian:bookworm
ANDROID_CMDLINE_TOOLS_URL: https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip
RUST_TOOLCHAIN: "1.91"
DOCKER_STATIC_URL: https://download.docker.com/linux/static/stable/x86_64/docker-27.5.1.tgz
@ -86,6 +90,8 @@ jobs:
INPUT_TAG: ${{ github.event.inputs.tag || inputs.tag }}
INPUT_DRY_RUN: ${{ github.event.inputs.dry_run }}
CALL_DRY_RUN: ${{ inputs.dry_run }}
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
REPO_API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}
run: |
set -euo pipefail
cd "${GITHUB_WORKSPACE}"
@ -102,13 +108,37 @@ jobs:
if [ -z "$latest" ]; then
ver="0.1.0"
else
ver="${latest#v}"
major="${ver%%.*}"
rest="${ver#*.}"
minor="${rest%%.*}"
patch="${rest#*.}"
patch=$((patch + 1))
ver="${major}.${minor}.${patch}"
# Core owns tag creation. If the latest tag's release is missing
# the Android APK, join that version instead of minting patch+1.
join=0
if [ -n "${FORGEJO_TOKEN:-}" ]; then
http=$(curl -sS --http1.1 -o /tmp/latest-rel.json -w '%{http_code}' \
-H "Authorization: Bearer $FORGEJO_TOKEN" \
"$REPO_API/releases/tags/$latest" || true)
if [ "$http" != "200" ]; then
join=1
echo "latest tag $latest has no release (http $http); joining"
elif node -e 'const d=require("/tmp/latest-rel.json"); const n=(d.assets||[]).some(a=>/onionwire-.*-android-.*\\.apk$/.test(a.name)); process.exit(n?0:1)'; then
echo "latest tag $latest already has an Android APK; patch+1"
else
join=1
echo "latest tag $latest release is missing Android APK; joining"
fi
else
echo "FORGEJO_TOKEN unset; cannot inspect release assets, joining $latest"
join=1
fi
if [ "$join" = "1" ]; then
ver="${latest#v}"
else
ver="${latest#v}"
major="${ver%%.*}"
rest="${ver#*.}"
minor="${rest%%.*}"
patch="${rest#*.}"
patch=$((patch + 1))
ver="${major}.${minor}.${patch}"
fi
fi
fi
echo "$ver" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$' || {
@ -185,7 +215,7 @@ jobs:
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y --no-install-recommends \
python3 unzip curl ca-certificates file build-essential pkg-config git
openjdk-17-jdk-headless python3 unzip curl ca-certificates file build-essential pkg-config git
mkdir -p /root/.android
cp /src/.ci-android/onionwire-release.jks /root/.android/onionwire-release.jks
cp /src/.ci-android/onionwire-release.env /root/.android/onionwire-release.env
@ -238,7 +268,7 @@ jobs:
echo "=== apksigner ==="
apksigner verify --print-certs "$apk"
echo "=== aapt ==="
aapt dump badging "$apk" | head -n 20
aapt dump badging "$apk" | sed -n '1,20p' || true
echo "=== sizes ==="
wc -c "$apk" "$aar"
} | tee dist/ci-verify.log
@ -384,27 +414,6 @@ jobs:
| docker start -a -i "$PUB_C"
docker rm -f "$PUB_C" >/dev/null || true
- name: Drop dangling tag on failure
if: failure() && steps.version.outputs.dry_run != 'true' && steps.publish.outputs.created_tag == 'true'
env:
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
REPO_API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}
TAG: ${{ steps.version.outputs.tag }}
run: |
set -euo pipefail
: "${FORGEJO_TOKEN:?}"
echo "build/publish failed after creating $TAG; deleting so the next run retries this version"
curl -sS --http1.1 -X DELETE \
-H "Authorization: Bearer $FORGEJO_TOKEN" \
"$REPO_API/git/tags/$TAG" || true
curl -sS --http1.1 -X DELETE \
-H "Authorization: Bearer $FORGEJO_TOKEN" \
"$REPO_API/tags/$TAG" || true
code=$(curl -sS --http1.1 -o /tmp/tag-after.json -w '%{http_code}' \
-H "Authorization: Bearer $FORGEJO_TOKEN" \
"$REPO_API/tags/$TAG" || true)
echo "GET tags/$TAG after delete -> $code"
- name: Scrub keystore
if: always()
run: |

View file

@ -123,9 +123,10 @@ deobfuscation, not before.
`.forgejo/workflows/android-release.yml` runs on `docker-amd64` (T480 dind).
The job image is `node:20-bullseye` (EOL) — **do not apt-get there**. The
toolchain runs in a sibling `eclipse-temurin:17-jdk-bookworm` container
toolchain runs in a sibling `debian:bookworm` container
(stdin-tar + `docker cp`, same pattern as the Rust CI job).
Any push to `main` that touches `android/**` (or the local build script / this
Any push to `main` that touches Android **sources or build config**
(`android/app/**`, `android/sdk/**`, Gradle files — not `android/README.md`)
workflow) builds `onionwire-<version>-android-arm64-v8a.apk` and
`onionwire-sdk-<version>.aar`, verifies them, and attaches them to the Forgejo
release for that tag. Version is the latest `v*.*.*` tag plus patch, or

View file

@ -55,6 +55,12 @@ val onionwireAbis: List<String> = (findProperty("onionwire.abis") as String?)
val jniLibsDir = layout.buildDirectory.dir("rustJniLibs")
val uniffiKotlinDir = layout.buildDirectory.dir("generated/uniffi")
// cargo honors CARGO_TARGET_DIR when set (CI sibling container). UniFFI's
// --library path must match, or bindgen dies with ENOENT after a green compile.
val cargoTargetDir: File = System.getenv("CARGO_TARGET_DIR")?.let(::File)
?: sdkCrateDir.resolve("target")
val hostCdylib: File = cargoTargetDir.resolve("release/libonionwire_sdk.so")
/** Host cdylib. UniFFI's `--library` mode dlopens it, so it must be host-arch. */
val cargoHostLib by tasks.registering(Exec::class) {
group = "onionwire"
@ -76,7 +82,7 @@ val uniffiBindgen by tasks.registering(Exec::class) {
commandLine(
cargoExe, "run", "--release", "--bin", "uniffi-bindgen", "--",
"generate",
"--library", "target/release/libonionwire_sdk.so",
"--library", hostCdylib.absolutePath,
"--language", "kotlin",
"--no-format",
"--config", "uniffi.toml",