Skip to content

Commit ba0a5a8

Browse files
authored
ci: fix the Go build cache never being hit (#972)
1 parent de3dc3a commit ba0a5a8

1 file changed

Lines changed: 29 additions & 8 deletions

File tree

.github/workflows/buildtest.yaml

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,7 @@ jobs:
3131
runs-on: ubuntu-latest
3232
steps:
3333
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
34-
- uses: actions/cache@2c8a9bd7457de244a408f35966fab2fb45fda9c8 # v6
35-
with:
36-
path: |
37-
~/go/pkg/mod
38-
~/go/bin
39-
~/.cache
40-
key: server-sdk-go
41-
34+
4235
- name: Set up SoX resampler and Opus
4336
run: |
4437
sudo apt-get update
@@ -49,6 +42,23 @@ jobs:
4942
with:
5043
# Test against the module minimum declared in go.mod, never a newer toolchain
5144
go-version-file: go.mod
45+
# setup-go's own cache restores on an exact key only, so any go.sum
46+
# change is a full cold build. Restored below instead.
47+
cache: false
48+
49+
# The run_id suffix never pre-exists, so a push always writes a fresh
50+
# entry rather than one frozen at the go.sum that first created it.
51+
- name: Restore Go caches
52+
id: go-cache
53+
uses: actions/cache/restore@2c8a9bd7457de244a408f35966fab2fb45fda9c8 # v6
54+
with:
55+
path: |
56+
~/.cache/go-build
57+
~/go/pkg/mod
58+
key: go-${{ runner.os }}-${{ hashFiles('go.sum') }}-${{ github.run_id }}
59+
restore-keys: |
60+
go-${{ runner.os }}-${{ hashFiles('go.sum') }}-
61+
go-${{ runner.os }}-
5262
5363
- name: Set up gotestfmt
5464
run: go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
@@ -81,3 +91,14 @@ jobs:
8191
args: test
8292
env:
8393
TestFlags: "-v"
94+
95+
# Only main writes. Pull requests read main's entry, which keeps ~1 GB
96+
# per PR run out of the repo's 10 GB cache budget.
97+
- name: Save Go caches
98+
if: github.event_name == 'push'
99+
uses: actions/cache/save@2c8a9bd7457de244a408f35966fab2fb45fda9c8 # v6
100+
with:
101+
path: |
102+
~/.cache/go-build
103+
~/go/pkg/mod
104+
key: ${{ steps.go-cache.outputs.cache-primary-key }}

0 commit comments

Comments
 (0)