Skip to content

Commit

Permalink
reusable workflow for android tests
Browse files Browse the repository at this point in the history
  • Loading branch information
whyoleg committed Jul 25, 2023
1 parent 4c18454 commit 3db90db
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 19 deletions.
66 changes: 66 additions & 0 deletions .github/actions/run-android-emulator-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: "Run Android emulator tests"
description: "Setups android emulator caching and running"
inputs:
api-level:
description: Android API level for testing
required: true
cache-disabled:
description: When 'true', all caching is disabled. No entries will be written to or read from the cache.
required: false
default: false
cache-read-only:
description: |
When 'true', existing entries will be read from the cache but no entries will be written.
By default this value is 'false' for workflows on the `dev` branch and 'true' for workflows on other branches.
required: false
default: ${{ github.ref_name != 'dev' }}
additional-arguments:
description: Additional arguments for running connectedCheck
required: false
default: ''
runs:
using: "composite"
steps:
- name: Build tests
uses: gradle/gradle-build-action@v2
with:
arguments: packageDebugAndroidTest --continue --configuration-cache
cache-disabled: ${{ inputs.cache-disabled }}
cache-read-only: ${{ inputs.cache-read-only }}

#TODO: make AVD cache respect disabled and read-only (https://github.com/actions/cache/blob/main/save/README.md)
- name: AVD cache
uses: actions/cache@v3
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ inputs.api-level }}

- name: Create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
arch: x86_64
api-level: ${{ inputs.api-level }}
script: echo "Generated AVD snapshot for caching."

- name: Run tests
uses: reactivecircus/android-emulator-runner@v2
with:
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -no-snapshot-save
arch: x86_64
api-level: ${{ inputs.api-level }}
script: ./gradlew connectedCheck --continue --configuration-cache ${{ inputs.additional-arguments }}

# Android test failures are not available in gradle build scans
- name: Upload test reports
if: success() || failure()
uses: actions/upload-artifact@v3
with:
name: test-reports-${{ inputs.api-level }}
path: '**/build/reports/androidTests'
20 changes: 1 addition & 19 deletions .github/workflows/build-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,6 @@ jobs:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-gradle

- name: Build tests
uses: gradle/gradle-build-action@v2
with:
arguments: |
packageDebugAndroidTest
--continue
--configuration-cache
- name: Run tests
uses: reactivecircus/android-emulator-runner@v2
- uses: ./.github/actions/run-android-emulator-tests
with:
api-level: ${{ matrix.api-level }}
arch: x86_64
script: ./gradlew connectedCheck --continue --configuration-cache

- name: Upload test reports
if: success() || failure()
uses: actions/upload-artifact@v3
with:
name: test-reports
path: '**/build/reports/androidTests'

0 comments on commit 3db90db

Please sign in to comment.