11name : Android Emulator Tests
2- on : [push, pull_request]
2+ on : [ push, pull_request ]
33
44jobs :
55 check-if-tests-exist :
66 runs-on : ubuntu-latest
77 outputs :
88 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 }}
912 steps :
1013 - name : Checkout
1114 uses : actions/checkout@v3
@@ -16,36 +19,81 @@ jobs:
1619 echo "NOT_EMPTY=$([ "$(ls -A BackupAPI/src/androidTest)" ] && echo 'true' || echo 'false')"
1720 echo "NOT_EMPTY=$([ "$(ls -A BackupAPI/src/androidTest)" ] && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
1821 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 BackupAPI/build.gradle | grep minSdkVersion | rev | cut -d' ' -f 1 | rev)" >> $GITHUB_OUTPUT
27+ echo "TARGET_SDK_VERSION=$(cat BackupAPI/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 BackupAPI/build.gradle | grep applicationId | rev | cut -d' ' -f 1 | rev | tr -d '"')" >> $GITHUB_OUTPUT
32+
1933 test :
2034 needs : check-if-tests-exist
2135 if : needs.check-if-tests-exist.outputs.status == 'true'
22- runs-on : macos -latest
36+ runs-on : ubuntu -latest
2337 strategy :
2438 matrix :
25- api-level : [29]
26- target : [default]
27- arch : [x86_64]
39+ api-level : [34, "${{ needs.check-if-tests-exist.outputs.min-sdk-version }}", "${{ needs.check-if-tests-exist.outputs.target-sdk-version }}"]
2840 steps :
2941 - name : Checkout
3042 uses : actions/checkout@v3
3143 with :
32- submodules : " recursive"
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 }}
3363
3464 - name : Set up JDK environment
3565 uses : actions/setup-java@v3
3666 with :
37- distribution : " zulu"
67+ distribution : ' zulu'
3868 java-version : 17
3969
40- - name : Gradle cache
41- uses : gradle/gradle-build-action@v2
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."
4281
4382 - name : Run connected tests
4483 uses : ReactiveCircus/android-emulator-runner@v2
4584 with :
4685 api-level : ${{ matrix.api-level }}
47- target : ${{ matrix.target }}
48- arch : ${{ matrix.arch }}
49- profile : Nexus 6
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
5090 disable-animations : true
51- script : bash ./gradlew :BackupAPI:connectedCheck --stacktrace
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 :BackupAPI: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