From abf542f41049ae3de3f581a37ea32d36c8a23828 Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Thu, 1 Oct 2026 10:25:17 -0700 Subject: [PATCH 1/2] ci: keep the Go build cache current actions/setup-go keys its cache on the Go version and go.sum only. The first job to finish after a new Go release or a go.sum change saves the entry, and every later run hits that key and skips saving. Master CI is still restoring the entries saved on 2026-09-11 (Go 1.27.1), so everything that changed since then recompiles in every run. Replace it with actions/cache restore/save, keyed per OS, architecture, Go version and job. Each run restores the newest cache saved for its key prefix, and runs other than pull requests save a new entry for the commit, so the cache tracks master. Pull requests only restore, which keeps the repository's cache storage bounded. A full race build cache compresses to about 80 MB. Claude-Session: https://claude.ai/code/session_01QKDYQr53zNKkR7nif2CAAq --- .github/workflows/checks.yml | 37 ++++++++++++++++++++++++++++ .github/workflows/echo.yml | 47 ++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 87342283a..0fbfa2418 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -21,6 +21,10 @@ env: # https://github.com/actions/setup-go/commit/924ae3a1cded613372ab5595356fb5720e22ba16 SETUP_GO_ACTION: &setup_go_action actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 + # https://github.com/actions/cache/commit/55cc8345863c7cc4c66a329aec7e433d2d1c52a9 + CACHE_RESTORE_ACTION: &cache_restore_action actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + CACHE_SAVE_ACTION: &cache_save_action actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + jobs: check: runs-on: ubuntu-latest @@ -33,6 +37,30 @@ jobs: with: go-version: ${{ env.LATEST_GO_VERSION }} check-latest: true + cache: false + + # setup-go's built-in cache is keyed on go.sum only, so its entry is never refreshed and + # soon holds little of the current build. Restore the latest cache saved for this job + # instead, and save a new one after runs other than pull requests, which only restore. + - name: Find Go Cache + id: go-cache + shell: bash + run: | + { + echo "build=$(go env GOCACHE)" + echo "mod=$(go env GOMODCACHE)" + echo "key=go-${{ runner.os }}-${{ runner.arch }}-$(go env GOVERSION)-${{ github.job }}" + } >> "$GITHUB_OUTPUT" + + - name: Restore Go Cache + id: go-cache-restore + uses: *cache_restore_action + with: + path: | + ${{ steps.go-cache.outputs.build }} + ${{ steps.go-cache.outputs.mod }} + key: ${{ steps.go-cache.outputs.key }}-${{ github.sha }} + restore-keys: ${{ steps.go-cache.outputs.key }}- - name: Run golint run: | @@ -49,3 +77,12 @@ jobs: go version go install golang.org/x/vuln/cmd/govulncheck@latest govulncheck ./... + + - name: Save Go Cache + if: github.event_name != 'pull_request' && steps.go-cache-restore.outputs.cache-hit != 'true' + uses: *cache_save_action + with: + path: | + ${{ steps.go-cache.outputs.build }} + ${{ steps.go-cache.outputs.mod }} + key: ${{ steps.go-cache.outputs.key }}-${{ github.sha }} diff --git a/.github/workflows/echo.yml b/.github/workflows/echo.yml index caaff30c0..9602e353f 100644 --- a/.github/workflows/echo.yml +++ b/.github/workflows/echo.yml @@ -21,6 +21,10 @@ env: # https://github.com/actions/setup-go/commit/924ae3a1cded613372ab5595356fb5720e22ba16 SETUP_GO_ACTION: &setup_go_action actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 + # https://github.com/actions/cache/commit/55cc8345863c7cc4c66a329aec7e433d2d1c52a9 + CACHE_RESTORE_ACTION: &cache_restore_action actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + CACHE_SAVE_ACTION: &cache_save_action actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + # https://github.com/codecov/codecov-action/commit/fb8b3582c8e4def4969c97caa2f19720cb33a72f CODECOV_ACTION: &codecov_action codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7 @@ -44,10 +48,46 @@ jobs: uses: *setup_go_action with: go-version: ${{ matrix.go }} + cache: false + + # setup-go's built-in cache is keyed on go.sum only, so its entry is never refreshed and + # soon holds little of the current build. Restore the latest cache saved for this job + # instead, and save a new one after runs other than pull requests, which only restore. + - &find_go_cache + name: Find Go Cache + id: go-cache + shell: bash + run: | + { + echo "build=$(go env GOCACHE)" + echo "mod=$(go env GOMODCACHE)" + echo "key=go-${{ runner.os }}-${{ runner.arch }}-$(go env GOVERSION)-${{ github.job }}" + } >> "$GITHUB_OUTPUT" + + - &restore_go_cache + name: Restore Go Cache + id: go-cache-restore + uses: *cache_restore_action + with: + path: | + ${{ steps.go-cache.outputs.build }} + ${{ steps.go-cache.outputs.mod }} + key: ${{ steps.go-cache.outputs.key }}-${{ github.sha }} + restore-keys: ${{ steps.go-cache.outputs.key }}- - name: Run Tests run: go test -race --coverprofile=coverage.coverprofile --covermode=atomic ./... + - &save_go_cache + name: Save Go Cache + if: github.event_name != 'pull_request' && steps.go-cache-restore.outputs.cache-hit != 'true' + uses: *cache_save_action + with: + path: | + ${{ steps.go-cache.outputs.build }} + ${{ steps.go-cache.outputs.mod }} + key: ${{ steps.go-cache.outputs.key }}-${{ github.sha }} + - name: Upload coverage to Codecov if: success() && matrix.go == env.LATEST_GO_VERSION && matrix.os == 'ubuntu-latest' uses: *codecov_action @@ -75,6 +115,11 @@ jobs: uses: *setup_go_action with: go-version: ${{ env.LATEST_GO_VERSION }} + cache: false + + - *find_go_cache + + - *restore_go_cache - name: Install Dependencies run: go install golang.org/x/perf/cmd/benchstat@latest @@ -92,3 +137,5 @@ jobs: - name: Run Benchstat run: | benchstat previous/benchmark.txt new/benchmark.txt + + - *save_go_cache From 64bd859b8aa0ac8c0c9b0229a4ec8a075469c22a Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Thu, 1 Oct 2026 15:21:00 -0700 Subject: [PATCH 2/2] ci: drop Go cache steps from the benchmark job Since #3140 the benchmark job runs only on pull requests, which never save a cache, so its restore would always miss. Claude-Session: https://claude.ai/code/session_01QKDYQr53zNKkR7nif2CAAq --- .github/workflows/echo.yml | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/.github/workflows/echo.yml b/.github/workflows/echo.yml index 1a744d2ee..d38a87514 100644 --- a/.github/workflows/echo.yml +++ b/.github/workflows/echo.yml @@ -58,8 +58,7 @@ jobs: # setup-go's built-in cache is keyed on go.sum only, so its entry is never refreshed and # soon holds little of the current build. Restore the latest cache saved for this job # instead, and save a new one after runs other than pull requests, which only restore. - - &find_go_cache - name: Find Go Cache + - name: Find Go Cache id: go-cache shell: bash run: | @@ -69,8 +68,7 @@ jobs: echo "key=go-${{ runner.os }}-${{ runner.arch }}-$(go env GOVERSION)-${{ github.job }}" } >> "$GITHUB_OUTPUT" - - &restore_go_cache - name: Restore Go Cache + - name: Restore Go Cache id: go-cache-restore uses: *cache_restore_action with: @@ -83,8 +81,7 @@ jobs: - name: Run Tests run: go test -race --coverprofile=coverage.coverprofile --covermode=atomic ./... - - &save_go_cache - name: Save Go Cache + - name: Save Go Cache if: github.event_name != 'pull_request' && steps.go-cache-restore.outputs.cache-hit != 'true' uses: *cache_save_action with: @@ -125,10 +122,6 @@ jobs: go-version: ${{ env.LATEST_GO_VERSION }} cache: false - - *find_go_cache - - - *restore_go_cache - - name: Install Dependencies run: go install golang.org/x/perf/cmd/benchstat@latest @@ -148,4 +141,3 @@ jobs: run: | benchstat previous/benchmark.txt new/benchmark.txt - - *save_go_cache