fix(component-test): let deploy test jobs reuse the Gradle build cache [ENERGY-2742] - #340
Draft
ckattmann wants to merge 1 commit into
Draft
fix(component-test): let deploy test jobs reuse the Gradle build cache [ENERGY-2742]#340ckattmann wants to merge 1 commit into
ckattmann wants to merge 1 commit into
Conversation
…e [ENERGY-2742] The test job cached Gradle only through actions/setup-java's cache: 'gradle', which keys on a hash of the dependency files and, on an exact primary-key hit, does not save. The build-cache-1 inside that archive is therefore a frozen snapshot that never accumulates task outputs, so every deploy re-runs KSP and both Kotlin compiles from scratch. service-energy production deploy 2026-09-06 (run 34027976026): 'Test project' 6m33s, 'BUILD SUCCESSFUL in 6m 31s', '11 actionable tasks: 11 executed', nothing FROM-CACHE; :kspKotlin ~63s, :compileKotlin ~45s, :kspTestKotlin ~30s, :compileTestKotlin ~30s. The pull-request workflow restores the same tasks FROM-CACHE because it keys actions/cache on the commit and saves after a non-exact restore. Mirror that here: drop setup-java's cache input, restore with a per-commit key plus '-gradle-deploy-' and '-gradle-' fallbacks, and save only when the restore was not an exact hit.
Contributor
Author
|
Update on the validation note: the repo's |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
testjob incomponent-test-kotlin.yml(used bydeploy-kotlin.ymlanddeploy-kotlin-v2.yml) caches Gradle only viaactions/setup-java'scache: 'gradle'. That key is a hash of the dependency files, andactions/cacheskips saving when the primary key hits — so the~/.gradle/caches/build-cache-1inside the restored archive is a frozen snapshot that never accumulates task outputs. Every deploy therefore re-runs KSP and both Kotlin compiles from scratch.Evidence from service-energy's production deploy on 2026-09-06 (run 34027976026,
main@bfb13787):Test projectBUILD SUCCESSFUL in 6m 31s,11 actionable tasks: 11 executed— nothing FROM-CACHE:kspKotlin:compileKotlin:kspTestKotlin:compileTestKotlin:test(first event 10:43:14 → last 10:45:29)Cache hit for: setup-java-Linux-arm64-gradle-43568f91…(598 MB) →Cache hit occurred on the primary key …, not saving cacheSo ~4 of the 6.5 minutes is compilation that the pull-request workflow gets from cache:
pull-request-kotlin.ymlrestores/saves~/.gradlewithactions/cachekeyed on${{ runner.os }}-gradle-${{ github.head_ref }}-${{ github.sha }}and saves after a non-exact restore, which is why its runs report:compileKotlin FROM-CACHE.For scale, service-energy's
Test projectstep across recent deploys: 9m18s (09-02), 5m10s / 4m59s (09-03), 4m50s (09-05), 6m33s (09-06). The compile cost is systematic, not a one-off.Change
One file,
component-test-kotlin.yml, mirroring whatpull-request-kotlin.ymlalready does:cache: 'gradle'fromactions/setup-javaRestore Gradle cache(id: gradle-cache,actions/cache/restore@v5) over~/.gradle/caches+~/.gradle/wrapper, key${{ runner.os }}-gradle-deploy-${{ github.sha }}, restore-keys${{ runner.os }}-gradle-deploy-then${{ runner.os }}-gradle-Save Gradle cache(actions/cache/save@v5) guarded byalways() && steps.gradle-cache.outputs.cache-hit != 'true'The
deploy-key segment keeps these archives distinct from the PR workflow's and fromsonar-cloud.yml's-gradle-main-keys; the two fallbacks mean a deploy warms up from the previous deploy, and can also pick up any main-scoped Gradle cache when there isn't one.Expected effect
~3–4 minutes off the deploy test job for every Kotlin service, growing with how little changed between deploys. The first deploy after this merges is still a miss (nothing under
-gradle-deploy-yet); from the second one onwards the previous archive is restored.Considerations for reviewers
${{ runner.os }}-gradle-deploy-${{ github.ref_name }}(one archive per tag/branch, overwritten) at the cost of losing the exact-hit guard's meaning.code-coverage-kotlin.ymlorcomponent-service-profile-kotlin.yml, which use the samecache: 'gradle'pattern and presumably have the same symptom. Happy to follow up once this shape is agreed.timeout-minutes, artifact upload, and the test task itself.Validation
jobs.test.steps= Checkout → Set up JDK → Restore Gradle cache (id: gradle-cache) → Test project → Upload test results (if: always()) → Save Gradle cache (if: always() && steps.gradle-cache.outputs.cache-hit != 'true')).actionlintis not installed on my machine, so it has not been run locally; relying on repo CI for that.--parallel --build-cache, which is what makes the restoredbuild-cache-1useful.Ticket: https://montaapp.atlassian.net/browse/ENERGY-2742 (draft — CODEOWNERS is @monta-app/sre, so this needs your review before it affects every Kotlin deploy)