diff --git a/.forgejo/workflows/android-release.yml b/.forgejo/workflows/android-release.yml index 5245ff4..14311a8 100644 --- a/.forgejo/workflows/android-release.yml +++ b/.forgejo/workflows/android-release.yml @@ -1,16 +1,11 @@ name: android-release -# Build the Android APK + SDK AAR on docker-amd64 and attach them to the -# 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, -# the same stdin-tar + docker cp pattern as .forgejo/workflows/ci.yml. +# Build the Android APK + SDK AAR on the amd64 runner and attach them to the +# Forgejo release for the computed (or requested) tag. Standalone on push to +# main, dispatch, or as a reusable workflow. # # 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. Never move an existing tag. on: push: @@ -26,10 +21,10 @@ on: required: false type: string dry_run: - description: Build and checksum without creating a tag or publishing (true/false) + description: Build and checksum without creating a tag or publishing required: false - type: string - default: "false" + type: boolean + default: false workflow_call: inputs: tag: @@ -37,8 +32,8 @@ on: type: string dry_run: required: false - type: string - default: "false" + type: boolean + default: false concurrency: group: onionwire-android-release @@ -49,15 +44,10 @@ env: CARGO_BUILD_JOBS: "1" ONIONWIRE_ANDROID_ABI: arm64-v8a ONIONWIRE_REQUIRE_RELEASE_KEY: "true" - ANDROID_IMAGE: eclipse-temurin:17-jdk-bookworm + # The dind pod is capped at 4Gi. Keep Gradle small or the job is 137. + GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.jvmargs=-Xmx1024m -XX:MaxMetaspaceSize=384m -Dfile.encoding=UTF-8" 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 - BUILD_CONTAINER: onionwire-android-${{ 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: @@ -68,17 +58,16 @@ jobs: uses: https://code.forgejo.org/actions/checkout@v4 with: fetch-depth: 0 - ref: ${{ github.event.inputs.tag || inputs.tag || github.sha }} + ref: ${{ inputs.tag || github.event.inputs.tag || github.sha }} - name: Record runner resources run: | set -euo pipefail cd "${GITHUB_WORKSPACE}" echo "workspace=$GITHUB_WORKSPACE hostname=$(hostname) arch=$(uname -m)" - nproc || true + nproc free -h || true df -h || true - ls -l /var/run/docker.sock || true - name: Compute version id: version @@ -89,7 +78,6 @@ jobs: run: | set -euo pipefail cd "${GITHUB_WORKSPACE}" - echo "INPUT_DRY_RUN='${INPUT_DRY_RUN:-}' CALL_DRY_RUN='${CALL_DRY_RUN:-}' EVENT=${GITHUB_EVENT_NAME:-}" git fetch --tags --force origin || true input_tag="${INPUT_TAG:-}" dry_run=false @@ -129,6 +117,65 @@ jobs: } >> "$GITHUB_OUTPUT" echo "version=$ver tag=$tag versionCode=$code dry_run=$dry_run" + - name: Install JDK, Rust, Android SDK, cargo-ndk + run: | + set -euo pipefail + cd "${GITHUB_WORKSPACE}" + export DEBIAN_FRONTEND=noninteractive + # T480 dind timed out on http://deb.debian.org:80 (Fastly). HTTPS works + # for Forgejo checkout; flip the debian mirrors before apt-get update. + if [ -f /etc/apt/sources.list ]; then + sed -i 's|http://deb.debian.org|https://deb.debian.org|g; s|http://security.debian.org|https://security.debian.org|g; s|http://deb.debian.org/debian-security|https://deb.debian.org/debian-security|g' /etc/apt/sources.list + fi + ls /etc/apt/sources.list.d 2>/dev/null || true + cat /etc/apt/sources.list || true + apt-get -o Acquire::Retries=3 -o Acquire::https::Timeout=60 update + apt-get install -y --no-install-recommends \ + openjdk-17-jdk-headless python3 python3-minimal unzip curl ca-certificates \ + file build-essential pkg-config git + java -version + python3 --version + + export ANDROID_HOME="${ANDROID_HOME:-$HOME/android-sdk}" + export ANDROID_SDK_ROOT="$ANDROID_HOME" + mkdir -p "$ANDROID_HOME/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 "$ANDROID_HOME/cmdline-tools/latest" + cp -a /tmp/cmdline-tools/cmdline-tools/. "$ANDROID_HOME/cmdline-tools/latest/" + yes | "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" --sdk_root="$ANDROID_HOME" --licenses >/tmp/sdk-licenses.log || true + "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" --sdk_root="$ANDROID_HOME" \ + "platform-tools" "platforms;android-36" "build-tools;36.0.0" "ndk;28.2.13676358" + test -d "$ANDROID_HOME/ndk/28.2.13676358" + echo "ANDROID_HOME=$ANDROID_HOME" + du -sh "$ANDROID_HOME" "$ANDROID_HOME/ndk/28.2.13676358" || true + + if [ ! -x "$HOME/.cargo/bin/rustup" ]; then + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain "$RUST_TOOLCHAIN" + fi + # shellcheck disable=SC1091 + source "$HOME/.cargo/env" + rustup toolchain install "$RUST_TOOLCHAIN" + rustup default "$RUST_TOOLCHAIN" + rustup target add aarch64-linux-android + rustc --version + cargo --version + cargo install cargo-ndk --locked + cargo ndk --version + + echo "ANDROID_HOME=$ANDROID_HOME" >> "$GITHUB_ENV" + echo "ANDROID_SDK_ROOT=$ANDROID_HOME" >> "$GITHUB_ENV" + echo "ANDROID_NDK_HOME=$ANDROID_HOME/ndk/28.2.13676358" >> "$GITHUB_ENV" + echo "$HOME/.cargo/bin" >> "$GITHUB_PATH" + echo "$ANDROID_HOME/cmdline-tools/latest/bin" >> "$GITHUB_PATH" + echo "$ANDROID_HOME/platform-tools" >> "$GITHUB_PATH" + echo "$ANDROID_HOME/build-tools/36.0.0" >> "$GITHUB_PATH" + echo "=== resources after SDK install ===" + free -h || true + df -h || true + du -sh "$HOME/android-sdk" "$HOME/.cargo" 2>/dev/null || true + - name: Decode release keystore env: ANDROID_KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }} @@ -151,147 +198,25 @@ jobs: test -s "$ks" umask 077 printf 'ANDROID_KEYSTORE_FILE=%s\nANDROID_KEYSTORE_PASSWORD=%s\nANDROID_KEY_ALIAS=%s\nANDROID_KEY_PASSWORD=%s\n' \ - "/root/.android/onionwire-release.jks" "$ANDROID_KEYSTORE_PASSWORD" "$ANDROID_KEY_ALIAS" "$ANDROID_KEY_PASSWORD" > "$envf" + "$ks" "$ANDROID_KEYSTORE_PASSWORD" "$ANDROID_KEY_ALIAS" "$ANDROID_KEY_PASSWORD" > "$envf" chmod 600 "$envf" - echo "keystore bytes=$(wc -c < "$ks") staged for the build container" + echo "keystore bytes=$(wc -c < "$ks") written under ~/.android (not logged)" - - name: Ensure docker CLI - 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 in bookworm container - id: build - env: - VERSION: ${{ steps.version.outputs.version }} - VERSION_CODE: ${{ steps.version.outputs.version_code }} + - name: Build APK + AAR run: | set -euo pipefail cd "${GITHUB_WORKSPACE}" - export DOCKER_HOST="${DOCKER_HOST:-unix:///var/run/docker.sock}" - start=$(date +%s) - cat > .ci-android-build.sh <<'INNER' - #!/usr/bin/env bash - set -euo pipefail - 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 - 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 - chmod 600 /root/.android/onionwire-release.jks /root/.android/onionwire-release.env # shellcheck disable=SC1091 - set -a - source /root/.android/onionwire-release.env - set +a - 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 - scripts/build-android-local.sh "$ONIONWIRE_VERSION" - version="$ONIONWIRE_VERSION" - 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|AndroidManifest.xml' || true - unzip -l "$apk" | grep "lib/$abi/libonionwire_sdk.so" - echo "=== sha256 ===" - ( cd dist && sha256sum -c "onionwire-$version-android-$abi.apk.sha256" "onionwire-sdk-$version.aar.sha256" ) - echo "=== apksigner ===" - apksigner verify --print-certs "$apk" - echo "=== aapt ===" - aapt dump badging "$apk" | head -n 20 - echo "=== sizes ===" - wc -c "$apk" "$aar" - } | tee dist/ci-verify.log - INNER - chmod +x .ci-android-build.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 - docker rm -f "$BUILD_CONTAINER" >/dev/null 2>&1 || true - docker pull "$ANDROID_IMAGE" - 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=true \ - -e ONIONWIRE_VERSION_CODE="$VERSION_CODE" \ - -e ONIONWIRE_VERSION="$VERSION" \ - -e RUST_TOOLCHAIN="$RUST_TOOLCHAIN" \ - -e ANDROID_CMDLINE_TOOLS_URL="$ANDROID_CMDLINE_TOOLS_URL" \ - -e GRADLE_OPTS="-Dorg.gradle.daemon=false -Dorg.gradle.jvmargs=-Xmx1024m -XX:MaxMetaspaceSize=384m -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-build.sh' - # Staging dir is included in the tar as .ci-android/ (gitignored paths). - mkdir -p .ci-android - cp "$HOME/.android/onionwire-release.jks" .ci-android/onionwire-release.jks - cp "$HOME/.android/onionwire-release.env" .ci-android/onionwire-release.env - 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/ + source "$HOME/.cargo/env" 2>/dev/null || true + export ANDROID_HOME="${ANDROID_HOME:?}" + export ANDROID_SDK_ROOT="$ANDROID_HOME" + export ANDROID_NDK_HOME="${ANDROID_NDK_HOME:?}" + export ONIONWIRE_VERSION_CODE="${{ steps.version.outputs.version_code }}" + export ONIONWIRE_REQUIRE_RELEASE_KEY=true + start=$(date +%s) + scripts/build-android-local.sh "${{ steps.version.outputs.version }}" 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 - rm -rf .ci-android - ls -l dist/ - name: Verify artifacts run: | @@ -308,18 +233,21 @@ jobs: echo "apk_bytes=$apk_bytes aar_bytes=$aar_bytes" [ "$apk_bytes" -gt 0 ] [ "$aar_bytes" -gt 0 ] + file "$apk" "$aar" + echo "=== unzip -l lib ===" + unzip -l "$apk" | grep -E 'lib/.+\.so|AndroidManifest.xml' || true + unzip -l "$apk" | grep "lib/$abi/libonionwire_sdk.so" + echo "=== sha256 ===" ( cd dist && sha256sum -c "onionwire-$version-android-$abi.apk.sha256" "onionwire-sdk-$version.aar.sha256" ) - echo "=== ci-verify.log (from bookworm build container) ===" - cat dist/ci-verify.log + echo "=== apksigner ===" + apksigner verify --print-certs "$apk" + echo "=== aapt dump badging ===" + aapt dump badging "$apk" | head -n 20 echo "=== resources after build ===" free -h || true df -h || true - export DOCKER_HOST="${DOCKER_HOST:-unix:///var/run/docker.sock}" - docker images "$ANDROID_IMAGE" --format '{{.Repository}}:{{.Tag}} {{.Size}}' || true - docker system df || true - name: Publish (create-or-join) - id: publish if: steps.version.outputs.dry_run != 'true' env: FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }} @@ -338,6 +266,8 @@ jobs: [ "$bytes" -gt 0 ] || { echo "refusing to publish empty $f" >&2; exit 1; } done + # Give the core workflow ~60s to create the tag first. If it exists, + # join that release and never send target_commitish (would move it). tag_exists=0 i=0 while [ "$i" -lt 6 ]; do @@ -354,60 +284,33 @@ jobs: sleep 10 done - created_tag=false if [ "$tag_exists" = "1" ]; then unset TARGET_COMMITISH || true else export TARGET_COMMITISH="$EVENT_SHA" - created_tag=true echo "creating tag $TAG at $TARGET_COMMITISH" fi - echo "created_tag=$created_tag" >> "$GITHUB_OUTPUT" - export DOCKER_HOST="${DOCKER_HOST:-unix:///var/run/docker.sock}" - PUB_C=onionwire-android-publish-${{ github.run_id }} - docker rm -f "$PUB_C" >/dev/null 2>&1 || true - docker create --name "$PUB_C" -i \ - -e FORGEJO_TOKEN \ - -e REPO_API \ - -e TARGET_COMMITISH="${TARGET_COMMITISH:-}" \ - -e TAG \ - -w /src \ - "$ANDROID_IMAGE" \ - bash -euxc 'mkdir -p /src && tar xzf - -C /src && cd /src && apt-get update && apt-get install -y --no-install-recommends python3 curl ca-certificates >/dev/null && scripts/publish-release.sh "$TAG" "OnionWire $TAG" scripts/release-body.md dist/onionwire-'"$VERSION"'-android-'"$ONIONWIRE_ANDROID_ABI"'.apk dist/onionwire-'"$VERSION"'-android-'"$ONIONWIRE_ANDROID_ABI"'.apk.sha256 dist/onionwire-sdk-'"$VERSION"'.aar dist/onionwire-sdk-'"$VERSION"'.aar.sha256' - tar czf - \ - --exclude=./target --exclude=./.git --exclude=./.worktrees \ - --exclude=./android/.gradle --exclude=./android/app/build \ - --exclude=./android/sdk/build \ - --exclude=./crates/onionwire-sdk/target \ - . \ - | 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" + published=0 + attempt=1 + while [ "$attempt" -le 5 ]; do + if scripts/publish-release.sh \ + "$TAG" "OnionWire $TAG" \ + scripts/release-body.md \ + "$apk" "$apk.sha256" "$aar" "$aar.sha256"; then + published=1 + break + fi + echo "publish attempt $attempt failed; retry in 10s" + unset TARGET_COMMITISH || true + attempt=$((attempt + 1)) + sleep 10 + done + [ "$published" = "1" ] || { echo "publish failed after retries" >&2; exit 1; } - name: Scrub keystore if: always() run: | set -euo pipefail - rm -rf "$HOME/.android/onionwire-release.jks" "$HOME/.android/onionwire-release.env" .ci-android - echo "keystore removed from runner" + rm -f "$HOME/.android/onionwire-release.jks" "$HOME/.android/onionwire-release.env" "$HOME/onionwire-release.jks" + echo "keystore removed from runner home" diff --git a/android/README.md b/android/README.md index f784dbc..890ba71 100644 --- a/android/README.md +++ b/android/README.md @@ -122,9 +122,6 @@ deobfuscation, not before. ## CI `.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 -(stdin-tar + `docker cp`, same pattern as the Rust CI job). Any push to `main` that touches `android/**` (or the local build script / this workflow) builds `onionwire--android-arm64-v8a.apk` and `onionwire-sdk-.aar`, verifies them, and attaches them to the Forgejo