From d164749a7fcf6d5c538284a43fc59395329a1e93 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Wed, 25 Nov 2026 13:33:28 -0500 Subject: [PATCH] fix(ci): save Robolectric's Android jars even when the test step fails on a Maven 429 (#3209) --- .github/workflows/build.yml | 39 ++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 43d90e5d17..9b32d1b442 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -754,12 +754,17 @@ jobs: ln -sfn "$(cd "$jars" && pwd)" "$m2" echo "cache=true" >> "$GITHUB_OUTPUT" fi - - name: Cache Robolectric's Android jars + - name: Restore Robolectric's Android jars + id: robolectric-cache if: steps.robolectric-jars.outputs.cache == 'true' - uses: actions/cache@v4 + uses: actions/cache/restore@v4 with: path: ../robolectric-jars - key: robolectric-android-all-v2-${{ steps.robolectric.outputs.version }} + key: robolectric-android-all-v3-${{ steps.robolectric.outputs.version }}-${{ github.run_id }} + restore-keys: robolectric-android-all-v3-${{ steps.robolectric.outputs.version }}- + - name: Count the restored Robolectric jars + if: steps.robolectric-jars.outputs.cache == 'true' + run: echo "ROBOLECTRIC_JARS_BEFORE=$(find "$GITHUB_WORKSPACE/../robolectric-jars" -name '*.jar' | wc -l)" >> "$GITHUB_ENV" - name: Unit tests id: unit-tests env: @@ -770,6 +775,34 @@ jobs: mkdir -p app/build ./gradlew testReleaseUnitTest --console=plain --info --stacktrace -Drobolectric.logging=stderr -PndkVersion="$NDK_VERSION" 2>&1 | tee app/build/unit-tests.log + # actions/cache only saves when the job succeeds, so a run whose tests died on a Maven 429 never filled the cache. + # Save the complete jars even after a failed test step, when this run added some; a partial download is dropped first. + - name: Save Robolectric's Android jars + id: robolectric-jars-final + if: always() && steps.robolectric-jars.outputs.cache == 'true' + run: | + python3 - <<'PY' + import glob, os, zipfile + root = os.path.join(os.environ['GITHUB_WORKSPACE'], '..', 'robolectric-jars') + for f in glob.glob(os.path.join(root, '**', '*'), recursive=True): + if not os.path.isfile(f): + continue + try: + ok = f.endswith('.jar') and zipfile.ZipFile(f).testzip() is None + except Exception: + ok = False + if not ok: + os.remove(f) + PY + after=$(find "$GITHUB_WORKSPACE/../robolectric-jars" -name '*.jar' | wc -l) + [ "$after" -gt "${ROBOLECTRIC_JARS_BEFORE:-0}" ] && echo "save=true" >> "$GITHUB_OUTPUT" || true + - name: Store Robolectric's Android jars + if: always() && steps.robolectric-jars-final.outputs.save == 'true' + uses: actions/cache/save@v4 + with: + path: ../robolectric-jars + key: robolectric-android-all-v3-${{ steps.robolectric.outputs.version }}-${{ github.run_id }} + - name: Upload unit test diagnostics id: unit-test-diagnostics if: always() && steps.unit-tests.outcome != 'skipped'