Skip to content

Commit 4df5660

Browse files
committed
chore: Optimize Go caches in Github Actions
1 parent 938fdfd commit 4df5660

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

.github/workflows/main.yml

+17-6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ jobs:
6565
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
6666
with:
6767
fetch-depth: 1
68+
- uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a
69+
with:
70+
path: |
71+
~/.cache/go-build
72+
~/go/pkg/mod
73+
key: setup-go-${{ runner.os }}-x64-ubuntu22-go-${{ env.GO_VERSION }}-${{ hashFiles('**/go.sum') }}
74+
restore-keys: |
75+
setup-go-${{ runner.os }}-x64-ubuntu22-go-${{ env.GO_VERSION }}-
6876
- uses: github/codeql-action/init@662472033e021d55d94146f66f6058822b0b39fd
6977
with:
7078
languages: go
@@ -304,17 +312,15 @@ jobs:
304312
runs-on: windows-2022
305313
permissions:
306314
contents: read
315+
env:
316+
GOPATH: 'D:\golang\go'
317+
GOCACHE: 'D:\golang\cache'
318+
GOMODCACHE: 'D:\golang\modcache'
307319
steps:
308320
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
309321
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed
310322
with:
311323
go-version: ${{ env.GO_VERSION }}
312-
- uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a
313-
with:
314-
path: ~/go/pkg/mod
315-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
316-
restore-keys: |
317-
${{ runner.os }}-go-
318324
- name: build
319325
run: |
320326
go build ./...
@@ -386,6 +392,11 @@ jobs:
386392
runs-on: ${{ matrix.runs-on }}
387393
permissions:
388394
contents: read
395+
env:
396+
GOPATH: ${{ startsWith(matrix.runs-on, 'windows') && 'D:\golang\go' || '' }}
397+
GOCACHE: ${{ startsWith(matrix.runs-on, 'windows') && 'D:\golang\cache' || '' }}
398+
GOMODCACHE: ${{ startsWith(matrix.runs-on, 'windows') && 'D:\golang\modcache' || '' }}
399+
USERPROFILE: ${{ startsWith(matrix.runs-on, 'windows') && 'D:\homedir' || '' }}
389400
steps:
390401
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
391402
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed

0 commit comments

Comments
 (0)