feat(setup-go): key Go caches per calling job, not per go.sum - #58
Merged
Conversation
actions/setup-go's built-in cache keys once per go.sum for the whole
repo: the first job to finish saves the key, and every sibling job
restores artifacts compiled with the wrong flags, recompiles from
scratch, and never saves its own ('Cache hit occurred on the primary
key …, not saving cache'). In k5s the Test job spent ~204 s of its
242 s recompiling the dependency graph with -race -coverprofile on
EVERY run, against ~30 s of actual test time — permanently, because
the shared key already held the build job's plain artifacts.
Replace the built-in cache with an actions/cache step over
~/go/pkg/mod + ~/.cache/go-build keyed on
setup-go-job-<os>-<arch>-<github.job>-<hash(go.mod, **/go.sum)>, with
restore-keys falling back to the same scope on a dep bump and then to
any scope (a cold job still inherits a sibling's module cache). New
cache-name input overrides the scope; 'false' disables.
Propagates to every @main caller on merge — the per-job keys are new,
so each repo's first run per job recompiles once and is warm after.
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.
Summary
Replaces
actions/setup-go's built-in cache with anactions/cachestep over~/go/pkg/mod+~/.cache/go-build, keyedsetup-go-job-<os>-<arch>-<github.job>-<hash(go.mod, **/go.sum)>.The built-in cache keys once per go.sum for the whole repo: the first job to save wins the key, and sibling jobs restore wrong-flag artifacts, recompile from scratch, and never save their own. Measured in k5s run 31884046285: the Test job spent 204 s of 242 s recompiling the dependency graph with
-race -coverprofileon every run, against ~31 s of actual test time; its post-step logsCache hit occurred on the primary key …, not saving cache.restore-keysfall back to the same scope with an older go.sum (near-warm after a dep bump), then to any scope (a cold job still inherits a sibling's module downloads).New
cache-nameinput: fixed name shares one cache across jobs that compile identically;"false"disables caching.Propagates to every
@maincaller on merge. Per-job keys are new, so each repo's first run per job compiles cold once and is warm from then on; the oldsetup-go-*caches age out on their own.Supersedes feat(setup-go): release-cache — a release-scoped Go cache for goreleaser jobs #56 (goreleaser
release-cacheinput): a goreleaser job's id gives it its own scope automatically, so the same benefit lands with zero caller opt-in. Second data point: k4a's last release spent 457 s of ~9 min insideRun GoReleaseron a cold cross-compile matrix — warm from the second release on under per-job scopes.Test plan
setup-go-job-Linux-X64-test-…/…-build-…; warm re-run restored them exactly — Test 284s→36s, Build 45s→37s🤖 Generated with Claude Code