From 5c1c1cea9ef2e3a24474253ed27e73adea3f95d1 Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Wed, 24 Feb 2021 10:14:48 -0800 Subject: [PATCH] Improve caching for go actions, add go build cache (#2519) Signed-off-by: Bogdan Drutu --- .github/workflows/build-and-test.yml | 74 +++++++++++++++++----------- Makefile | 8 +++ Makefile.Common | 1 - 3 files changed, 52 insertions(+), 31 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index c078fbe3f96..be211795bd7 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -23,13 +23,15 @@ jobs: echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV echo "$(go env GOPATH)/bin" >> $GITHUB_PATH shell: bash - - name: Cache Go Modules + - name: Cache Go uses: actions/cache@v2 env: cache-name: cache-go-modules with: - path: \Users\runneradmin\go\pkg\mod - key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('./go.mod') }} + path: | + \Users\runneradmin\go\pkg\mod + %LocalAppData%\go-build + key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('./go.mod', '**/go.sum') }} - name: Run Unit tests run: go test ./... - name: GitHub Issue Generator @@ -51,17 +53,21 @@ jobs: run: | echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV echo "$(go env GOPATH)/bin" >> $GITHUB_PATH - - name: Cache Go Modules + - name: Cache Go id: module-cache uses: actions/cache@v2 env: cache-name: cache-go-modules with: - path: /home/runner/go/pkg/mod - key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('**/go.mod') }} - - name: Download dependencies + path: | + /home/runner/go/pkg/mod + /home/runner/.cache/go-build + key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('**/go.mod', '**/go.sum') }} + - name: Install dependencies if: steps.module-cache.outputs.cache-hit != 'true' - run: go mod download + run: | + make gomoddownload + make gotestinstall - name: Cache Tools id: tool-cache uses: actions/cache@v2 @@ -90,13 +96,16 @@ jobs: run: | echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV echo "$(go env GOPATH)/bin" >> $GITHUB_PATH - - name: Cache Go Modules + - name: Cache Go + id: module-cache uses: actions/cache@v2 env: cache-name: cache-go-modules with: - path: /home/runner/go/pkg/mod - key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('./go.mod') }} + path: | + /home/runner/go/pkg/mod + /home/runner/.cache/go-build + key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('**/go.mod', '**/go.sum') }} - name: Cache Tools id: tool-cache uses: actions/cache@v2 @@ -129,13 +138,16 @@ jobs: run: | echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV echo "$(go env GOPATH)/bin" >> $GITHUB_PATH - - name: Cache Go Modules + - name: Cache Go + id: module-cache uses: actions/cache@v2 env: cache-name: cache-go-modules with: - path: /home/runner/go/pkg/mod - key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('./go.mod') }} + path: | + /home/runner/go/pkg/mod + /home/runner/.cache/go-build + key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('**/go.mod', '**/go.sum') }} - name: Cache Tools id: tool-cache uses: actions/cache@v2 @@ -170,13 +182,16 @@ jobs: run: | echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV echo "$(go env GOPATH)/bin" >> $GITHUB_PATH - - name: Cache Go Modules + - name: Cache Go + id: module-cache uses: actions/cache@v2 env: cache-name: cache-go-modules with: - path: /home/runner/go/pkg/mod - key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('./go.mod') }} + path: | + /home/runner/go/pkg/mod + /home/runner/.cache/go-build + key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('**/go.mod', '**/go.sum') }} - name: Cache Tools id: tool-cache uses: actions/cache@v2 @@ -211,13 +226,16 @@ jobs: run: | echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV echo "$(go env GOPATH)/bin" >> $GITHUB_PATH - - name: Cache Go Modules + - name: Cache Go + id: module-cache uses: actions/cache@v2 env: cache-name: cache-go-modules with: - path: /home/runner/go/pkg/mod - key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('./go.mod') }} + path: | + /home/runner/go/pkg/mod + /home/runner/.cache/go-build + key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('**/go.mod', '**/go.sum') }} - name: Cache Tools id: tool-cache uses: actions/cache@v2 @@ -267,13 +285,16 @@ jobs: run: | echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV echo "$(go env GOPATH)/bin" >> $GITHUB_PATH - - name: Cache Go Modules + - name: Cache Go + id: module-cache uses: actions/cache@v2 env: cache-name: cache-go-modules with: - path: /home/runner/go/pkg/mod - key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('./go.mod') }} + path: | + /home/runner/go/pkg/mod + /home/runner/.cache/go-build + key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('**/go.mod', '**/go.sum') }} - name: Cache Tools id: tool-cache uses: actions/cache@v2 @@ -365,13 +386,6 @@ jobs: echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV echo "$(go env GOPATH)/bin" >> $GITHUB_PATH mkdir bin/ - - name: Cache Go Modules - uses: actions/cache@v2 - env: - cache-name: cache-go-modules - with: - path: \Users\runneradmin\go\pkg\mod - key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('./go.mod') }} - name: Download Binaries uses: actions/download-artifact@v1 with: diff --git a/Makefile b/Makefile index d798152f5f9..c3b5384391d 100644 --- a/Makefile +++ b/Makefile @@ -80,6 +80,14 @@ testbed-list-correctness-metrics: testbed-correctness-metrics: otelcol cd ./testbed/correctness/metrics && ./runtests.sh +.PHONY: gomoddownload +gomoddownload: + @$(MAKE) for-all CMD="go mod download" + +.PHONY: gotestinstall +gotestinstall: + @$(MAKE) for-all CMD="make test GOTEST_OPT=\"-i\"" + .PHONY: gotest gotest: @$(MAKE) for-all CMD="make test" diff --git a/Makefile.Common b/Makefile.Common index cfa9892c93b..ae66699e9a4 100644 --- a/Makefile.Common +++ b/Makefile.Common @@ -27,7 +27,6 @@ all-license-srcs: .PHONY: test test: - @echo "running go unit test ./... in `pwd`" @echo $(ALL_PKGS) | xargs -n 10 $(GOTEST) $(GOTEST_OPT) .PHONY: benchmark