Skip to content

Commit

Permalink
Cache Gradle Managed Devices emulator snapshot.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brettchabot committed Jan 25, 2024
1 parent 36b7f78 commit 3ec3460
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions .github/workflows/ci.yml
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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:
Expand All @@ -137,4 +159,3 @@ jobs:
name: test-reports
path: gradle-tests/**/build/reports/androidTests/


0 comments on commit 3ec3460

Please sign in to comment.