.github/workflows: cache droidctl #54
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: Test nix-on-droid in an emulator | |
on: | |
pull_request: | |
push: | |
schedule: | |
- cron: 0 0 * * 1 | |
jobs: | |
emulate: | |
runs-on: ubuntu-latest | |
timeout-minutes: 30 | |
strategy: | |
fail-fast: false | |
matrix: | |
api-level: [29] | |
# below 28: didn't start, IDK why | |
# 34: sometimes work, but doesn't seem stable, even w/o caching images | |
way: | |
- bootstrap_flakes | |
- bootstrap_channels | |
- poke_around | |
- test_channels_uiautomator | |
- test_channels_shell | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install Nix / enable KVM | |
uses: DeterminateSystems/nix-installer-action@main | |
- name: Setup cachix | |
uses: cachix/cachix-action@v14 | |
with: | |
name: nix-on-droid | |
signingKey: "${{ secrets.CACHIX_SIGNING_KEY }}" | |
- name: Configure droidctl evaluation cache | |
uses: actions/cache@v4 | |
id: droidctl-cache | |
with: | |
path: /tmp/droidctl | |
key: avd-${{ matrix.api-level }}-${{ matrix.way}} # concurrent save | |
- name: Build droidctl (anew and push to cachix) | |
if: steps.droidctl-cache.outputs.cache-hit != 'true' | |
run: | | |
nix build 'github:t184256/droidctl' --out-link /tmp/droidctl | |
realpath /tmp/droidctl | cachix push nix-on-droid | |
- name: Fetch droidctl (from cachix using cached eval) | |
if: steps.droidctl-cache.outputs.cache-hit == 'true' | |
run: nix build /tmp/droidctl | |
- name: Build zipball, channel tarball and flake to inject | |
run: | | |
rm -rf n-o-d | |
mkdir -p n-o-d | |
git -C . archive --format=tar.gz --prefix n-o-d/ HEAD > n-o-d/archive.tar.gz | |
ARCHES=x86_64 nix run '.#deploy' -- file:///data/local/tmp/n-o-d/archive.tar.gz n-o-d/ | |
- name: Gradle cache | |
uses: gradle/actions/setup-gradle@v3 | |
- name: Configure AVD cache | |
if: matrix.api-level == 29 | |
uses: actions/cache@v4 | |
id: avd-cache | |
with: | |
path: | | |
~/.android/avd/* | |
~/.android/adb* | |
/usr/local/lib/android/sdk | |
key: avd-${{ matrix.api-level }}-${{ matrix.way}} # concurrent save | |
- name: Create AVD and generate snapshot for caching | |
if: matrix.api-level == 29 && steps.avd-cache.outputs.cache-hit != 'true' | |
uses: reactivecircus/android-emulator-runner@v2 | |
with: | |
target: default | |
arch: x86_64 | |
api-level: ${{ matrix.api-level }} | |
force-avd-creation: false | |
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none | |
disable-animations: false | |
script: echo "Generated AVD snapshot for caching." | |
- name: Test way=${{ matrix.way}} api-level=${{ matrix.api-level }} | |
uses: reactivecircus/android-emulator-runner@v2 | |
with: | |
target: default | |
arch: x86_64 | |
api-level: ${{ matrix.api-level }} | |
force-avd-creation: false | |
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none | |
disable-animations: true | |
# https://github.com/ReactiveCircus/android-emulator-runner/issues/385 | |
script: > | |
trap 'pkill --exact --echo --signal SIGKILL crashpad_handle || true' EXIT && | |
adb shell 'rm -rf /data/local/tmp/n-o-d' && | |
adb push n-o-d /data/local/tmp/ && | |
echo 'pushed' && | |
adb shell 'cd /data/local/tmp/n-o-d && tar xzof archive.tar.gz && mv n-o-d unpacked' && | |
echo 'unpacked' && | |
cd tests/emulator && | |
adb shell settings put secure enabled_accessibility_services com.google.android.marvin.talkback/com.google.android.marvin.talkback.TalkBackService && | |
echo 'ready' && | |
/tmp/droidctl/bin/droidctl run ${{ matrix.way }}.py | |
# TODO: push to cachix from within the emulator | |
- name: Upload screenshots | |
if: always() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: screenshots-${{ matrix.way }}-${{ matrix.api-level }} | |
path: tests/emulator/screenshots | |
if-no-files-found: warn # 'error' or 'ignore' are also available |