Skip to content

Commit fb6ce10

Browse files
authored
Refactor Go CI workflow for better structure and coverage
1 parent 2ca7151 commit fb6ce10

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

.github/workflows/go.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Go CI / Test / Lint
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
ci:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
go-version: [1.20, 1.21]
16+
17+
steps:
18+
# Checkout code
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
# Go setup
23+
- name: Setup Go
24+
uses: actions/setup-go@v4
25+
with:
26+
go-version: ${{ matrix.go-version }}
27+
28+
# Cache modules and build cache
29+
- name: Cache Go build & modules
30+
uses: actions/cache@v3
31+
with:
32+
path: |
33+
~/.cache/go-build
34+
~/go/pkg/mod
35+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
36+
restore-keys: |
37+
${{ runner.os }}-go-
38+
39+
# Ensure dependencies
40+
- name: Go mod tidy
41+
run: go mod tidy
42+
43+
# Lint
44+
- name: Run golangci-lint
45+
uses: golangci/golangci-lint-action@v4
46+
with:
47+
version: v1.59.0
48+
args: run --timeout 5m
49+
50+
# Build
51+
- name: Build code
52+
run: go build -v ./...
53+
54+
# Test + coverage
55+
- name: Run tests with coverage
56+
run: |
57+
go test ./... -coverprofile=coverage.out -failfast -timeout=30s
58+
go tool cover -func=coverage.out
59+
60+
# Upload coverage report (optional)
61+
- name: Upload coverage to Codecov
62+
if: github.event_name != 'pull_request'
63+
uses: codecov/codecov-action@v4
64+
with:
65+
files: coverage.out

0 commit comments

Comments
 (0)