From b9ef19efe66455cc7b4d414abb95578755a9b08f Mon Sep 17 00:00:00 2001 From: tdakkota Date: Tue, 28 Mar 2023 14:21:45 +0300 Subject: [PATCH 1/4] ci: use manual caching (again) Setup readonly caches for linters. Separate cache for `coverage` and `test-examples` workflow. --- .github/workflows/ci.yml | 38 ++++++++++++-- .github/workflows/codeql-analysis.yml | 21 +++++++- .github/workflows/coverage.yml | 24 +++++++-- .github/workflows/lint.yml | 71 ++++++++++++++++++++++++--- .github/workflows/pr-extra.yml | 21 +++++++- 5 files changed, 159 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 64f627673..be4189260 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - flags: [ "" ] + flags: [""] arch: - amd64 runner: @@ -33,7 +33,23 @@ jobs: uses: actions/setup-go@v4 with: go-version: '1.20' - cache: true + cache: false + + - name: Get Go environment + id: go-env + run: | + echo "cache=$(go env GOCACHE)" >> $GITHUB_ENV + echo "modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV + + - name: Set up cache + uses: actions/cache@v3 + with: + path: | + ${{ env.cache }} + ${{ env.modcache }} + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- - name: Run tests env: @@ -60,7 +76,23 @@ jobs: uses: actions/setup-go@v4 with: go-version: '1.20' - cache: true + cache: false + + - name: Get Go environment + id: go-env + run: | + echo "cache=$(go env GOCACHE)" >> $GITHUB_ENV + echo "modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV + + - name: Set up cache + uses: actions/cache@v3 + with: + path: | + ${{ env.cache }} + ${{ env.modcache }} + key: test-examples-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + test-examples-${{ runner.os }}-go- - name: Run tests run: cd examples && go test ./... diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 1b6ed56f8..c80cd49bc 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -54,7 +54,26 @@ jobs: uses: actions/setup-go@v4 with: go-version: '1.20' - cache: true + cache: false + + - name: Get Go environment + id: go-env + run: | + echo "cache=$(go env GOCACHE)" >> $GITHUB_ENV + echo "modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV + + # Notice: we're using read-only cache. + # + # See https://github.com/actions/setup-go/issues/357#issuecomment-1486486358 + - name: Set up cache + uses: actions/cache/restore@v3 + with: + path: | + ${{ env.cache }} + ${{ env.modcache }} + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- - name: Remove examples run: rm -rf ./examples diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index ca18e1543..fe3899f2f 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -9,14 +9,30 @@ jobs: test: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v3 - - name: Install Go uses: actions/setup-go@v4 with: go-version: '1.20' - cache: true + cache: false + + - name: Get Go environment + id: go-env + run: | + echo "cache=$(go env GOCACHE)" >> $GITHUB_ENV + echo "modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV + + - name: Set up cache + uses: actions/cache/restore@v3 + with: + path: | + ${{ env.cache }} + ${{ env.modcache }} + key: coverage-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + coverage-${{ runner.os }}-go- + + - name: Checkout code + uses: actions/checkout@v3 - name: Download dependencies run: go mod download && go mod tidy diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 906ac53ed..6c116940c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -16,15 +16,34 @@ jobs: - name: Install Go uses: actions/setup-go@v4 with: - go-version: "1.20" - cache: true + go-version: '1.20' + cache: false + + - name: Get Go environment + id: go-env + run: | + echo "cache=$(go env GOCACHE)" >> $GITHUB_ENV + echo "modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV + + # Notice: we're using read-only cache. + # + # See https://github.com/actions/setup-go/issues/357#issuecomment-1486486358 + - name: Set up cache + uses: actions/cache/restore@v3 + with: + path: | + ${{ env.cache }} + ${{ env.modcache }} + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- - name: Lint uses: golangci/golangci-lint-action@v3 with: version: latest args: --timeout 5m - # Package/build cache already provided by actions/setup-go. + # Package/build cache already provided above. # # Disable module cache. skip-pkg-cache: true @@ -41,8 +60,27 @@ jobs: - name: Install Go uses: actions/setup-go@v4 with: - go-version: "1.20" - cache: true + go-version: '1.20' + cache: false + + - name: Get Go environment + id: go-env + run: | + echo "cache=$(go env GOCACHE)" >> $GITHUB_ENV + echo "modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV + + # Notice: we're using read-only cache. + # + # See https://github.com/actions/setup-go/issues/357#issuecomment-1486486358 + - name: Set up cache + uses: actions/cache/restore@v3 + with: + path: | + ${{ env.cache }} + ${{ env.modcache }} + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- - name: Download dependencies run: go mod download && go mod tidy @@ -60,8 +98,27 @@ jobs: - name: Install Go uses: actions/setup-go@v4 with: - go-version: "1.20" - cache: true + go-version: '1.20' + cache: false + + - name: Get Go environment + id: go-env + run: | + echo "cache=$(go env GOCACHE)" >> $GITHUB_ENV + echo "modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV + + # Notice: we're using read-only cache. + # + # See https://github.com/actions/setup-go/issues/357#issuecomment-1486486358 + - name: Set up cache + uses: actions/cache/restore@v3 + with: + path: | + ${{ env.cache }} + ${{ env.modcache }} + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- - name: Download dependencies run: go mod download && go mod tidy diff --git a/.github/workflows/pr-extra.yml b/.github/workflows/pr-extra.yml index c87f63be2..760ff5b8f 100644 --- a/.github/workflows/pr-extra.yml +++ b/.github/workflows/pr-extra.yml @@ -17,7 +17,26 @@ jobs: uses: actions/setup-go@v4 with: go-version: '1.20' - cache: true + cache: false + + - name: Get Go environment + id: go-env + run: | + echo "cache=$(go env GOCACHE)" >> $GITHUB_ENV + echo "modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV + + # Notice: we're using read-only cache. + # + # See https://github.com/actions/setup-go/issues/357#issuecomment-1486486358 + - name: Set up cache + uses: actions/cache/restore@v3 + with: + path: | + ${{ env.cache }} + ${{ env.modcache }} + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- - name: List dependencies run: go list -json -m all > go.list From a06b28c7818bfe37d876db96ff5b7ee01c2c8593 Mon Sep 17 00:00:00 2001 From: tdakkota Date: Tue, 28 Mar 2023 14:23:49 +0300 Subject: [PATCH 2/4] ci(cache): use `runner.arch` as part of key --- .github/workflows/ci.yml | 8 ++++---- .github/workflows/codeql-analysis.yml | 4 ++-- .github/workflows/coverage.yml | 7 ++----- .github/workflows/lint.yml | 12 ++++++------ .github/workflows/pr-extra.yml | 4 ++-- 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index be4189260..d44bdde92 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,9 +47,9 @@ jobs: path: | ${{ env.cache }} ${{ env.modcache }} - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + key: ${{ runner.os }}-${{ runner.arch }}-go-${{ hashFiles('**/go.sum') }} restore-keys: | - ${{ runner.os }}-go- + ${{ runner.os }}-${{ runner.arch }}-go- - name: Run tests env: @@ -90,9 +90,9 @@ jobs: path: | ${{ env.cache }} ${{ env.modcache }} - key: test-examples-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + key: test-examples-${{ runner.os }}-${{ runner.arch }}-go-${{ hashFiles('**/go.sum') }} restore-keys: | - test-examples-${{ runner.os }}-go- + test-examples-${{ runner.os }}-${{ runner.arch }}-go- - name: Run tests run: cd examples && go test ./... diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index c80cd49bc..3e8d6cf40 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -71,9 +71,9 @@ jobs: path: | ${{ env.cache }} ${{ env.modcache }} - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + key: ${{ runner.os }}-${{ runner.arch }}-go-${{ hashFiles('**/go.sum') }} restore-keys: | - ${{ runner.os }}-go- + ${{ runner.os }}-${{ runner.arch }}-go- - name: Remove examples run: rm -rf ./examples diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index fe3899f2f..433440601 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -27,16 +27,13 @@ jobs: path: | ${{ env.cache }} ${{ env.modcache }} - key: coverage-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + key: coverage-${{ runner.os }}-${{ runner.arch }}-go-${{ hashFiles('**/go.sum') }} restore-keys: | - coverage-${{ runner.os }}-go- + coverage-${{ runner.os }}-${{ runner.arch }}-go- - name: Checkout code uses: actions/checkout@v3 - - name: Download dependencies - run: go mod download && go mod tidy - - name: Run tests with coverage run: make coverage diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6c116940c..8cee2a5ac 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -34,9 +34,9 @@ jobs: path: | ${{ env.cache }} ${{ env.modcache }} - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + key: ${{ runner.os }}-${{ runner.arch }}-go-${{ hashFiles('**/go.sum') }} restore-keys: | - ${{ runner.os }}-go- + ${{ runner.os }}-${{ runner.arch }}-go- - name: Lint uses: golangci/golangci-lint-action@v3 @@ -78,9 +78,9 @@ jobs: path: | ${{ env.cache }} ${{ env.modcache }} - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + key: ${{ runner.os }}-${{ runner.arch }}-go-${{ hashFiles('**/go.sum') }} restore-keys: | - ${{ runner.os }}-go- + ${{ runner.os }}-${{ runner.arch }}-go- - name: Download dependencies run: go mod download && go mod tidy @@ -116,9 +116,9 @@ jobs: path: | ${{ env.cache }} ${{ env.modcache }} - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + key: ${{ runner.os }}-${{ runner.arch }}-go-${{ hashFiles('**/go.sum') }} restore-keys: | - ${{ runner.os }}-go- + ${{ runner.os }}-${{ runner.arch }}-go- - name: Download dependencies run: go mod download && go mod tidy diff --git a/.github/workflows/pr-extra.yml b/.github/workflows/pr-extra.yml index 760ff5b8f..415cd6b51 100644 --- a/.github/workflows/pr-extra.yml +++ b/.github/workflows/pr-extra.yml @@ -34,9 +34,9 @@ jobs: path: | ${{ env.cache }} ${{ env.modcache }} - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + key: ${{ runner.os }}-${{ runner.arch }}-go-${{ hashFiles('**/go.sum') }} restore-keys: | - ${{ runner.os }}-go- + ${{ runner.os }}-${{ runner.arch }}-go- - name: List dependencies run: go list -json -m all > go.list From 2db341daa6e7ba03b534b3452f584110de7e3445 Mon Sep 17 00:00:00 2001 From: tdakkota Date: Tue, 28 Mar 2023 14:28:49 +0300 Subject: [PATCH 3/4] ci: use bash shell on Windows --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d44bdde92..6cfcc3194 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,6 +37,7 @@ jobs: - name: Get Go environment id: go-env + shell: bash run: | echo "cache=$(go env GOCACHE)" >> $GITHUB_ENV echo "modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV From 3f91b124db7a3759ecdf0214ac89bb390a886933 Mon Sep 17 00:00:00 2001 From: tdakkota Date: Tue, 28 Mar 2023 14:55:55 +0300 Subject: [PATCH 4/4] ci: use separate cache for `-race` and `386` jobs --- .github/workflows/ci.yml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6cfcc3194..ea2b83581 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,15 +42,26 @@ jobs: echo "cache=$(go env GOCACHE)" >> $GITHUB_ENV echo "modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV + # Build cache key prefix, using runner OS and arch. + - name: Compute cache prefix + id: cache-prefix + shell: bash + env: + RUNNER_PREFIX: ${{ runner.os }}-${{ runner.arch }}-go + ARCH_PREFIX: ${{ matrix.arch != 'amd64' && format('-{0}', matrix.arch) || '' }} + RACE_PREFIX: ${{ contains(matrix.flags, '-race') && '-race' || '' }} + run: + echo "cache_prefix=$RUNNER_PREFIX$ARCH_PREFIX$RACE_PREFIX" >> $GITHUB_ENV + - name: Set up cache uses: actions/cache@v3 with: path: | ${{ env.cache }} ${{ env.modcache }} - key: ${{ runner.os }}-${{ runner.arch }}-go-${{ hashFiles('**/go.sum') }} + key: ${{ env.cache_prefix }}-${{ hashFiles('**/go.sum') }} restore-keys: | - ${{ runner.os }}-${{ runner.arch }}-go- + ${{ env.cache_prefix }}- - name: Run tests env: