Skip to content

Commit 1000cfd

Browse files
committed
Add GitHub Actions CI workflow
- Run tests on Go 1.20, 1.21, 1.22, 1.23 - Upload coverage to Codecov - Run go vet and format checks - Run benchmarks
1 parent ea60adc commit 1000cfd

1 file changed

Lines changed: 102 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master, main, v*]
6+
pull_request:
7+
branches: [master, main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
go-version: ['1.20', '1.21', '1.22', '1.23']
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v5
21+
with:
22+
go-version: ${{ matrix.go-version }}
23+
24+
- name: Cache Go modules
25+
uses: actions/cache@v4
26+
with:
27+
path: |
28+
~/.cache/go-build
29+
~/go/pkg/mod
30+
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
31+
restore-keys: |
32+
${{ runner.os }}-go-${{ matrix.go-version }}-
33+
34+
- name: Test
35+
run: go test -v ./...
36+
37+
- name: Test with Coverage
38+
run: go test -coverprofile=coverage.out ./...
39+
40+
- name: Upload Coverage
41+
if: matrix.go-version == '1.22'
42+
uses: codecov/codecov-action@v4
43+
with:
44+
file: ./coverage.out
45+
flags: unittests
46+
name: codecov-umbrella
47+
fail_ci_if_error: false
48+
49+
lint:
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@v4
53+
54+
- name: Set up Go
55+
uses: actions/setup-go@v5
56+
with:
57+
go-version: '1.22'
58+
59+
- name: Run go vet
60+
run: go vet ./...
61+
62+
- name: Check formatting
63+
run: |
64+
if ! gofmt -d . | grep -q .; then
65+
echo "Code is properly formatted"
66+
else
67+
echo "Code needs formatting"
68+
gofmt -d .
69+
exit 1
70+
fi
71+
72+
- name: Run staticcheck
73+
uses: dominantv/ci-staticcheck-action@latest
74+
with:
75+
version: latest
76+
packages: ./...
77+
flags: -checks=all
78+
79+
benchmark:
80+
runs-on: ubuntu-latest
81+
steps:
82+
- uses: actions/checkout@v4
83+
84+
- name: Set up Go
85+
uses: actions/setup-go@v5
86+
with:
87+
go-version: '1.22'
88+
89+
- name: Run benchmarks
90+
run: go test -bench=. -benchmem ./...
91+
92+
- name: Upload benchmark results
93+
uses: benchmark-action/github-action-benchmark@v1
94+
with:
95+
name: Go Benchmark
96+
tool: 'go'
97+
output-file-path: bench.txt
98+
github-pages: false
99+
alert-threshold: '200%'
100+
fail-on-alert: false
101+
env:
102+
BENCHMARK_FLAG: '-bench=. -benchmem'

0 commit comments

Comments
 (0)