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')