Skip to content

Commit 5ba24ac

Browse files
mrj0slashformotion
andauthored
update ci to use mise (#23)
* apply zizmor findings --------- Co-authored-by: slashformotion <slashformotion@protonmail.com>
1 parent 73b018d commit 5ba24ac

4 files changed

Lines changed: 190 additions & 128 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 7 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -9,132 +9,12 @@ on:
99
- main
1010

1111
jobs:
12-
test:
13-
runs-on: ubuntu-latest
12+
test-lint:
1413
strategy:
1514
matrix:
16-
go-version: [oldstable, stable]
17-
services:
18-
postgres:
19-
image: postgres:17.4
20-
ports:
21-
- 5444:5432
22-
options: >-
23-
--health-cmd pg_isready
24-
--health-interval 10s
25-
--health-timeout 5s
26-
--health-retries 5
27-
env:
28-
POSTGRES_PASSWORD: password
29-
steps:
30-
- uses: actions/checkout@v3
31-
- name: Set up Go
32-
uses: actions/setup-go@v4
33-
with:
34-
go-version: ${{ matrix.go-version }}
35-
- name: Cache Go modules
36-
uses: actions/cache@v3
37-
with:
38-
path: |
39-
~/.cache/go-build
40-
/go/pkg/mod
41-
key: go-mod-v4-${{ hashFiles('**/go.sum') }}
42-
- name: Install Dependencies
43-
run: go mod download
44-
- name: Run tests
45-
run: |
46-
mkdir -p /tmp/test-reports
47-
# gotestsum hash is version version v1.12.3
48-
go run gotest.tools/gotestsum@ddd0b05a6878e2e8257a2abe6e7df66cebc53d0e --junitfile /tmp/test-reports/unit-tests.xml
49-
make test-examples
50-
- uses: actions/upload-artifact@v4
51-
name: Upload test results
52-
with:
53-
name: test-reports-${{ matrix.go-version }}
54-
path: /tmp/test-reports
55-
- name: Update coverage report
56-
uses: ncruces/go-coverage-report@v0.3.0
57-
with:
58-
report: true
59-
chart: true
60-
amend: true
61-
if: |
62-
matrix.go-version == 'stable'
63-
continue-on-error: true
64-
65-
test-race:
66-
runs-on: ubuntu-latest
67-
strategy:
68-
matrix:
69-
go-version: [oldstable, stable]
70-
steps:
71-
- uses: actions/checkout@v3
72-
- name: Set up Go
73-
uses: actions/setup-go@v4
74-
with:
75-
go-version: ${{ matrix.go-version }}
76-
- name: Cache Go modules
77-
uses: actions/cache@v3
78-
with:
79-
path: |
80-
~/.cache/go-build
81-
/go/pkg/mod
82-
key: go-mod-v4-${{ hashFiles('**/go.sum') }}
83-
- name: Install Dependencies
84-
run: go mod download
85-
- name: Run tests with race detector
86-
run: make test-race
87-
88-
lint:
89-
runs-on: ubuntu-latest
90-
strategy:
91-
matrix:
92-
go-version: [oldstable, stable]
93-
steps:
94-
- uses: actions/checkout@v3
95-
- name: Set up Go
96-
uses: actions/setup-go@v4
97-
with:
98-
go-version: ${{ matrix.go-version }}
99-
- name: Cache Go modules
100-
uses: actions/cache@v3
101-
with:
102-
path: |
103-
~/.cache/go-build
104-
/go/pkg/mod
105-
key: go-mod-v4-${{ hashFiles('**/go.sum') }}
106-
- name: Install Dependencies
107-
run: go mod download
108-
- name: Install tooling
109-
run: make tooling
110-
- name: Linting
111-
run: make lint
112-
- name: Running vulncheck
113-
run: make vuln-check
114-
115-
fmt:
116-
runs-on: ubuntu-latest
117-
strategy:
118-
matrix:
119-
go-version: [oldstable, stable]
120-
steps:
121-
- uses: actions/checkout@v3
122-
- name: Set up Go
123-
uses: actions/setup-go@v4
124-
with:
125-
go-version: ${{ matrix.go-version }}
126-
- name: Cache Go modules
127-
uses: actions/cache@v3
128-
with:
129-
path: |
130-
~/.cache/go-build
131-
/go/pkg/mod
132-
key: go-mod-v4-${{ hashFiles('**/go.sum') }}
133-
- name: Install Dependencies
134-
run: go mod download
135-
- name: Install tooling
136-
run: make tooling
137-
- name: Running formatting
138-
run: |
139-
make fmt
140-
make has-changes
15+
go-version: [ "1.25", "1.24" ]
16+
uses: ./.github/workflows/lint-tests.yaml
17+
with:
18+
go-version: ${{ matrix.go-version }}
19+
permissions:
20+
contents: read

.github/workflows/lint-tests.yaml

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
name: CI
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
go-version:
7+
type: string
8+
required: true
9+
10+
jobs:
11+
preflight:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
gopath: ${{ steps.gopath.outputs.value }}
15+
go-mods-cache-key: ${{ steps.cache-keys.outputs.go-mods-cache-key }}
16+
go-bins-cache-key: ${{ steps.cache-keys.outputs.go-bins-cache-key }}
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
persist-credentials: false
21+
22+
- uses: jdx/mise-action@146a28175021df8ca24f8ee1828cc2a60f980bd5
23+
with:
24+
cache: true
25+
reshim: true
26+
tool_versions: |
27+
go ${{ inputs.go-version }}
28+
github_token: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: Get Go path
31+
id: gopath
32+
run: echo "value=$(go env GOPATH)" >> $GITHUB_OUTPUT
33+
34+
- name: Cache keys
35+
id: cache-keys
36+
run: |
37+
echo "go-mods-cache-key=go-mods-${{ runner.os }}-${{ hashFiles('**/go.sum') }}" >> $GITHUB_OUTPUT
38+
39+
- name: Cache Go mods
40+
id: go-mods-cache
41+
uses: actions/cache@v4
42+
with:
43+
lookup-only: true
44+
path: ${{ steps.gopath.outputs.value }}/pkg/mod
45+
key: ${{ steps.cache-keys.outputs.go-mods-cache-key }}
46+
47+
- name: 📥 Download dependencies
48+
if: steps.go-mods-cache.outputs.cache-hit != 'true'
49+
run: go mod download
50+
51+
test:
52+
runs-on: ubuntu-latest
53+
needs: preflight
54+
services:
55+
postgres:
56+
image: postgres:17.4
57+
ports:
58+
- 5444:5432
59+
options: >-
60+
--health-cmd pg_isready
61+
--health-interval 10s
62+
--health-timeout 5s
63+
--health-retries 5
64+
env:
65+
POSTGRES_PASSWORD: password
66+
steps:
67+
- uses: actions/checkout@v4
68+
with:
69+
persist-credentials: false
70+
- uses: jdx/mise-action@146a28175021df8ca24f8ee1828cc2a60f980bd5
71+
with:
72+
cache: true
73+
reshim: true
74+
tool_versions: |
75+
go ${{ inputs.go-version }}
76+
github_token: ${{ secrets.GITHUB_TOKEN }}
77+
- name: 💾 Cache Go mods
78+
uses: actions/cache@v4
79+
with:
80+
path: ${{ needs.preflight.outputs.gopath }}/pkg/mod
81+
key: ${{ needs.preflight.outputs.go-mods-cache-key }}
82+
fail-on-cache-miss: true
83+
- name: Run tests units
84+
run: |
85+
mkdir -p /tmp/test-reports
86+
gotestsum --junitfile /tmp/test-reports/unit-tests.xml
87+
- uses: actions/upload-artifact@v4
88+
name: Upload test results
89+
with:
90+
name: test-reports-${{ inputs.go-version }}
91+
path: /tmp/test-reports
92+
- name: Run Examples
93+
run: make test-examples
94+
95+
- name: Update coverage report
96+
uses: ncruces/go-coverage-report@aa507d98fb11c2b4dffa1b731e0786f50fd8ec93
97+
with:
98+
report: true
99+
chart: true
100+
amend: true
101+
if: |
102+
inputs.go-version == '1.25'
103+
continue-on-error: true
104+
105+
test-race:
106+
runs-on: ubuntu-latest
107+
needs: preflight
108+
steps:
109+
- uses: actions/checkout@v4
110+
with:
111+
persist-credentials: false
112+
- uses: jdx/mise-action@146a28175021df8ca24f8ee1828cc2a60f980bd5
113+
with:
114+
cache: true
115+
reshim: true
116+
tool_versions: |
117+
go ${{ inputs.go-version }}
118+
github_token: ${{ secrets.GITHUB_TOKEN }}
119+
- name: 💾 Cache Go mods
120+
uses: actions/cache@v4
121+
with:
122+
path: ${{ needs.preflight.outputs.gopath }}/pkg/mod
123+
key: ${{ needs.preflight.outputs.go-mods-cache-key }}
124+
fail-on-cache-miss: true
125+
- name: Run tests with race detector
126+
run: make test-race
127+
128+
lint:
129+
runs-on: ubuntu-latest
130+
needs: preflight
131+
steps:
132+
- uses: actions/checkout@v4
133+
with:
134+
persist-credentials: false
135+
- uses: jdx/mise-action@146a28175021df8ca24f8ee1828cc2a60f980bd5
136+
with:
137+
cache: true
138+
reshim: true
139+
tool_versions: |
140+
go ${{ inputs.go-version }}
141+
github_token: ${{ secrets.GITHUB_TOKEN }}
142+
- name: 💾 Cache Go mods
143+
uses: actions/cache@v4
144+
with:
145+
path: ${{ needs.preflight.outputs.gopath }}/pkg/mod
146+
key: ${{ needs.preflight.outputs.go-mods-cache-key }}
147+
fail-on-cache-miss: true
148+
- name: go vet
149+
run: mise vet
150+
- name: Running staticcheck
151+
run: mise static
152+
- name: Running vulncheck
153+
run: mise vuln
154+
155+
fmt:
156+
runs-on: ubuntu-latest
157+
needs: preflight
158+
steps:
159+
- uses: actions/checkout@v4
160+
with:
161+
persist-credentials: false
162+
- uses: jdx/mise-action@146a28175021df8ca24f8ee1828cc2a60f980bd5
163+
with:
164+
cache: true
165+
reshim: true
166+
tool_versions: |
167+
go ${{ inputs.go-version }}
168+
github_token: ${{ secrets.GITHUB_TOKEN }}
169+
- name: 💾 Cache Go mods
170+
uses: actions/cache@v4
171+
with:
172+
path: ${{ needs.preflight.outputs.gopath }}/pkg/mod
173+
key: ${{ needs.preflight.outputs.go-mods-cache-key }}
174+
fail-on-cache-miss: true
175+
- name: Running formatting
176+
run: |
177+
mise fmt
178+
mise has-changes

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ lint:
1717
staticcheck -checks=all ./...
1818

1919
fmt:
20-
go list -f '{{.Dir}}' ./... | xargs -I {} goimports -local $(BASE_PACKAGE) -w {}
20+
go fmt ./...
21+
goimports -l -w .
2122

2223
vuln-check:
2324
govulncheck ./...

mise.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ go = "1.25.1"
1010
"go:honnef.co/go/tools/cmd/staticcheck" = { version = "v0.6.1" }
1111
"go:golang.org/x/vuln/cmd/govulncheck" = { version = "v1.1.4" }
1212
"go:golang.org/x/tools/cmd/goimports" = { version = "v0.20.0" }
13+
"go:gotest.tools/gotestsum" = { version = "ddd0b05a6878e2e8257a2abe6e7df66cebc53d0e" }
1314

1415
[tasks]
1516
test = "go test ./..."
1617
vet = "go vet ./..."
1718
static = "staticcheck -checks=all ./..."
1819
vuln = "govulncheck ./..."
20+
fmt = "go fmt ./... && goimports -l -w ."
21+
has-changes = "git diff --exit-code --quiet HEAD --"

0 commit comments

Comments
 (0)