From ecbda604e20db111f729ad34604b8b41dfd70b1c Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Fri, 4 Dec 2026 08:56:53 -0500 Subject: [PATCH] ci: save the Robolectric jar cache from main only (#3604) A pull request's cache entry is visible only to that pull request, so each PR stored its own ~830 MB copy that no other PR could restore, while new PRs started from main's incomplete set and downloaded the rest from Maven Central, where the 429s come from. The copies also kept the repository at its 10 GB cache limit and pushed out other caches. --- .github/workflows/unit-tests.yml | 4 +++- tools/tests/test_ci_checks.py | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index a2ef6cfe8e..663bd30e6a 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -178,8 +178,10 @@ jobs: PY after=$(find "$GITHUB_WORKSPACE/../robolectric-jars" -name '*.jar' | wc -l) [ "$after" -gt "${ROBOLECTRIC_JARS_BEFORE:-0}" ] && echo "save=true" >> "$GITHUB_OUTPUT" || true + # A pull request's cache is visible only to that pull request, and each copy is hundreds of megabytes against the + # repository's 10 GB cache limit. Only main saves, so every pull request restores main's set. - name: Store Robolectric's Android jars - if: always() && steps.robolectric-jars-final.outputs.save == 'true' + if: always() && github.event_name != 'pull_request' && steps.robolectric-jars-final.outputs.save == 'true' uses: actions/cache/save@v4 with: path: ${{ steps.robolectric-jars.outputs.path }} diff --git a/tools/tests/test_ci_checks.py b/tools/tests/test_ci_checks.py index 8e3b7e9880..1e7995a3d2 100644 --- a/tools/tests/test_ci_checks.py +++ b/tools/tests/test_ci_checks.py @@ -33,6 +33,13 @@ class CiChecksTest(unittest.TestCase): robolectric = [cache['path'] for cache in caches if cache['key'].startswith('robolectric-')] self.assertEqual(robolectric, ['${{ steps.robolectric-jars.outputs.path }}'] * 2) + def test_only_main_saves_the_robolectric_cache(self): + steps = yaml.safe_load((ROOT / '.github/workflows/unit-tests.yml').read_text())['jobs']['unit-tests']['steps'] + saves = [step for step in steps if step.get('uses', '').startswith('actions/cache/save') + and step['with']['key'].startswith('robolectric-')] + self.assertEqual(len(saves), 1) + self.assertIn("github.event_name != 'pull_request'", saves[0]['if']) + def test_unit_test_retry_requires_maven_exception(self): steps = yaml.safe_load((ROOT / '.github/workflows/unit-tests.yml').read_text())['jobs']['unit-tests']['steps'] run = next(step['run'] for step in steps if step.get('id') == 'unit-tests')