From 90544b57252611acc3969858890d9ada4b696757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Santos?= Date: Fri, 26 Jul 2024 14:05:35 +0100 Subject: [PATCH] Cache AVD to improve instrumented tests time (#786) ## Proposed Changes - Apply cache suggestions from https://github.com/ReactiveCircus/android-emulator-runner to improve the instrumented tests time. It's currently taking 9-10 minutes. - Added more `setup-gradle` steps to further use gradle cache too. Those need to be merged to `master` to work. --- .github/workflows/validate.yml | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 94e8a6b54..eff9318d2 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -36,6 +36,9 @@ jobs: - name: checkout uses: actions/checkout@v4 + - name: Gradle cache + uses: gradle/actions/setup-gradle@v3 + - name: Build `StableFullRelease` and `StableFdroidRelease` variants run: ./gradlew build${{ matrix.version }} && ./gradlew clean @@ -54,6 +57,9 @@ jobs: - name: checkout uses: actions/checkout@v4 + - name: Gradle cache + uses: gradle/actions/setup-gradle@v3 + - name: Run unit tests run: ./gradlew testOoniStableFullRelease @@ -90,6 +96,32 @@ jobs: sudo udevadm control --reload-rules sudo udevadm trigger --name-match=kvm + - name: Gradle cache + uses: gradle/actions/setup-gradle@v3 + + - name: AVD cache + uses: actions/cache@v4 + id: avd-cache + with: + path: | + ~/.android/avd/* + ~/.android/adb* + key: avd-${{ matrix.api-level }}-${{ matrix.target }} + + - name: create AVD and generate snapshot for caching + if: steps.avd-cache.outputs.cache-hit != 'true' + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: ${{ matrix.api-level }} + target: ${{ matrix.target }} + arch: x86_64 + profile: Nexus 6 + ram-size: 4096M + force-avd-creation: false + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none + disable-animations: false + script: echo "Generated AVD snapshot for caching." + - name: Run instrumented tests uses: reactivecircus/android-emulator-runner@v2 with: @@ -98,6 +130,9 @@ jobs: arch: x86_64 profile: Nexus 6 ram-size: 4096M + force-avd-creation: false + emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none + disable-animations: true script: ./gradlew connectedOoniStableFullDebugAndroidTest - name: uploads test reports @@ -153,6 +188,9 @@ jobs: java-version: '17' distribution: 'temurin' + - name: Gradle cache + uses: gradle/actions/setup-gradle@v3 + - name: Assemble APKs if: success() && steps.get_issue_number.outputs.result run: ./gradlew assemble${{ matrix.version }}