|
| 1 | +name: Android Emulator Tests |
| 2 | +on: |
| 3 | + workflow_run: |
| 4 | + workflows: ["Android CI"] |
| 5 | + types: |
| 6 | + - completed |
| 7 | + branches: |
| 8 | + - main |
| 9 | + workflow_dispatch: {} |
| 10 | + |
| 11 | +jobs: |
| 12 | + test: |
| 13 | + if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }} |
| 14 | + runs-on: ubuntu-latest |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + api-level: [29, 31, 35] |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + - uses: ./.github/actions/common-setup |
| 22 | + - name: Enable KVM |
| 23 | + run: | |
| 24 | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules |
| 25 | + sudo udevadm control --reload-rules |
| 26 | + sudo udevadm trigger --name-match=kvm |
| 27 | + - name: Gradle cache |
| 28 | + uses: gradle/actions/setup-gradle@v4 |
| 29 | + - name: AVD cache |
| 30 | + uses: actions/cache@v4 |
| 31 | + id: avd-cache |
| 32 | + with: |
| 33 | + path: | |
| 34 | + ~/.android/avd/* |
| 35 | + ~/.android/adb* |
| 36 | + key: avd-${{ matrix.api-level }} |
| 37 | + - name: Create AVD and generate snapshot for caching |
| 38 | + if: steps.avd-cache.outputs.cache-hit != 'true' |
| 39 | + uses: reactivecircus/android-emulator-runner@v2 |
| 40 | + with: |
| 41 | + api-level: ${{ matrix.api-level }} |
| 42 | + arch: x86_64 |
| 43 | + force-avd-creation: false |
| 44 | + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none |
| 45 | + disable-animations: true |
| 46 | + script: echo "Generated AVD snapshot for caching." |
| 47 | + - name: Run instrumented tests |
| 48 | + uses: reactivecircus/android-emulator-runner@v2 |
| 49 | + with: |
| 50 | + api-level: ${{ matrix.api-level }} |
| 51 | + arch: x86_64 |
| 52 | + force-avd-creation: false |
| 53 | + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none |
| 54 | + disable-animations: true |
| 55 | + script: ./gradlew connectedDebugAndroidTest |
| 56 | + - name: Upload test results |
| 57 | + uses: actions/upload-artifact@v4 |
| 58 | + if: always() |
| 59 | + with: |
| 60 | + name: test-results-${{ matrix.api-level }} |
| 61 | + path: app/build/reports/androidTests |
| 62 | + - name: Publish test results |
| 63 | + uses: mikepenz/action-junit-report@v5 |
| 64 | + if: always() |
| 65 | + with: |
| 66 | + report_paths: 'app/build/outputs/androidTest-results/connected/**/*.xml' |
0 commit comments