chore(.github): add android workflow #20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | ||
on: [push, pull_request] | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
env: | ||
ANDROID_SDK_ROOT: ${{ github.workspace }}/android-sdk | ||
ANDROID_NDK_HOME: ${{ github.workspace }}/android-ndk | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Set up JDK | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'zulu' | ||
java-version: '11' | ||
- name: Set up Android SDK | ||
uses: android-actions/setup-android@v2 | ||
with: | ||
api-level: 30 | ||
build-tools: 30.0.3 | ||
- name: Install NDK | ||
run: sdkmanager --install "ndk;25.2.9519653" | ||
- name: Export ANDROID_NDK_HOME | ||
run: echo "ANDROID_NDK_HOME=$ANDROID_HOME/ndk/25.2.9519653" >> $GITHUB_ENV | ||
- name: Verify ANDROID_NDK_HOME | ||
run: echo $ANDROID_NDK_HOME | ||
- name: Install Rust | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: stable | ||
override: true | ||
components: rustfmt, clippy | ||
- name: Add Android targets | ||
run: rustup target add aarch64-linux-android | ||
- name: Install cargo-ndk | ||
run: cargo install cargo-ndk | ||
- name: Build unit tests for Android | ||
env: | ||
ANDROID_NDK_HOME: ${{ github.workspace }}/android-sdk/ndk/25.2.9519653 | ||
run: cargo ndk -t aarch64-linux-android test --no-run | ||
- name: Enable KVM group perms | ||
run: | | ||
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules | ||
sudo udevadm control --reload-rules | ||
sudo udevadm trigger --name-match=kvm | ||
- name: Create emulator script | ||
run: | | ||
echo '#!/bin/bash | ||
adb wait-for-device | ||
boot_completed=false | ||
retries=0 | ||
max_retries=10 | ||
while [ "$boot_completed" != "1" ] && [ $retries -lt $max_retries ]; do | ||
echo "Waiting for emulator to boot... ($((retries+1))/$max_retries)" | ||
boot_completed=$(adb -s emulator-5554 shell getprop sys.boot_completed 2>/dev/null | tr -d "\r") | ||
if [ "$boot_completed" != "1" ]; then | ||
sleep 10 | ||
fi | ||
retries=$((retries+1)) | ||
done | ||
if [ "$boot_completed" != "1" ]; then | ||
echo "Emulator failed to boot within expected time." | ||
exit 1 | ||
fi | ||
echo "Emulator is ready." | ||
for test in $(find target/aarch64-linux-android/debug/deps/ -type f -executable -name "*-*"); do | ||
adb push "$test" /data/local/tmp/ | ||
adb shell chmod +x /data/local/tmp/$(basename "$test") | ||
adb shell /data/local/tmp/$(basename "$test") | ||
done' > run_tests_on_emulator.sh | ||
run: chmod +x run_tests_on_emulator.sh | ||
- name: Set up Android Emulator and run tests | ||
uses: reactivecircus/android-emulator-runner@v2 | ||
with: | ||
api-level: 30 | ||
target: default | ||
arch: x86_64 | ||
profile: Nexus 6 | ||
emulator-options: "-no-window -no-audio" | ||
avd-name: test | ||
force-avd-creation: true | ||
emulator-boot-timeout: 600 | ||
script: ./run_tests_on_emulator.sh |