Skip to content

Commit 08c6fb4

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

File tree

3 files changed

+59
-38
lines changed

3 files changed

+59
-38
lines changed

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

Lines changed: 51 additions & 37 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,21 +138,24 @@ 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
142154
env:
143155
cache-name: cache-tool-binaries
144156
with:
145157
path: /home/runner/go/bin
146-
key: tools-${{ runner.os }}-${{ hashFiles('./internal/tools/go.mod') }}
158+
key: tools-${{ runner.os }}-${{ hashFiles('./internal/tools/go.mod', './cmd/mdatagen/go.mod', './cmd/mdatagen/*.go') }}
147159
- name: Run Unit Tests
148160
run: |
149161
mkdir -p test-results/junit
@@ -170,21 +182,24 @@ 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
183198
env:
184199
cache-name: cache-tool-binaries
185200
with:
186201
path: /home/runner/go/bin
187-
key: tools-${{ runner.os }}-${{ hashFiles('./internal/tools/go.mod') }}
202+
key: tools-${{ runner.os }}-${{ hashFiles('./internal/tools/go.mod', './cmd/mdatagen/go.mod', './cmd/mdatagen/*.go') }}
188203
- name: Build Collector for All Architectures
189204
run: grep ^binaries-all-sys Makefile|fmt -w 1|tail -n +2|xargs make
190205
- name: Create Collector Binaries Archive
@@ -211,21 +226,24 @@ 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
224242
env:
225243
cache-name: cache-tool-binaries
226244
with:
227245
path: /home/runner/go/bin
228-
key: tools-${{ runner.os }}-${{ hashFiles('./internal/tools/go.mod') }}
246+
key: tools-${{ runner.os }}-${{ hashFiles('./internal/tools/go.mod', './cmd/mdatagen/go.mod', './cmd/mdatagen/*.go') }}
229247
- name: Install fluentbit
230248
if: ${{ contains(matrix.test, 'Log10kDPS') }}
231249
run: |
@@ -267,21 +285,24 @@ 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
280301
env:
281302
cache-name: cache-tool-binaries
282303
with:
283304
path: /home/runner/go/bin
284-
key: tools-${{ runner.os }}-${{ hashFiles('./internal/tools/go.mod') }}
305+
key: tools-${{ runner.os }}-${{ hashFiles('./internal/tools/go.mod', './cmd/mdatagen/go.mod', './cmd/mdatagen/*.go') }}
285306
- name: Loadtest
286307
run: make testbed-correctness
287308
- name: GitHub Issue Generator
@@ -322,7 +343,7 @@ jobs:
322343
cache-name: cache-tool-binaries
323344
with:
324345
path: /home/runner/go/bin
325-
key: tools-${{ runner.os }}-${{ hashFiles('./internal/tools/go.mod') }}
346+
key: tools-${{ runner.os }}-${{ hashFiles('./internal/tools/go.mod', './cmd/mdatagen/go.mod', './cmd/mdatagen/*.go') }}
326347
- name: Download Collector Binaries
327348
uses: actions/download-artifact@v1
328349
with:
@@ -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:
@@ -414,7 +428,7 @@ jobs:
414428
cache-name: cache-tool-binaries
415429
with:
416430
path: /home/runner/go/bin
417-
key: tools-${{ runner.os }}-${{ hashFiles('./internal/tools/go.mod') }}
431+
key: tools-${{ runner.os }}-${{ hashFiles('./internal/tools/go.mod', './cmd/mdatagen/go.mod', './cmd/mdatagen/*.go') }}
418432
- name: Download Binaries
419433
uses: actions/download-artifact@v1
420434
with:
@@ -474,7 +488,7 @@ jobs:
474488
cache-name: cache-tool-binaries
475489
with:
476490
path: /home/runner/go/bin
477-
key: tools-${{ runner.os }}-${{ hashFiles('./internal/tools/go.mod') }}
491+
key: tools-${{ runner.os }}-${{ hashFiles('./internal/tools/go.mod', './cmd/mdatagen/go.mod', './cmd/mdatagen/*.go') }}
478492
- name: Download Binaries
479493
uses: actions/download-artifact@v1
480494
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)