From b3dfc8b8d8443a88ee458f9e3b5324332842ca85 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Wed, 2 Dec 2026 18:45:12 -0500 Subject: [PATCH] ci: save the Robolectric jar cache from main only 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 a525311b34..f178688d99 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -160,8 +160,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 5b45850fc8..c4aaa2ad1f 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')