From ed3314ea2e836de1f541418a2c33ef695afc04ee Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Thu, 1 Oct 2026 15:17:21 -0700 Subject: [PATCH 1/2] ci: align workflows with labstack/echo - Rename the test workflow to ci.yml ("CI"); the lint workflow is now "Checks". - Test with Go 1.25, 1.26 and 1.27, and run coverage, benchmarks and checks on 1.27. - Keep the Go build cache current: restore the newest cache for each OS, Go version and job, and save a new one on pushes (setup-go's cache is keyed on go.sum only and goes stale). - Run the benchmark comparison only on pull requests (github.base_ref is empty on pushes, so it compared the branch with itself), with -benchtime=100ms so it takes minutes instead of about 20. - Cancel superseded pull request runs. - Pin actions/cache to a commit, like the other actions. Claude-Session: https://claude.ai/code/session_01QKDYQr53zNKkR7nif2CAAq --- .github/workflows/checks.yml | 47 ++++++++++++++++++-- .github/workflows/{echo.yml => ci.yml} | 61 +++++++++++++++++++++++--- 2 files changed, 99 insertions(+), 9 deletions(-) rename .github/workflows/{echo.yml => ci.yml} (51%) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index ba04119..f4b6989 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -1,4 +1,4 @@ -name: Run checks +name: Checks on: push: @@ -12,9 +12,13 @@ on: permissions: contents: read # to fetch code (actions/checkout) +# Cancel superseded runs of the same pull request; runs on main always finish. +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + env: - # run static analysis only with the latest Go version - LATEST_GO_VERSION: "1.26" + LATEST_GO_VERSION: "1.27" # https://github.com/actions/checkout/commit/df4cb1c069e1874edd31b4311f1884172cec0e10 CHECKOUT_ACTION: &checkout_action actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 @@ -22,6 +26,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 @@ -34,6 +42,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: | @@ -50,3 +82,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/ci.yml similarity index 51% rename from .github/workflows/echo.yml rename to .github/workflows/ci.yml index 4c027db..39168ad 100644 --- a/.github/workflows/echo.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: Run Tests +name: CI on: push: @@ -12,8 +12,13 @@ on: permissions: contents: read # to fetch code (actions/checkout) +# Cancel superseded runs of the same pull request; runs on main always finish. +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + env: - LATEST_GO_VERSION: "1.26" + LATEST_GO_VERSION: "1.27" # https://github.com/actions/checkout/commit/df4cb1c069e1874edd31b4311f1884172cec0e10 CHECKOUT_ACTION: &checkout_action actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 @@ -21,6 +26,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 @@ -33,7 +42,7 @@ jobs: # Echo tests with last four major releases (unless there are pressing vulnerabilities) # As we depend on `golang.org/x/` libraries which only support the last 2 Go releases, we could have situations when # we derive from the last four major releases promise. - go: ["1.25", "1.26"] + go: ["1.25", "1.26", "1.27"] name: ${{ matrix.os }} @ Go ${{ matrix.go }} runs-on: ${{ matrix.os }} steps: @@ -44,10 +53,43 @@ 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. + - 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 Tests + - name: CI run: go test -race --coverprofile=coverage.coverprofile --covermode=atomic ./... + - 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 @@ -56,6 +98,9 @@ jobs: fail_ci_if_error: false benchmark: + # Compares the pull request against its base branch. github.base_ref is only set for + # pull_request events, so on other events both checkouts would be the same commit. + if: github.event_name == 'pull_request' needs: test name: Benchmark comparison runs-on: ubuntu-latest @@ -75,20 +120,24 @@ jobs: uses: *setup_go_action with: go-version: ${{ env.LATEST_GO_VERSION }} + cache: false - name: Install Dependencies run: go install golang.org/x/perf/cmd/benchstat@latest + # -benchtime=100ms instead of the default 1s keeps the job to a few minutes. The + # comparison is advisory: it reports differences but never fails the build. - name: Run Benchmark (Previous) run: | cd previous - go test -run="-" -bench=".*" -count=8 ./... > benchmark.txt + go test -run="-" -bench=".*" -benchtime=100ms -count=8 ./... > benchmark.txt - name: Run Benchmark (New) run: | cd new - go test -run="-" -bench=".*" -count=8 ./... > benchmark.txt + go test -run="-" -bench=".*" -benchtime=100ms -count=8 ./... > benchmark.txt - name: Run Benchstat run: | benchstat previous/benchmark.txt new/benchmark.txt + From 106b64867201056180c23d7ca21c1636153e9693 Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Thu, 1 Oct 2026 15:20:45 -0700 Subject: [PATCH 2/2] ci: restore the Run Tests step name The rename to ci.yml also renamed the test step; only the workflow is CI. Claude-Session: https://claude.ai/code/session_01QKDYQr53zNKkR7nif2CAAq --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 39168ad..f5d3cfb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,7 +78,7 @@ jobs: key: ${{ steps.go-cache.outputs.key }}-${{ github.sha }} restore-keys: ${{ steps.go-cache.outputs.key }}- - - name: CI + - name: Run Tests run: go test -race --coverprofile=coverage.coverprofile --covermode=atomic ./... - name: Save Go Cache