Skip to content

Commit c9b8ad0

Browse files
committed
Improve caching for go actions, add go build cache
Signed-off-by: Bogdan Drutu <[email protected]>
1 parent 379645d commit c9b8ad0

File tree

3 files changed

+52
-31
lines changed

3 files changed

+52
-31
lines changed

.github/workflows/build-and-test.yml

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ jobs:
2323
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
2424
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
2525
shell: bash
26-
- name: Cache Go Modules
26+
- name: Cache Go
2727
uses: actions/cache@v2
2828
env:
2929
cache-name: cache-go-modules
3030
with:
31-
path: \Users\runneradmin\go\pkg\mod
32-
key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('./go.mod') }}
31+
path: |
32+
\Users\runneradmin\go\pkg\mod
33+
%LocalAppData%\go-build
34+
key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('./go.mod', '**/go.sum') }}
3335
- name: Run Unit tests
3436
run: go test ./...
3537
- name: GitHub Issue Generator
@@ -51,17 +53,21 @@ jobs:
5153
run: |
5254
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
5355
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
54-
- name: Cache Go Modules
56+
- name: Cache Go
5557
id: module-cache
5658
uses: actions/cache@v2
5759
env:
5860
cache-name: cache-go-modules
5961
with:
60-
path: /home/runner/go/pkg/mod
61-
key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('**/go.mod') }}
62-
- name: Download dependencies
62+
path: |
63+
/home/runner/go/pkg/mod
64+
/home/runner/.cache/go-build
65+
key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('**/go.mod', '**/go.sum') }}
66+
- name: Install dependencies
6367
if: steps.module-cache.outputs.cache-hit != 'true'
64-
run: go mod download
68+
run: |
69+
make gomoddownload
70+
make gotestinstall
6571
- name: Cache Tools
6672
id: tool-cache
6773
uses: actions/cache@v2
@@ -90,13 +96,16 @@ jobs:
9096
run: |
9197
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
9298
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
93-
- name: Cache Go Modules
99+
- name: Cache Go
100+
id: module-cache
94101
uses: actions/cache@v2
95102
env:
96103
cache-name: cache-go-modules
97104
with:
98-
path: /home/runner/go/pkg/mod
99-
key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('./go.mod') }}
105+
path: |
106+
/home/runner/go/pkg/mod
107+
/home/runner/.cache/go-build
108+
key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('**/go.mod', '**/go.sum') }}
100109
- name: Cache Tools
101110
id: tool-cache
102111
uses: actions/cache@v2
@@ -129,13 +138,16 @@ jobs:
129138
run: |
130139
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
131140
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
132-
- name: Cache Go Modules
141+
- name: Cache Go
142+
id: module-cache
133143
uses: actions/cache@v2
134144
env:
135145
cache-name: cache-go-modules
136146
with:
137-
path: /home/runner/go/pkg/mod
138-
key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('./go.mod') }}
147+
path: |
148+
/home/runner/go/pkg/mod
149+
/home/runner/.cache/go-build
150+
key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('**/go.mod', '**/go.sum') }}
139151
- name: Cache Tools
140152
id: tool-cache
141153
uses: actions/cache@v2
@@ -170,13 +182,16 @@ jobs:
170182
run: |
171183
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
172184
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
173-
- name: Cache Go Modules
185+
- name: Cache Go
186+
id: module-cache
174187
uses: actions/cache@v2
175188
env:
176189
cache-name: cache-go-modules
177190
with:
178-
path: /home/runner/go/pkg/mod
179-
key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('./go.mod') }}
191+
path: |
192+
/home/runner/go/pkg/mod
193+
/home/runner/.cache/go-build
194+
key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('**/go.mod', '**/go.sum') }}
180195
- name: Cache Tools
181196
id: tool-cache
182197
uses: actions/cache@v2
@@ -211,13 +226,16 @@ jobs:
211226
run: |
212227
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
213228
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
214-
- name: Cache Go Modules
229+
- name: Cache Go
230+
id: module-cache
215231
uses: actions/cache@v2
216232
env:
217233
cache-name: cache-go-modules
218234
with:
219-
path: /home/runner/go/pkg/mod
220-
key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('./go.mod') }}
235+
path: |
236+
/home/runner/go/pkg/mod
237+
/home/runner/.cache/go-build
238+
key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('**/go.mod', '**/go.sum') }}
221239
- name: Cache Tools
222240
id: tool-cache
223241
uses: actions/cache@v2
@@ -267,13 +285,16 @@ jobs:
267285
run: |
268286
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
269287
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
270-
- name: Cache Go Modules
288+
- name: Cache Go
289+
id: module-cache
271290
uses: actions/cache@v2
272291
env:
273292
cache-name: cache-go-modules
274293
with:
275-
path: /home/runner/go/pkg/mod
276-
key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('./go.mod') }}
294+
path: |
295+
/home/runner/go/pkg/mod
296+
/home/runner/.cache/go-build
297+
key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('**/go.mod', '**/go.sum') }}
277298
- name: Cache Tools
278299
id: tool-cache
279300
uses: actions/cache@v2
@@ -365,13 +386,6 @@ jobs:
365386
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
366387
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
367388
mkdir bin/
368-
- name: Cache Go Modules
369-
uses: actions/cache@v2
370-
env:
371-
cache-name: cache-go-modules
372-
with:
373-
path: \Users\runneradmin\go\pkg\mod
374-
key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('./go.mod') }}
375389
- name: Download Binaries
376390
uses: actions/download-artifact@v1
377391
with:

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ testbed-list-correctness-metrics:
8080
testbed-correctness-metrics: otelcol
8181
cd ./testbed/correctness/metrics && ./runtests.sh
8282

83+
.PHONY: gomoddownload
84+
gomoddownload:
85+
@$(MAKE) for-all CMD="go mod download"
86+
87+
.PHONY: gotestinstall
88+
gotestinstall:
89+
@$(MAKE) for-all CMD="make test GOTEST_OPT=\"-i\""
90+
8391
.PHONY: gotest
8492
gotest:
8593
@$(MAKE) for-all CMD="make test"

Makefile.Common

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ all-license-srcs:
2727

2828
.PHONY: test
2929
test:
30-
@echo "running go unit test ./... in `pwd`"
3130
@echo $(ALL_PKGS) | xargs -n 10 $(GOTEST) $(GOTEST_OPT)
3231

3332
.PHONY: benchmark

0 commit comments

Comments
 (0)