Skip to content

Commit 5da5df4

Browse files
authored
ci: align workflows with labstack/echo (#43)
* 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 * 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
1 parent 2784e7c commit 5da5df4

2 files changed

Lines changed: 98 additions & 8 deletions

File tree

‎.github/workflows/checks.yml‎

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Run checks
1+
name: Checks
22

33
on:
44
push:
@@ -12,16 +12,24 @@ on:
1212
permissions:
1313
contents: read # to fetch code (actions/checkout)
1414

15+
# Cancel superseded runs of the same pull request; runs on main always finish.
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
18+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
19+
1520
env:
16-
# run static analysis only with the latest Go version
17-
LATEST_GO_VERSION: "1.26"
21+
LATEST_GO_VERSION: "1.27"
1822

1923
# https://github.com/actions/checkout/commit/df4cb1c069e1874edd31b4311f1884172cec0e10
2024
CHECKOUT_ACTION: &checkout_action actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
2125

2226
# https://github.com/actions/setup-go/commit/924ae3a1cded613372ab5595356fb5720e22ba16
2327
SETUP_GO_ACTION: &setup_go_action actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6
2428

29+
# https://github.com/actions/cache/commit/55cc8345863c7cc4c66a329aec7e433d2d1c52a9
30+
CACHE_RESTORE_ACTION: &cache_restore_action actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
31+
CACHE_SAVE_ACTION: &cache_save_action actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
32+
2533
jobs:
2634
check:
2735
runs-on: ubuntu-latest
@@ -34,6 +42,30 @@ jobs:
3442
with:
3543
go-version: ${{ env.LATEST_GO_VERSION }}
3644
check-latest: true
45+
cache: false
46+
47+
# setup-go's built-in cache is keyed on go.sum only, so its entry is never refreshed and
48+
# soon holds little of the current build. Restore the latest cache saved for this job
49+
# instead, and save a new one after runs other than pull requests, which only restore.
50+
- name: Find Go Cache
51+
id: go-cache
52+
shell: bash
53+
run: |
54+
{
55+
echo "build=$(go env GOCACHE)"
56+
echo "mod=$(go env GOMODCACHE)"
57+
echo "key=go-${{ runner.os }}-${{ runner.arch }}-$(go env GOVERSION)-${{ github.job }}"
58+
} >> "$GITHUB_OUTPUT"
59+
60+
- name: Restore Go Cache
61+
id: go-cache-restore
62+
uses: *cache_restore_action
63+
with:
64+
path: |
65+
${{ steps.go-cache.outputs.build }}
66+
${{ steps.go-cache.outputs.mod }}
67+
key: ${{ steps.go-cache.outputs.key }}-${{ github.sha }}
68+
restore-keys: ${{ steps.go-cache.outputs.key }}-
3769

3870
- name: Run golint
3971
run: |
@@ -50,3 +82,12 @@ jobs:
5082
go version
5183
go install golang.org/x/vuln/cmd/govulncheck@latest
5284
govulncheck ./...
85+
86+
- name: Save Go Cache
87+
if: github.event_name != 'pull_request' && steps.go-cache-restore.outputs.cache-hit != 'true'
88+
uses: *cache_save_action
89+
with:
90+
path: |
91+
${{ steps.go-cache.outputs.build }}
92+
${{ steps.go-cache.outputs.mod }}
93+
key: ${{ steps.go-cache.outputs.key }}-${{ github.sha }}
Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Run Tests
1+
name: CI
22

33
on:
44
push:
@@ -12,15 +12,24 @@ on:
1212
permissions:
1313
contents: read # to fetch code (actions/checkout)
1414

15+
# Cancel superseded runs of the same pull request; runs on main always finish.
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
18+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
19+
1520
env:
16-
LATEST_GO_VERSION: "1.26"
21+
LATEST_GO_VERSION: "1.27"
1722

1823
# https://github.com/actions/checkout/commit/df4cb1c069e1874edd31b4311f1884172cec0e10
1924
CHECKOUT_ACTION: &checkout_action actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
2025

2126
# https://github.com/actions/setup-go/commit/924ae3a1cded613372ab5595356fb5720e22ba16
2227
SETUP_GO_ACTION: &setup_go_action actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6
2328

29+
# https://github.com/actions/cache/commit/55cc8345863c7cc4c66a329aec7e433d2d1c52a9
30+
CACHE_RESTORE_ACTION: &cache_restore_action actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
31+
CACHE_SAVE_ACTION: &cache_save_action actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
32+
2433
# https://github.com/codecov/codecov-action/commit/fb8b3582c8e4def4969c97caa2f19720cb33a72f
2534
CODECOV_ACTION: &codecov_action codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7
2635

@@ -33,7 +42,7 @@ jobs:
3342
# Echo tests with last four major releases (unless there are pressing vulnerabilities)
3443
# As we depend on `golang.org/x/` libraries which only support the last 2 Go releases, we could have situations when
3544
# we derive from the last four major releases promise.
36-
go: ["1.25", "1.26"]
45+
go: ["1.25", "1.26", "1.27"]
3746
name: ${{ matrix.os }} @ Go ${{ matrix.go }}
3847
runs-on: ${{ matrix.os }}
3948
steps:
@@ -44,10 +53,43 @@ jobs:
4453
uses: *setup_go_action
4554
with:
4655
go-version: ${{ matrix.go }}
56+
cache: false
57+
58+
# setup-go's built-in cache is keyed on go.sum only, so its entry is never refreshed and
59+
# soon holds little of the current build. Restore the latest cache saved for this job
60+
# instead, and save a new one after runs other than pull requests, which only restore.
61+
- name: Find Go Cache
62+
id: go-cache
63+
shell: bash
64+
run: |
65+
{
66+
echo "build=$(go env GOCACHE)"
67+
echo "mod=$(go env GOMODCACHE)"
68+
echo "key=go-${{ runner.os }}-${{ runner.arch }}-$(go env GOVERSION)-${{ github.job }}"
69+
} >> "$GITHUB_OUTPUT"
70+
71+
- name: Restore Go Cache
72+
id: go-cache-restore
73+
uses: *cache_restore_action
74+
with:
75+
path: |
76+
${{ steps.go-cache.outputs.build }}
77+
${{ steps.go-cache.outputs.mod }}
78+
key: ${{ steps.go-cache.outputs.key }}-${{ github.sha }}
79+
restore-keys: ${{ steps.go-cache.outputs.key }}-
4780

4881
- name: Run Tests
4982
run: go test -race --coverprofile=coverage.coverprofile --covermode=atomic ./...
5083

84+
- name: Save Go Cache
85+
if: github.event_name != 'pull_request' && steps.go-cache-restore.outputs.cache-hit != 'true'
86+
uses: *cache_save_action
87+
with:
88+
path: |
89+
${{ steps.go-cache.outputs.build }}
90+
${{ steps.go-cache.outputs.mod }}
91+
key: ${{ steps.go-cache.outputs.key }}-${{ github.sha }}
92+
5193
- name: Upload coverage to Codecov
5294
if: success() && matrix.go == env.LATEST_GO_VERSION && matrix.os == 'ubuntu-latest'
5395
uses: *codecov_action
@@ -56,6 +98,9 @@ jobs:
5698
fail_ci_if_error: false
5799

58100
benchmark:
101+
# Compares the pull request against its base branch. github.base_ref is only set for
102+
# pull_request events, so on other events both checkouts would be the same commit.
103+
if: github.event_name == 'pull_request'
59104
needs: test
60105
name: Benchmark comparison
61106
runs-on: ubuntu-latest
@@ -75,20 +120,24 @@ jobs:
75120
uses: *setup_go_action
76121
with:
77122
go-version: ${{ env.LATEST_GO_VERSION }}
123+
cache: false
78124

79125
- name: Install Dependencies
80126
run: go install golang.org/x/perf/cmd/benchstat@latest
81127

128+
# -benchtime=100ms instead of the default 1s keeps the job to a few minutes. The
129+
# comparison is advisory: it reports differences but never fails the build.
82130
- name: Run Benchmark (Previous)
83131
run: |
84132
cd previous
85-
go test -run="-" -bench=".*" -count=8 ./... > benchmark.txt
133+
go test -run="-" -bench=".*" -benchtime=100ms -count=8 ./... > benchmark.txt
86134
87135
- name: Run Benchmark (New)
88136
run: |
89137
cd new
90-
go test -run="-" -bench=".*" -count=8 ./... > benchmark.txt
138+
go test -run="-" -bench=".*" -benchtime=100ms -count=8 ./... > benchmark.txt
91139
92140
- name: Run Benchstat
93141
run: |
94142
benchstat previous/benchmark.txt new/benchmark.txt
143+

0 commit comments

Comments
 (0)