Skip to content

Only save Go caches from trunk - #14840

Merged
williammartin merged 1 commit into
trunkfrom
williammartin-review-pr-14837
Oct 27, 2026
Merged

williammartin merged 1 commit into
trunkfrom
williammartin-review-pr-14837

Conversation

@williammartin

Copy link
Copy Markdown
Member

Relates to #14837

Description

#14837 gave the build and integration-tests jobs in go.yml their own Go caches, keyed on the job, OS, runner image, Go version and go.mod. A race cache is about 520 MB and a non-race cache about 300 MB, so every run that misses saves about 2.5 GB across the three OSes.

Pull requests that change go.mod, which Dependabot opens often, each miss and save their own copy. Those caches can only be restored by that pull request, so they take up the repository's cache storage and push out the trunk caches everything else relies on.

This PR changes .github/actions/setup-go so that only trunk saves caches. Pull requests restore them with actions/cache/restore, and fall back to the latest trunk cache for the same job, OS and Go version when go.mod has changed.

How did you test this change?

Not tested. The restore path runs in this PR's own CI, but the save path only runs on trunk, so I can't exercise it before merging.

Key points

  • A pull request that changes go.mod restores an older trunk cache on every run, rather than building cold once and then reusing its own cache. I think most packages still match, so this costs little, but I haven't measured it.
  • trunk saves on an exact key only, with no fallback to an older cache. Building on a restored older cache would keep adding stale packages to it.
  • The build job also builds gh without -race after the tests, so those packages end up in the race cache too. I suspect they add only about 30 MB, so I didn't split them out.

Notes for reviewers

The whole change is in .github/actions/setup-go/action.yml. The key format is unchanged from #14837, so existing trunk caches still match.

Authorship and follow-up

Who wrote this:

  • A human wrote it.
  • An agent wrote it under close human direction.
  • An agent wrote it independently, and no human has guided the implementation beyond the initial prompt.

Who answers review comments:

  • @williammartin will read and reply directly.
  • An agent will draft replies and @username will read them before they are posted.
  • Nobody has explicitly committed to replying.

Pull requests restore the per-job Go caches but no longer save them,
falling back to the latest trunk cache when go.mod changes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4a5f4c22-1eba-41b2-a77e-3d29b257ace9

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the change restricting Go cache saves to trunk.

No open issues 🎉

What changed in this PR

This PR limits Go cache saves to trunk, reducing cache storage consumed by pull requests while preserving the separate job caches introduced in #14837.

Changes:

  • Centralizes cache key construction without changing the existing key format.
  • Restricts cache saving to trunk, using exact-key matching without fallback.
  • Makes other refs restore-only, with a compatible prefix fallback when go.mod changes.
File Description
.github/​actions/​setup-go/​action.yml Separates trunk caching from restore-only behavior and computes shared cache keys.

Review effort: Balanced

@williammartin
williammartin merged commit 93d24ce into trunk Oct 27, 2026
17 checks passed
@williammartin
williammartin deleted the williammartin-review-pr-14837 branch October 27, 2026 14:38
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.

3 participants