Skip to content

Commit e6b10d9

Browse files
authored
ci: keep the Go build cache current (#3139)
* ci: keep the Go build cache current actions/setup-go keys its cache on the Go version and go.sum only. The first job to finish after a new Go release or a go.sum change saves the entry, and every later run hits that key and skips saving. Master CI is still restoring the entries saved on 2026-09-11 (Go 1.27.1), so everything that changed since then recompiles in every run. Replace it with actions/cache restore/save, keyed per OS, architecture, Go version and job. Each run restores the newest cache saved for its key prefix, and runs other than pull requests save a new entry for the commit, so the cache tracks master. Pull requests only restore, which keeps the repository's cache storage bounded. A full race build cache compresses to about 80 MB. Claude-Session: https://claude.ai/code/session_01QKDYQr53zNKkR7nif2CAAq * ci: drop Go cache steps from the benchmark job Since #3140 the benchmark job runs only on pull requests, which never save a cache, so its restore would always miss. Claude-Session: https://claude.ai/code/session_01QKDYQr53zNKkR7nif2CAAq
1 parent 680772f commit e6b10d9

2 files changed

Lines changed: 76 additions & 0 deletions

File tree

‎.github/workflows/checks.yml‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ env:
2626
# https://github.com/actions/setup-go/commit/924ae3a1cded613372ab5595356fb5720e22ba16
2727
SETUP_GO_ACTION: &setup_go_action actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6
2828

29+
# https://github.com/actions/cache/commit/55cc8345863c7cc4c66a329aec7e433d2d1c52a9
30+
CACHE_RESTORE_ACTION: &cache_restore_action actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
31+
CACHE_SAVE_ACTION: &cache_save_action actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
32+
2933
jobs:
3034
check:
3135
runs-on: ubuntu-latest
@@ -38,6 +42,30 @@ jobs:
3842
with:
3943
go-version: ${{ env.LATEST_GO_VERSION }}
4044
check-latest: true
45+
cache: false
46+
47+
# setup-go's built-in cache is keyed on go.sum only, so its entry is never refreshed and
48+
# soon holds little of the current build. Restore the latest cache saved for this job
49+
# instead, and save a new one after runs other than pull requests, which only restore.
50+
- name: Find Go Cache
51+
id: go-cache
52+
shell: bash
53+
run: |
54+
{
55+
echo "build=$(go env GOCACHE)"
56+
echo "mod=$(go env GOMODCACHE)"
57+
echo "key=go-${{ runner.os }}-${{ runner.arch }}-$(go env GOVERSION)-${{ github.job }}"
58+
} >> "$GITHUB_OUTPUT"
59+
60+
- name: Restore Go Cache
61+
id: go-cache-restore
62+
uses: *cache_restore_action
63+
with:
64+
path: |
65+
${{ steps.go-cache.outputs.build }}
66+
${{ steps.go-cache.outputs.mod }}
67+
key: ${{ steps.go-cache.outputs.key }}-${{ github.sha }}
68+
restore-keys: ${{ steps.go-cache.outputs.key }}-
4169

4270
- name: Run golint
4371
run: |
@@ -54,3 +82,12 @@ jobs:
5482
go version
5583
go install golang.org/x/vuln/cmd/govulncheck@latest
5684
govulncheck ./...
85+
86+
- name: Save Go Cache
87+
if: github.event_name != 'pull_request' && steps.go-cache-restore.outputs.cache-hit != 'true'
88+
uses: *cache_save_action
89+
with:
90+
path: |
91+
${{ steps.go-cache.outputs.build }}
92+
${{ steps.go-cache.outputs.mod }}
93+
key: ${{ steps.go-cache.outputs.key }}-${{ github.sha }}

‎.github/workflows/echo.yml‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ env:
2626
# https://github.com/actions/setup-go/commit/924ae3a1cded613372ab5595356fb5720e22ba16
2727
SETUP_GO_ACTION: &setup_go_action actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6
2828

29+
# https://github.com/actions/cache/commit/55cc8345863c7cc4c66a329aec7e433d2d1c52a9
30+
CACHE_RESTORE_ACTION: &cache_restore_action actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
31+
CACHE_SAVE_ACTION: &cache_save_action actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
32+
2933
# https://github.com/codecov/codecov-action/commit/fb8b3582c8e4def4969c97caa2f19720cb33a72f
3034
CODECOV_ACTION: &codecov_action codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7
3135

@@ -49,10 +53,43 @@ jobs:
4953
uses: *setup_go_action
5054
with:
5155
go-version: ${{ matrix.go }}
56+
cache: false
57+
58+
# setup-go's built-in cache is keyed on go.sum only, so its entry is never refreshed and
59+
# soon holds little of the current build. Restore the latest cache saved for this job
60+
# instead, and save a new one after runs other than pull requests, which only restore.
61+
- name: Find Go Cache
62+
id: go-cache
63+
shell: bash
64+
run: |
65+
{
66+
echo "build=$(go env GOCACHE)"
67+
echo "mod=$(go env GOMODCACHE)"
68+
echo "key=go-${{ runner.os }}-${{ runner.arch }}-$(go env GOVERSION)-${{ github.job }}"
69+
} >> "$GITHUB_OUTPUT"
70+
71+
- name: Restore Go Cache
72+
id: go-cache-restore
73+
uses: *cache_restore_action
74+
with:
75+
path: |
76+
${{ steps.go-cache.outputs.build }}
77+
${{ steps.go-cache.outputs.mod }}
78+
key: ${{ steps.go-cache.outputs.key }}-${{ github.sha }}
79+
restore-keys: ${{ steps.go-cache.outputs.key }}-
5280

5381
- name: Run Tests
5482
run: go test -race --coverprofile=coverage.coverprofile --covermode=atomic ./...
5583

84+
- name: Save Go Cache
85+
if: github.event_name != 'pull_request' && steps.go-cache-restore.outputs.cache-hit != 'true'
86+
uses: *cache_save_action
87+
with:
88+
path: |
89+
${{ steps.go-cache.outputs.build }}
90+
${{ steps.go-cache.outputs.mod }}
91+
key: ${{ steps.go-cache.outputs.key }}-${{ github.sha }}
92+
5693
- name: Upload coverage to Codecov
5794
if: success() && matrix.go == env.LATEST_GO_VERSION && matrix.os == 'ubuntu-latest'
5895
uses: *codecov_action
@@ -83,6 +120,7 @@ jobs:
83120
uses: *setup_go_action
84121
with:
85122
go-version: ${{ env.LATEST_GO_VERSION }}
123+
cache: false
86124

87125
- name: Install Dependencies
88126
run: go install golang.org/x/perf/cmd/benchstat@latest
@@ -102,3 +140,4 @@ jobs:
102140
- name: Run Benchstat
103141
run: |
104142
benchstat previous/benchmark.txt new/benchmark.txt
143+

0 commit comments

Comments
 (0)