Skip to content

Commit

Permalink
.github/workflows: revamp for extra parallelism
Browse files Browse the repository at this point in the history
  • Loading branch information
t184256 committed Jun 16, 2024
1 parent 7882ff6 commit 6a5c608
Showing 1 changed file with 107 additions and 33 deletions.
140 changes: 107 additions & 33 deletions .github/workflows/emulator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,82 @@ on:
- cron: 0 0 * * 1

jobs:
emulate:

prepare-droidctl:
runs-on: ubuntu-latest
timeout-minutes: 30
timeout-minutes: 5
outputs:
path: ${{ steps.droidctl-build.outputs.path }}
steps:
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main
- name: Configure Nix magic cache
uses: DeterminateSystems/magic-nix-cache-action@main

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
- id: droidctl-build
name: Build droidctl
run: |
nix build 'github:t184256/droidctl' --out-link /tmp/droidctl
echo "path=$(realpath /tmp/droidctl)" >> "$GITHUB_OUTPUT"
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Nix / enable KVM
prepare-n-o-d:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main
- name: Configure Nix magic cache
uses: DeterminateSystems/magic-nix-cache-action@main

- name: Setup cachix
uses: cachix/cachix-action@v14
with:
name: nix-on-droid
signingKey: "${{ secrets.CACHIX_SIGNING_KEY }}"

- name: Build droidctl
run: nix build 'github:t184256/droidctl' --out-link droidctl
- name: Checkout repository
uses: actions/checkout@v4

- name: Build zipball, channel tarball and flake to inject
- id: injection-build
name: Build zipball and channel tarball to inject (n-o-d)
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: Store zipball and channel tarball to inject (n-o-d)
uses: actions/upload-artifact@v4
with:
name: n-o-d
path: n-o-d


prepare-avd:
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
fail-fast: false
matrix:
api-level: [29] # keep in sync
steps:
- name: Configure AVD cache
if: matrix.api-level == 29
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ matrix.api-level }}-${{ matrix.way }} # concurrent save
key: avd-${{ matrix.api-level }}

- name: Enable KVM
if: matrix.api-level == 29 && steps.avd-cache.outputs.cache-hit != 'true'
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 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:
# ! Keep in sync with the other one,
# ! but w/o -no-snapshot-save and with disable-animations: false
target: default
arch: x86_64
api-level: ${{ matrix.api-level }}
Expand All @@ -68,7 +90,58 @@ jobs:
disable-animations: false
script: echo "Generated AVD snapshot for caching."

- name: Test way=${{ matrix.way}} api-level=${{ matrix.api-level }}

emulate:
needs:
- prepare-droidctl
- prepare-n-o-d
- prepare-avd
runs-on: ubuntu-latest
timeout-minutes: 30

strategy:
fail-fast: false
matrix:
api-level: [29] # keep in sync
# below 28: bootstrap didn't start, IDK why
# 34: sometimes work, but doesn't seem stable, even w/o caching images
script:
- bootstrap_flakes
- bootstrap_channels
- poke_around
- test_channels_uiautomator
- test_channels_shell

steps:
- name: Install Nix / enable KVM
uses: DeterminateSystems/nix-installer-action@main
- name: Configure Nix magic cache
uses: DeterminateSystems/magic-nix-cache-action@main

- name: Fetch droidctl (using previous eval)
env:
DROIDCTL: ${{needs.prepare-droidctl.outputs.path}}
run: nix build "$DROIDCTL" --out-path /tmp/droidctl

- name: Checkout repository
uses: actions/checkout@v4

- name: Retrieve zipball and channel tarball to inject (n-o-d)
uses: actions/download-artifact@v4
with:
name: n-o-d

- name: Configure AVD cache
if: matrix.api-level == 29 # tested, robust with kill workaround
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ matrix.api-level }}

- name: Test script=${{ matrix.script }} api-level=${{ matrix.api-level }}
uses: reactivecircus/android-emulator-runner@v2
with:
target: default
Expand All @@ -88,13 +161,14 @@ jobs:
cd tests/emulator &&
adb shell settings put secure enabled_accessibility_services com.google.android.marvin.talkback/com.google.android.marvin.talkback.TalkBackService &&
echo 'ready' &&
nix run 'github:t184256/droidctl' -- run ${{ matrix.way }}.py
# TODO: push to cachix from within the emulator
/tmp/droidctl/bin/droidctl run ${{ matrix.script }}.py
# TODO: push to cachix from within the emulator?
# would be of use on aarch64, not x86_64
- name: Upload screenshots
if: always()
uses: actions/upload-artifact@v4
with:
name: screenshots-${{ matrix.way }}-${{ matrix.api-level }}
name: screenshots-${{ matrix.script }}-${{ matrix.api-level }}
path: tests/emulator/screenshots
if-no-files-found: warn # 'error' or 'ignore' are also available

0 comments on commit 6a5c608

Please sign in to comment.