File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments