ci: fix the Go build cache never being hit - #79
Open
u9g wants to merge 1 commit into
Open
Conversation
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.
The
Testjob compiles the module from scratch on every run, because neither of the two caches configured here has ever produced a hit.The
actions/cachestep used a constant key.key: media-sdknever changes, andactions/cachedoes not re-save on a hit, so the entry stayed frozen at whatever it held when first written. The cache API reports it as 227 MB, created 2026-08-06, still being restored today — and because every run reads it, its last-accessed time keeps refreshing, so it never ages out either. Nothing in it could match: it cached all of~/.cache, whosego-buildentries are keyed by compiler build ID, so a newer toolchain misses every one. It cost time on every run and left aGOCACHEfull of dead entries thatsetup-gothen re-uploaded.setup-go's built-in cache cannot close the gap. Its key is
setup-go-{os}-{arch}-{linuxver}go-{version}-{go.sum hash}, and it callsrestoreCachewith no restore keys — a match is exact or nothing, and upstream has declined to add prefix fallback (actions/setup-go#404). So any dependency bump rebuilds everything rather than just the part that changed, and a Go point release rotates the key out from under every open PR at once.What this changes
actions/cachestep.cache: falseon setup-go and restores viaactions/cache/restore, keyed on thego.sumhash with a prefix fallback, so a dependency change reuses the entries that are still valid.run_idso it never matches on write. A push therefore always stores a fresh entry, rather than one pinned to thego.sumthat first created it.Narrowing the paths to
~/.cache/go-buildand~/go/pkg/moddrops~/go/bin. Binaries installed there are re-go installed on every run regardless, and the build cache covers most of that cost.The save step reuses the restore step's
cache-primary-keyoutput rather than re-evaluatinghashFiles, because theReplace mutexesstep rewritesgo.mod/go.sumpartway through the job. The key therefore reflects the committedgo.sum, not the mutated one.Follow-up, not in this PR
The frozen 227 MB
media-sdkentry this PR stops writing to should be deleted; nothing will read it again.