fix: cache compiled binary instead of recompiling each run#6
Merged
Conversation
go run . recompiled the tool on every invocation (~15s) and setup-go's module cache never worked: its cache-dependency-path is the action's go.sum under _actions/, outside GITHUB_WORKSPACE, so the cache key could not resolve. Build the binary once and cache it keyed on a content hash of the Go sources (correct for both SHA-pinned consumers and the repo's own uses: ./ self-invocation), skipping Go setup and compilation on a cache hit.
|
Ready to review this PR? Stage has broken it down into 4 individual chapters for you:
Chapters generated by Stage for commit 5c4aa0f on Jun 25, 2026 10:30am UTC. |
Contributor
Change file check✅ OK — 1 valid change file(s) added in this PR. |
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 action ran
go run .on every invocation, recompiling the tool (~15s) each time it's used — in Firmware that's three workflows (release,get-vars,check-changes). setup-go's module cache was supposed to mitigate this but never worked:The cause: the action's
cache-dependency-pathis its owngo.sumunder/home/runner/work/_actions/OpenShock/release-tool/<sha>/go.sum— outsideGITHUB_WORKSPACE(.../Firmware/Firmware). GitHub's cache-key path resolution is rooted at the workspace, so it can't resolve a path under_actions/, and the restore fails on every run.Fix
Build the binary once and cache it, instead of recompiling:
*.go,go.mod,go.sum) is computed in a shell step (works at any absolute path, unlikehashFiles), and used as the cache key. This is correct both for external consumers (pinned by SHA) and for this repo's ownuses: ./self-invocation (where the source changes per commit andgithub.action_refwould be unreliable).cache: false(no more broken module cache / warning) andgo build -o release-tool .produces the binary, which is then cached../release-toolbinary; behavior is identical togo run ...gitignorefor the builtrelease-toolbinary so theuses: ./self-invocation and local builds don't dirty the tree.Testing
go build+./release-tool statusproduce identical output togo run . status(Next version: 1.6.0against the Firmware repo).action.ymlvalidated as YAML; built binary is git-ignored.