From 515afb642cf36c6825fbc4596d1715bd244f4c82 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Sun, 11 Oct 2026 22:32:46 +0200 Subject: [PATCH] ci(tests): cache the Robolectric Android SDK jars Robolectric does not take its `android-all` jars through Gradle. It fetches them itself from Maven Central the first time a test needs a given SDK level, so every unit test run depends on a TLS handshake to a remote repository that nothing caches: `setup-gradle` covers `~/.gradle`, while Robolectric writes to `~/.m2/repository/org/robolectric`. When that handshake fails the whole suite dies in `initializationError` before a single assertion runs, which reads like a broken pull request rather than the infrastructure hiccup it is. Cache the directory Robolectric downloads into, keyed on the Robolectric version so that an upgrade fetches the new jars once and caches those instead of serving stale ones. Restore and save are separate steps because `actions/cache` only saves on a green job, and the runs worth caching are precisely the ones where a download succeeded but a later test failed. Assisted-by: Claude Code:claude-opus-5 Signed-off-by: Andy Scherzinger --- .github/workflows/unit-tests.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 2151c5caa3..1cac07a147 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -36,9 +36,28 @@ jobs: - name: Setup Gradle uses: gradle/actions/setup-gradle@3f5f9adaf7d9fecd50b5935e54106014257a94e6 # v6.4.0 + - name: Read the Robolectric version + id: robolectric + run: echo "version=$(grep -oP 'org\.robolectric:robolectric:\K[0-9.]+' app/build.gradle.kts)" >> "$GITHUB_OUTPUT" + + - name: Restore the Robolectric Android SDK jars + id: robolectric-cache + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ~/.m2/repository/org/robolectric + key: robolectric-sdks-${{ runner.os }}-${{ steps.robolectric.outputs.version }} + - name: Run unit tests with coverage run: ./gradlew --no-daemon testGplayDebugUnit + # Saved even when the suite fails, so a red run still leaves the jars behind. + - name: Save the Robolectric Android SDK jars + if: ${{ always() && steps.robolectric-cache.outputs.cache-hit != 'true' }} + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ~/.m2/repository/org/robolectric + key: robolectric-sdks-${{ runner.os }}-${{ steps.robolectric.outputs.version }} + - name: Upload test artifacts if: ${{ failure() }} uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2