Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4b75472

Browse files
committed
fix caching for windows and tweak cache keys
It turns out that the globbing used by actions/cache does not actually support reading env vars, and so the caching of GOCACHE on windows never worked. Use the full path relative to $HOME. We also start suggesting the inclusion of the Go version as part of the cache key, because GOCACHE is different per go version. Finally, bump the versions of setup-go and checkout.
1 parent 7b5e425 commit 4b75472

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

.github/workflows/test.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ jobs:
88
os: [ubuntu-latest, macos-latest, windows-latest]
99
runs-on: ${{ matrix.os }}
1010
steps:
11-
- uses: actions/setup-go@v2
11+
- uses: actions/setup-go@v3
1212
with:
1313
go-version: ${{ matrix.go-version }}
14-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v3
1515
- run: go test ./...
1616

1717
test-cache:
1818
runs-on: ubuntu-latest
1919
steps:
20-
- uses: actions/setup-go@v2
20+
- uses: actions/setup-go@v3
2121
with:
2222
go-version: 1.17.x
23-
- uses: actions/checkout@v2
23+
- uses: actions/checkout@v3
2424
- uses: actions/cache@v2
2525
with:
2626
# In order:
@@ -32,8 +32,8 @@ jobs:
3232
~/go/pkg/mod
3333
~/.cache/go-build
3434
~/Library/Caches/go-build
35-
%LocalAppData%\go-build
36-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
35+
~\AppData\Local\go-build
36+
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
3737
restore-keys: |
38-
${{ runner.os }}-go-
38+
${{ runner.os }}-go-${{ matrix.go-version }}-
3939
- run: go test ./...

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ jobs:
1717
os: [ubuntu-latest, macos-latest, windows-latest]
1818
runs-on: ${{ matrix.os }}
1919
steps:
20-
- uses: actions/setup-go@v2
20+
- uses: actions/setup-go@v3
2121
with:
2222
go-version: ${{ matrix.go-version }}
23-
- uses: actions/checkout@v2
23+
- uses: actions/checkout@v3
2424
- run: go test ./...
2525
```
2626
@@ -100,10 +100,10 @@ You can also include Go's build cache, to improve incremental builds:
100100
~/go/pkg/mod
101101
~/.cache/go-build
102102
~/Library/Caches/go-build
103-
%LocalAppData%\go-build
104-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
103+
~\AppData\Local\go-build
104+
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
105105
restore-keys: |
106-
${{ runner.os }}-go-
106+
${{ runner.os }}-go-${{ matrix.go-version }}-
107107
```
108108

109109
This is demonstrated via the `test-cache` job [in this very repository](https://github.com/mvdan/github-actions-golang/actions).
@@ -201,7 +201,7 @@ jobs:
201201
run:
202202
working-directory: ${{ env.GOPATH }}/src/github.com/${{ github.repository }}
203203
steps:
204-
- uses: actions/checkout@v2
204+
- uses: actions/checkout@v3
205205
with:
206206
path: ${{ env.GOPATH }}/src/github.com/${{ github.repository }}
207207
```

0 commit comments

Comments
 (0)