Merge pull request 'feat(android): auto-publish signed APK and AAR from CI' (#26) from wt/t_87d7245b into main
All checks were successful
ci / test (push) Successful in 3m8s
All checks were successful
ci / test (push) Successful in 3m8s
Reviewed-on: #26
This commit is contained in:
commit
4a248f5b73
4 changed files with 420 additions and 26 deletions
316
.forgejo/workflows/android-release.yml
Normal file
316
.forgejo/workflows/android-release.yml
Normal file
|
|
@ -0,0 +1,316 @@
|
|||
name: android-release
|
||||
|
||||
# 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.
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- "android/**"
|
||||
- "scripts/build-android-local.sh"
|
||||
- ".forgejo/workflows/android-release.yml"
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: Existing tag to (re)build and attach (empty = next version)
|
||||
required: false
|
||||
type: string
|
||||
dry_run:
|
||||
description: Build and checksum without creating a tag or publishing
|
||||
required: false
|
||||
type: boolean
|
||||
default: false
|
||||
workflow_call:
|
||||
inputs:
|
||||
tag:
|
||||
required: false
|
||||
type: string
|
||||
dry_run:
|
||||
required: false
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
concurrency:
|
||||
group: onionwire-android-release
|
||||
cancel-in-progress: false
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: never
|
||||
CARGO_BUILD_JOBS: "1"
|
||||
ONIONWIRE_ANDROID_ABI: arm64-v8a
|
||||
ONIONWIRE_REQUIRE_RELEASE_KEY: "true"
|
||||
# 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"
|
||||
|
||||
jobs:
|
||||
android:
|
||||
runs-on: docker-amd64
|
||||
timeout-minutes: 90
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: https://code.forgejo.org/actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
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
|
||||
free -h || true
|
||||
df -h || true
|
||||
|
||||
- name: Compute version
|
||||
id: version
|
||||
env:
|
||||
INPUT_TAG: ${{ github.event.inputs.tag || inputs.tag }}
|
||||
INPUT_DRY_RUN: ${{ github.event.inputs.dry_run }}
|
||||
CALL_DRY_RUN: ${{ inputs.dry_run }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
cd "${GITHUB_WORKSPACE}"
|
||||
git fetch --tags --force origin || true
|
||||
input_tag="${INPUT_TAG:-}"
|
||||
dry_run=false
|
||||
case "${INPUT_DRY_RUN:-}" in true|TRUE|True|1|yes|YES) dry_run=true ;; esac
|
||||
case "${CALL_DRY_RUN:-}" in true|TRUE|True|1|yes|YES) dry_run=true ;; esac
|
||||
if [ -n "$input_tag" ]; then
|
||||
ver="${input_tag#v}"
|
||||
else
|
||||
latest="$(git tag -l 'v*.*.*' --sort=-v:refname | head -n1 || true)"
|
||||
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}"
|
||||
fi
|
||||
fi
|
||||
echo "$ver" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$' || {
|
||||
echo "not a MAJOR.MINOR.PATCH version: $ver" >&2
|
||||
exit 1
|
||||
}
|
||||
major="${ver%%.*}"
|
||||
rest="${ver#*.}"
|
||||
minor="${rest%%.*}"
|
||||
patch="${rest#*.}"
|
||||
code=$((major * 10000 + minor * 100 + patch))
|
||||
tag="v$ver"
|
||||
{
|
||||
echo "version=$ver"
|
||||
echo "tag=$tag"
|
||||
echo "version_code=$code"
|
||||
echo "dry_run=$dry_run"
|
||||
} >> "$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 }}
|
||||
ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
|
||||
ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
|
||||
ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
cd "${GITHUB_WORKSPACE}"
|
||||
: "${ANDROID_KEYSTORE_BASE64:?ANDROID_KEYSTORE_BASE64 secret is missing}"
|
||||
: "${ANDROID_KEYSTORE_PASSWORD:?ANDROID_KEYSTORE_PASSWORD secret is missing}"
|
||||
: "${ANDROID_KEY_ALIAS:?ANDROID_KEY_ALIAS secret is missing}"
|
||||
: "${ANDROID_KEY_PASSWORD:?ANDROID_KEY_PASSWORD secret is missing}"
|
||||
mkdir -p "$HOME/.android"
|
||||
chmod 700 "$HOME/.android"
|
||||
ks="$HOME/.android/onionwire-release.jks"
|
||||
envf="$HOME/.android/onionwire-release.env"
|
||||
printf '%s' "$ANDROID_KEYSTORE_BASE64" | base64 -d > "$ks"
|
||||
chmod 600 "$ks"
|
||||
test -s "$ks"
|
||||
umask 077
|
||||
printf 'ANDROID_KEYSTORE_FILE=%s\nANDROID_KEYSTORE_PASSWORD=%s\nANDROID_KEY_ALIAS=%s\nANDROID_KEY_PASSWORD=%s\n' \
|
||||
"$ks" "$ANDROID_KEYSTORE_PASSWORD" "$ANDROID_KEY_ALIAS" "$ANDROID_KEY_PASSWORD" > "$envf"
|
||||
chmod 600 "$envf"
|
||||
echo "keystore bytes=$(wc -c < "$ks") written under ~/.android (not logged)"
|
||||
|
||||
- name: Build APK + AAR
|
||||
run: |
|
||||
set -euo pipefail
|
||||
cd "${GITHUB_WORKSPACE}"
|
||||
# shellcheck disable=SC1091
|
||||
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))"
|
||||
|
||||
- name: Verify artifacts
|
||||
run: |
|
||||
set -euo pipefail
|
||||
cd "${GITHUB_WORKSPACE}"
|
||||
version="${{ steps.version.outputs.version }}"
|
||||
abi="$ONIONWIRE_ANDROID_ABI"
|
||||
apk="dist/onionwire-$version-android-$abi.apk"
|
||||
aar="dist/onionwire-sdk-$version.aar"
|
||||
[ -s "$apk" ] || { echo "missing or empty $apk" >&2; exit 1; }
|
||||
[ -s "$aar" ] || { echo "missing or empty $aar" >&2; exit 1; }
|
||||
apk_bytes=$(wc -c < "$apk")
|
||||
aar_bytes=$(wc -c < "$aar")
|
||||
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 "=== 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
|
||||
|
||||
- name: Publish (create-or-join)
|
||||
if: steps.version.outputs.dry_run != 'true'
|
||||
env:
|
||||
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
||||
REPO_API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}
|
||||
EVENT_SHA: ${{ github.sha }}
|
||||
TAG: ${{ steps.version.outputs.tag }}
|
||||
VERSION: ${{ steps.version.outputs.version }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
cd "${GITHUB_WORKSPACE}"
|
||||
: "${FORGEJO_TOKEN:?FORGEJO_TOKEN secret is missing}"
|
||||
apk="dist/onionwire-$VERSION-android-$ONIONWIRE_ANDROID_ABI.apk"
|
||||
aar="dist/onionwire-sdk-$VERSION.aar"
|
||||
for f in "$apk" "$apk.sha256" "$aar" "$aar.sha256"; do
|
||||
bytes=$(wc -c < "$f")
|
||||
[ "$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
|
||||
code=$(curl -sS --http1.1 -o /tmp/tag.json -w '%{http_code}' \
|
||||
-H "Authorization: Bearer $FORGEJO_TOKEN" \
|
||||
"$REPO_API/tags/$TAG" || true)
|
||||
if [ "$code" = "200" ]; then
|
||||
tag_exists=1
|
||||
echo "tag $TAG already exists; joining"
|
||||
break
|
||||
fi
|
||||
i=$((i + 1))
|
||||
echo "tag $TAG not found yet (http $code), wait 10s ($i/6)"
|
||||
sleep 10
|
||||
done
|
||||
|
||||
if [ "$tag_exists" = "1" ]; then
|
||||
unset TARGET_COMMITISH || true
|
||||
else
|
||||
export TARGET_COMMITISH="$EVENT_SHA"
|
||||
echo "creating tag $TAG at $TARGET_COMMITISH"
|
||||
fi
|
||||
|
||||
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 -f "$HOME/.android/onionwire-release.jks" "$HOME/.android/onionwire-release.env" "$HOME/onionwire-release.jks"
|
||||
echo "keystore removed from runner home"
|
||||
Loading…
Reference in a new issue