Files
Ferrous-Solitaire/.gitea/workflows/android-build.yml
T
funman300 01d6b27e61
Android Build / build-apk (push) Failing after 3m50s
Build and Deploy / build-and-push (push) Failing after 33s
fix(ci): detect existing container SDK before installing, set ANDROID_HOME via GITHUB_ENV
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 10:53:14 -07:00

138 lines
5.5 KiB
YAML

name: Android Build
on:
push:
branches: [master]
# Rebuild whenever app/engine/asset code changes.
# Skip server-only, deploy, and doc changes.
paths-ignore:
- 'deploy/**'
- 'argocd/**'
- 'solitaire_server/**'
- '**.md'
env:
NDK_VERSION: "25.2.9519653"
BUILD_TOOLS_VERSION: "34.0.0"
jobs:
build-apk:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set short SHA
id: meta
run: echo "sha=${GITHUB_SHA::8}" >> "$GITHUB_OUTPUT"
# ── Probe the container's existing Android SDK ─────────────────────
- name: Detect Android SDK
id: sdk
run: |
# Gitea/GitHub ubuntu-latest runners may already have an Android
# SDK at /usr/local/lib/android/sdk. If it has the platform and
# NDK we need we use it directly; otherwise we install our own.
DEFAULT="${ANDROID_HOME:-/usr/local/lib/android/sdk}"
echo "container default ANDROID_HOME: $DEFAULT"
echo "sdk_path=$DEFAULT" >> "$GITHUB_OUTPUT"
ls "$DEFAULT/platforms/" 2>/dev/null || echo "(no platforms/ in default)"
ls "$DEFAULT/ndk/" 2>/dev/null || echo "(no ndk/ in default)"
# ── System dependencies (always needed for build tools + signing) ──
- name: Install system dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y openjdk-17-jdk-headless unzip jq
# ── Install missing SDK components if needed ───────────────────────
- name: Install SDK platform and NDK
env:
ANDROID_SDK: ${{ steps.sdk.outputs.sdk_path }}
run: |
# Ensure sdkmanager is on PATH
SDKMAN="$ANDROID_SDK/cmdline-tools/latest/bin/sdkmanager"
if [ ! -f "$SDKMAN" ]; then
echo "sdkmanager not found — installing cmdline-tools"
mkdir -p "$ANDROID_SDK/cmdline-tools"
curl -sL \
"https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip" \
-o /tmp/cmdtools.zip
unzip -q /tmp/cmdtools.zip -d /tmp/cmdtools
sudo mv /tmp/cmdtools/cmdline-tools "$ANDROID_SDK/cmdline-tools/latest"
fi
yes | sudo "$SDKMAN" --sdk_root="$ANDROID_SDK" --licenses \
> /dev/null 2>&1 || true
NEEDS=""
[ ! -f "$ANDROID_SDK/platforms/android-34/android.jar" ] && NEEDS="$NEEDS platforms;android-34"
[ ! -d "$ANDROID_SDK/ndk/$NDK_VERSION" ] && NEEDS="$NEEDS ndk;$NDK_VERSION"
[ ! -d "$ANDROID_SDK/build-tools/$BUILD_TOOLS_VERSION" ] && NEEDS="$NEEDS build-tools;$BUILD_TOOLS_VERSION"
if [ -n "$NEEDS" ]; then
echo "Installing:$NEEDS"
sudo "$SDKMAN" --sdk_root="$ANDROID_SDK" $NEEDS
else
echo "All SDK components already present"
fi
echo "ANDROID_HOME=$ANDROID_SDK" >> "$GITHUB_ENV"
echo "ANDROID_NDK_HOME=$ANDROID_SDK/ndk/$NDK_VERSION" >> "$GITHUB_ENV"
# ── Rust toolchain ─────────────────────────────────────────────────
- name: Install Rust stable
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
| sh -s -- -y --default-toolchain stable --no-modify-path
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
- name: Add Android cross-compilation targets
run: |
rustup target add \
aarch64-linux-android \
armv7-linux-androideabi \
x86_64-linux-android
# ── Cargo caches ───────────────────────────────────────────────────
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
key: cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: cargo-registry-
- name: Cache cargo-apk binary
uses: actions/cache@v4
id: apk-tool-cache
with:
path: ~/.cargo/bin/cargo-apk
key: cargo-apk-${{ runner.os }}-stable
- name: Cache build artifacts
uses: actions/cache@v4
with:
path: target
key: android-target-${{ hashFiles('**/Cargo.lock') }}-${{ github.sha }}
restore-keys: android-target-${{ hashFiles('**/Cargo.lock') }}-
# ── Build ──────────────────────────────────────────────────────────
- name: Install cargo-apk
if: steps.apk-tool-cache.outputs.cache-hit != 'true'
run: cargo install cargo-apk --locked
- name: Build debug APK
run: cargo apk build --package solitaire_app --lib
# ── Artifact ───────────────────────────────────────────────────────
- name: Upload APK
uses: actions/upload-artifact@v4
with:
name: solitaire-quest-debug-${{ steps.meta.outputs.sha }}
path: target/debug/apk/solitaire-quest.apk
retention-days: 30