Skip to content

Commit

Permalink
chore: move avd creation/run into separate action
Browse files Browse the repository at this point in the history
  • Loading branch information
CAMOBAP committed May 19, 2024
1 parent 134ec3f commit d21b1b8
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 123 deletions.
67 changes: 67 additions & 0 deletions .github/actions/android-emulator-run/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: android-emulator-run
description: Do run script after emulator boot (use cached AVD or create a new one)

inputs:
script:
description: Script to run after emulator booted
required: true
arch:
description: Emulator arch, supported values depends on runner
required: true
default: x86_64
target:
description: Emulator target. Supported `default` or `google_apis` values
required: true
default: default
profile:
description: Emulator profile
required: true
default: Nexus 6
api-level:
description: Emulator API level
required: true
default: '28'
boot-options:
description: Emulator boot options
required: true
default: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none

runs:
using: "composite"
steps:
- name: Cache AVD
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-api-${{ inputs.api-level }}-target-${{ inputs.target }}
- name: Enable KVM group perms
shell: bash
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'
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
arch: ${{ inputs.arch }}
target: ${{ inputs.target }}
profile: ${{ inputs.profile }}
api-level: ${{ inputs.api-level }}
emulator-options: ${{ inputs.boot-options }}
force-avd-creation: false
disable-animations: false
script: echo "Generated AVD snapshot for caching."
- uses: reactivecircus/android-emulator-runner@v2
with:
arch: ${{ inputs.arch }}
target: ${{ inputs.target }}
profile: ${{ inputs.profile }}
api-level: ${{ inputs.api-level }}
emulator-options: ${{ inputs.boot-options }}
force-avd-creation: false
disable-animations: true
script: ${{ inputs.script }}
131 changes: 8 additions & 123 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ on:

env:
JAVA_VERSION: '17'
AVD_ARCH: x86_64
AVD_OPTIONS: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
AVD_PROFILE: Nexus 6

jobs:
test:
Expand Down Expand Up @@ -83,11 +80,6 @@ jobs:
name: 'Test UI'
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
api-level: [28]
target: [default]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
Expand All @@ -97,43 +89,10 @@ jobs:
- uses: gradle/gradle-build-action@v3
with:
cache-read-only: false
- name: 'Cache AVD'
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-api-${{ matrix.api-level }}-target-${{ matrix.target }}
- 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 AVD'
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
- name: Run tests
uses: ./.github/actions/android-emulator-run
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.target }}
emulator-options: ${{ env.AVD_OPTIONS }}
force-avd-creation: false
disable-animations: false
arch: ${{ env.AVD_ARCH }}
profile: ${{ env.AVD_PROFILE }}
script: echo "Generated AVD snapshot for caching."
- name: 'Tests'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.target }}
emulator-options: ${{ env.AVD_OPTIONS }}
force-avd-creation: false
disable-animations: true
arch: ${{ env.AVD_ARCH }}
profile: ${{ env.AVD_PROFILE }}
script: |
parallel --retries 3 ::: "./gradlew test:connectedCheck"
script: "parallel --retries 3 ::: './gradlew test:connectedCheck'"
- if: failure()
uses: actions/upload-artifact@v4
with:
Expand All @@ -147,11 +106,6 @@ jobs:
needs: [ test-ui ]
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
api-level: [28]
target: [default]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
Expand All @@ -161,43 +115,10 @@ jobs:
- uses: gradle/gradle-build-action@v3
with:
cache-read-only: false
- name: 'Cache AVD'
uses: actions/cache@v4
id: avd-cache
- name: Run tests
uses: ./.github/actions/android-emulator-run
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-api-${{ matrix.api-level }}-target-${{ matrix.target }}
- 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 AVD'
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.target }}
emulator-options: ${{ env.AVD_OPTIONS }}
force-avd-creation: false
disable-animations: false
arch: ${{ env.AVD_ARCH }}
profile: ${{ env.AVD_PROFILE }}
script: echo "Generated AVD snapshot for caching."
- name: 'Tests'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.target }}
emulator-options: ${{ env.AVD_OPTIONS }}
force-avd-creation: false
disable-animations: true
arch: ${{ env.AVD_ARCH }}
profile: ${{ env.AVD_PROFILE }}
script: |
parallel --retries 3 ::: "./gradlew test:connectedCheck -P testingMinimizedBuild=true -P android.enableR8.fullMode=false"
script: "parallel --retries 3 ::: './gradlew test:connectedCheck -P testingMinimizedBuild=true -P android.enableR8.fullMode=false'"
- if: failure()
uses: actions/upload-artifact@v4
with:
Expand All @@ -210,11 +131,6 @@ jobs:
name: 'Test Benchmark'
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
api-level: [28]
target: [default]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
Expand All @@ -224,40 +140,9 @@ jobs:
- uses: gradle/gradle-build-action@v3
with:
cache-read-only: false
- name: 'Cache AVD'
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-api-${{ matrix.api-level }}-target-${{ matrix.target }}
- 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 AVD'
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.target }}
emulator-options: ${{ env.AVD_OPTIONS }}
force-avd-creation: false
disable-animations: false
arch: ${{ env.AVD_ARCH }}
profile: ${{ env.AVD_PROFILE }}
script: echo "Generated AVD snapshot for caching."
- uses: reactivecircus/android-emulator-runner@v2
- name: Run tests
uses: ./.github/actions/android-emulator-run
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.target }}
emulator-options: ${{ env.AVD_OPTIONS }}
force-avd-creation: false
disable-animations: true
arch: ${{ env.AVD_ARCH }}
profile: ${{ env.AVD_PROFILE }}
script: ./gradlew benchmark:connectedReleaseAndroidTest
- name: Diff benchmark result
id: diff-benchmark
Expand Down

0 comments on commit d21b1b8

Please sign in to comment.