Skip to content

fix: cache compiled binary instead of recompiling each run#6

Merged
hhvrc merged 1 commit into
masterfrom
fix/cache-built-binary
Jun 25, 2026
Merged

fix: cache compiled binary instead of recompiling each run#6
hhvrc merged 1 commit into
masterfrom
fix/cache-built-binary

Conversation

@hhvrc

@hhvrc hhvrc commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

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:

##[warning]Restore cache failed: Some specified paths were not resolved, unable to cache dependencies.

The cause: the action's cache-dependency-path is its own go.sum under /home/runner/work/_actions/OpenShock/release-tool/<sha>/go.sumoutside GITHUB_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:

  • A content hash of the Go sources (*.go, go.mod, go.sum) is computed in a shell step (works at any absolute path, unlike hashFiles), and used as the cache key. This is correct both for external consumers (pinned by SHA) and for this repo's own uses: ./ self-invocation (where the source changes per commit and github.action_ref would be unreliable).
  • On a cache hit, Go setup and compilation are skipped entirely.
  • On a miss, setup-go runs with cache: false (no more broken module cache / warning) and go build -o release-tool . produces the binary, which is then cached.
  • The run step executes the prebuilt ./release-tool binary; behavior is identical to go run ..
  • Added .gitignore for the built release-tool binary so the uses: ./ self-invocation and local builds don't dirty the tree.

Testing

  • go build + ./release-tool status produce identical output to go run . status (Next version: 1.6.0 against the Firmware repo).
  • action.yml validated as YAML; built binary is git-ignored.

Open in Stage

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.
@stage-review

stage-review Bot commented Jun 25, 2026

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 4 individual chapters for you:

Title
1 Ignore compiled binary in git
2 Implement binary caching logic in action
3 Execute prebuilt binary instead of recompiling
4 Document caching fix in changelog
Open in Stage

Chapters generated by Stage for commit 5c4aa0f on Jun 25, 2026 10:30am UTC.

@github-actions

Copy link
Copy Markdown
Contributor

Change file check

OK — 1 valid change file(s) added in this PR.

@hhvrc hhvrc merged commit 765f1ed into master Jun 25, 2026
7 checks passed
@hhvrc hhvrc deleted the fix/cache-built-binary branch June 25, 2026 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant