From 3ec34606ccd69025f564d10da2d7e3893dd8b797 Mon Sep 17 00:00:00 2001 From: Brett Chabot Date: Thu, 25 Jan 2024 12:46:11 -0800 Subject: [PATCH] Cache Gradle Managed Devices emulator snapshot. It currently takes ~50 seconds on each CI run to boot the emulator and save a snapshot. This commit saves the snapshot to a github action cache, to save the cost of booting on each run. However, compressing and saving the snapshot to cache is also expensive (~30 seconds) so we don't want to do this for every run. Ideally there would be a precise mechanism for determining if the snapshot has changed. For now, just use a cache key encorporating the date and the hash of the top level build.gradle file, so the cache is generated every week. --- .github/workflows/ci.yml | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8c00526ab..587ee5a08 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ jobs: distribution: 'zulu' java-version: '17' - name: 'Cache Bazel files' - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.cache/bazel key: ${{ runner.os }}-${{ env.cache-version }}-bazel-build-${{ github.sha }} @@ -75,7 +75,7 @@ jobs: distribution: 'zulu' java-version: '17' - name: 'Cache Bazel files' - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.cache/bazel key: ${{ runner.os }}-${{ env.cache-version }}-bazel-test-${{ github.sha }} @@ -110,9 +110,31 @@ jobs: run: | echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules sudo udevadm control --reload-rules - sudo udevadm trigger --name-match=kvm + sudo udevadm trigger --name-match=kvm + - name: Set ANDROID_USER_HOME + run: echo "ANDROID_USER_HOME=$HOME/.android" >> $GITHUB_ENV - name: 'Cache Gradle files' uses: gradle/gradle-build-action@v2 + # Saving the GMD snapshot to cache is expensive + # Theoretically we only need to update the cache if the snapshot is changed, + # which should only happen if emulator version or system image has changed. + # As a workaround, encorporate the year and week to the cache key, so + # the snapshot cache gets regenerated every week + # http://man7.org/linux/man-pages/man1/date.1.html + - name: Get Date + id: get-date + run: | + echo "date=$(/bin/date -u "+%Y%U")" >> $GITHUB_OUTPUT + shell: bash + - name: 'Cache GMD snapshot' + uses: actions/cache@v4 + with: + path: | + ~/.android/avd/gradle-managed/* + ~/.android/adb* + # use combination of date (to cover case where emulator or system image version changed) and + # hash of top-level build.gradle (to cover case where AGP or android API level changed) + key: ${{ runner.os }}-${{ env.cache-version }}-gmd-${{ steps.get-date.outputs.date }}-${{ hashFiles('gradle-tests/build.gradle') }} - name: 'Download local snapshot for tests' uses: actions/download-artifact@v4 with: @@ -137,4 +159,3 @@ jobs: name: test-reports path: gradle-tests/**/build/reports/androidTests/ -