From fad47eb92c956fc2db10a0adde966554eee8736d Mon Sep 17 00:00:00 2001 From: Jesper Terkelsen Date: Fri, 5 Jun 2026 09:00:34 +0200 Subject: [PATCH] ci(sonar-cloud): publish Linux-gradle-main- cache to warm PR fresh-branch builds [NO-JIRA] GitHub/runs-on caches are branch-scoped: a run can only restore caches from its own ref + the default branch (main). The Kotlin PR test workflow (#298) never runs on main, so no Linux-gradle-* cache exists there, and its Linux-gradle- fallback can't reach sibling PR caches -> every fresh branch's first build is cold (~3-4m recompile). sonar-cloud.yml already compiles + tests on main (code-analysis on push:main). Have it save ~/.gradle under Linux-gradle-main- (split restore/save, replacing setup-java's frozen cache:'gradle'). That sits on refs/heads/main = default branch, so the PR test workflow's existing Linux-gradle- fallback matches it -> fresh PR branches start warm. No change to pull-request-kotlin.yml needed. Save is guarded to refs/heads/main so a PR-context run can't poison the baseline. Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/workflows/sonar-cloud.yml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sonar-cloud.yml b/.github/workflows/sonar-cloud.yml index 41df8f6..98498f9 100644 --- a/.github/workflows/sonar-cloud.yml +++ b/.github/workflows/sonar-cloud.yml @@ -63,7 +63,16 @@ jobs: with: distribution: corretto java-version: ${{ inputs.java-version }} - cache: 'gradle' + - name: Restore Gradle cache + id: gradle-cache + uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-main-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-gradle-main- - name: Cache SonarCloud packages uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5 with: @@ -90,3 +99,11 @@ jobs: **/build/reports/problems/** if-no-files-found: ignore retention-days: 30 + - name: Save Gradle cache + if: ${{ always() && github.ref == 'refs/heads/main' && steps.gradle-cache.outputs.cache-hit != 'true' }} + uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-main-${{ github.sha }}