|
| 1 | +name: Android Emulator Tests |
| 2 | +on: [ push, pull_request ] |
| 3 | + |
| 4 | +jobs: |
| 5 | + check-if-tests-exist: |
| 6 | + runs-on: ubuntu-latest |
| 7 | + outputs: |
| 8 | + status: ${{ steps.check-androidTest.outputs.NOT_EMPTY }} |
| 9 | + min-sdk-version: ${{ steps.get-sdk-version.outputs.MIN_SDK_VERSION }} |
| 10 | + target-sdk-version: ${{ steps.get-sdk-version.outputs.TARGET_SDK_VERSION }} |
| 11 | + app-id: ${{ steps.get-app-id.outputs.APP_ID }} |
| 12 | + steps: |
| 13 | + - name: Checkout |
| 14 | + uses: actions/checkout@v3 |
| 15 | + with: |
| 16 | + submodules: "recursive" |
| 17 | + - name: Check if androidTest folder is not empty |
| 18 | + run: | |
| 19 | + echo "NOT_EMPTY=$([ "$(ls -A app/src/androidTest)" ] && echo 'true' || echo 'false')" |
| 20 | + echo "NOT_EMPTY=$([ "$(ls -A app/src/androidTest)" ] && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT |
| 21 | + id: check-androidTest |
| 22 | + - name: Get min and target sdk |
| 23 | + if: steps.check-androidTest.outputs.NOT_EMPTY == 'true' |
| 24 | + id: get-sdk-version |
| 25 | + run: | |
| 26 | + echo "MIN_SDK_VERSION=$(cat app/build.gradle | grep minSdkVersion | rev | cut -d' ' -f 1 | rev)" >> $GITHUB_OUTPUT |
| 27 | + echo "TARGET_SDK_VERSION=$(cat app/build.gradle | grep targetSdkVersion | rev | cut -d' ' -f 1 | rev)" >> $GITHUB_OUTPUT |
| 28 | + - name: Get app ID |
| 29 | + id: get-app-id |
| 30 | + run: | |
| 31 | + echo "APP_ID=$(cat app/build.gradle | grep applicationId | rev | cut -d' ' -f 1 | rev | tr -d '"')" >> $GITHUB_OUTPUT |
| 32 | + |
| 33 | + test: |
| 34 | + needs: check-if-tests-exist |
| 35 | + if: needs.check-if-tests-exist.outputs.status == 'true' |
| 36 | + runs-on: ubuntu-latest |
| 37 | + strategy: |
| 38 | + matrix: |
| 39 | + api-level: [34, "${{ needs.check-if-tests-exist.outputs.min-sdk-version }}", "${{ needs.check-if-tests-exist.outputs.target-sdk-version }}"] |
| 40 | + steps: |
| 41 | + - name: Checkout |
| 42 | + uses: actions/checkout@v3 |
| 43 | + with: |
| 44 | + submodules: 'recursive' |
| 45 | + |
| 46 | + - name: Enable KVM group perms |
| 47 | + run: | |
| 48 | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules |
| 49 | + sudo udevadm control --reload-rules |
| 50 | + sudo udevadm trigger --name-match=kvm |
| 51 | +
|
| 52 | + - name: Gradle cache |
| 53 | + uses: gradle/gradle-build-action@v3 |
| 54 | + |
| 55 | + - name: AVD cache |
| 56 | + uses: actions/cache@v4 |
| 57 | + id: avd-cache |
| 58 | + with: |
| 59 | + path: | |
| 60 | + ~/.android/avd/* |
| 61 | + ~/.android/adb* |
| 62 | + key: avd-${{ matrix.api-level }} |
| 63 | + |
| 64 | + - name: Set up JDK environment |
| 65 | + uses: actions/setup-java@v3 |
| 66 | + with: |
| 67 | + distribution: 'zulu' |
| 68 | + java-version: 17 |
| 69 | + |
| 70 | + - name: create AVD and generate snapshot for caching |
| 71 | + if: steps.avd-cache.outputs.cache-hit != 'true' |
| 72 | + uses: reactivecircus/android-emulator-runner@v2 |
| 73 | + with: |
| 74 | + api-level: ${{ matrix.api-level }} |
| 75 | + target: ${{ matrix.api-level >= 30 && 'google_apis' || 'default' }} |
| 76 | + arch: ${{ matrix.api-level < 21 && 'x86' || 'x86_64' }} |
| 77 | + force-avd-creation: false |
| 78 | + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none |
| 79 | + disable-animations: false |
| 80 | + script: echo "Generated AVD snapshot for caching." |
| 81 | + |
| 82 | + - name: Run connected tests |
| 83 | + uses: ReactiveCircus/android-emulator-runner@v2 |
| 84 | + with: |
| 85 | + api-level: ${{ matrix.api-level }} |
| 86 | + target: ${{ matrix.api-level >= 30 && 'google_apis' || 'default' }} |
| 87 | + arch: ${{ matrix.api-level < 21 && 'x86' || 'x86_64' }} |
| 88 | + force-avd-creation: false |
| 89 | + emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none |
| 90 | + disable-animations: true |
| 91 | + script: | |
| 92 | + adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}} || true |
| 93 | + adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}}.test || true |
| 94 | + adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}}.androidTest || true |
| 95 | + chmod +x gradlew |
| 96 | + ./gradlew :app:connectedCheck --stacktrace |
| 97 | + adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}} || true |
| 98 | + adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}}.test || true |
| 99 | + adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}}.androidTest || true |
0 commit comments