Skip to content

Commit b7f51a1

Browse files
committed
.github/workflows: add artifact caching and remove double build on race
Go artifact caching will help provided that the cache remains small enough - we can reuse the strategy from the Windows build where we only cache and pull the zips, but let go(1) do the many-file unpacking as it does so faster. The race matrix was building once without race, then running all the tests with race, so change the matrix to incldue a `buildflags` parameter and use that both in the build and test steps. Updates #cleanup Signed-off-by: James Tucker <james@tailscale.com>
1 parent f352f8a commit b7f51a1

File tree

1 file changed

+55
-11
lines changed

1 file changed

+55
-11
lines changed

.github/workflows/test.yml

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,30 @@ jobs:
4646
include:
4747
- goarch: amd64
4848
- goarch: amd64
49-
variant: race
49+
buildflags: "-race"
5050
- goarch: "386" # thanks yaml
5151
runs-on: ubuntu-22.04
5252
steps:
5353
- name: checkout
5454
uses: actions/checkout@v3
55+
- name: Restore Cache
56+
uses: actions/cache@v3
57+
with:
58+
# Note: unlike the other setups, this is only grabbing the mod download
59+
# cache, rather than the whole mod directory, as the download cache
60+
# contains zips that can be unpacked in parallel faster than they can be
61+
# fetched and extracted by tar
62+
path: |
63+
~/.cache/go-build
64+
~/go/pkg/mod/cache
65+
~\AppData\Local\go-build
66+
# The -2- here should be incremented when the scheme of data to be
67+
# cached changes (e.g. path above changes).
68+
key: ${{ github.job }}-${{ runner.os }}-${{ matrix.goarch }}-${{ matrix.buildflags }}-go-2-${{ hashFiles('**/go.sum') }}
69+
restore-keys: |
70+
${{ github.job }}-${{ runner.os }}-${{ matrix.goarch }}-${{ matrix.buildflags }}-go-2-
5571
- name: build all
56-
run: ./tool/go build ./...
72+
run: ./tool/go build ${{matrix.buildflags}} ./...
5773
env:
5874
GOARCH: ${{ matrix.goarch }}
5975
- name: build variant CLIs
@@ -73,13 +89,7 @@ jobs:
7389
- name: build test wrapper
7490
run: ./tool/go build -o /tmp/testwrapper ./cmd/testwrapper
7591
- name: test all
76-
if: matrix.variant != 'race'
77-
run: ./tool/go test -exec=/tmp/testwrapper -bench=. -benchtime=1x ./...
78-
env:
79-
GOARCH: ${{ matrix.goarch }}
80-
- name: test all (race)
81-
if: matrix.variant == 'race'
82-
run: ./tool/go test -race -exec=/tmp/testwrapper -bench=. -benchtime=1x ./...
92+
run: ./tool/go test ${{matrix.buildflags}} -exec=/tmp/testwrapper -bench=. -benchtime=1x ./...
8393
env:
8494
GOARCH: ${{ matrix.goarch }}
8595
- name: check that no tracked files changed
@@ -116,12 +126,14 @@ jobs:
116126
# contains zips that can be unpacked in parallel faster than they can be
117127
# fetched and extracted by tar
118128
path: |
129+
~/.cache/go-build
119130
~/go/pkg/mod/cache
120131
~\AppData\Local\go-build
121132
# The -2- here should be incremented when the scheme of data to be
122133
# cached changes (e.g. path above changes).
123-
# TODO(raggi): add a go version here.
124-
key: ${{ runner.os }}-go-2-${{ hashFiles('**/go.sum') }}
134+
key: ${{ github.job }}-${{ runner.os }}-go-2-${{ hashFiles('**/go.sum') }}
135+
restore-keys: |
136+
${{ github.job }}-${{ runner.os }}-go-2-
125137
- name: test
126138
# Don't use -bench=. -benchtime=1x.
127139
# Somewhere in the layers (powershell?)
@@ -181,6 +193,22 @@ jobs:
181193
steps:
182194
- name: checkout
183195
uses: actions/checkout@v3
196+
- name: Restore Cache
197+
uses: actions/cache@v3
198+
with:
199+
# Note: unlike the other setups, this is only grabbing the mod download
200+
# cache, rather than the whole mod directory, as the download cache
201+
# contains zips that can be unpacked in parallel faster than they can be
202+
# fetched and extracted by tar
203+
path: |
204+
~/.cache/go-build
205+
~/go/pkg/mod/cache
206+
~\AppData\Local\go-build
207+
# The -2- here should be incremented when the scheme of data to be
208+
# cached changes (e.g. path above changes).
209+
key: ${{ github.job }}-${{ runner.os }}-${{ matrix.goos }}-${{ matrix.goarch }}-go-2-${{ hashFiles('**/go.sum') }}
210+
restore-keys: |
211+
${{ github.job }}-${{ runner.os }}-${{ matrix.goos }}-${{ matrix.goarch }}-go-2-
184212
- name: build all
185213
run: ./tool/go build ./cmd/...
186214
env:
@@ -230,6 +258,22 @@ jobs:
230258
steps:
231259
- name: checkout
232260
uses: actions/checkout@v3
261+
- name: Restore Cache
262+
uses: actions/cache@v3
263+
with:
264+
# Note: unlike the other setups, this is only grabbing the mod download
265+
# cache, rather than the whole mod directory, as the download cache
266+
# contains zips that can be unpacked in parallel faster than they can be
267+
# fetched and extracted by tar
268+
path: |
269+
~/.cache/go-build
270+
~/go/pkg/mod/cache
271+
~\AppData\Local\go-build
272+
# The -2- here should be incremented when the scheme of data to be
273+
# cached changes (e.g. path above changes).
274+
key: ${{ github.job }}-${{ runner.os }}-go-2-${{ hashFiles('**/go.sum') }}
275+
restore-keys: |
276+
${{ github.job }}-${{ runner.os }}-go-2-
233277
- name: build tsconnect client
234278
run: ./tool/go build ./cmd/tsconnect/wasm ./cmd/tailscale/cli
235279
env:

0 commit comments

Comments
 (0)