Skip to content

Commit a7e8437

Browse files
authored
Updated README and improved CI (#57)
1 parent e8d7560 commit a7e8437

13 files changed

Lines changed: 361 additions & 179 deletions

File tree

.github/workflows/test.yml

Lines changed: 124 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,130 @@ permissions:
1212
pull-requests: write
1313

1414
jobs:
15-
test:
15+
lint:
16+
name: Lint
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Install Go
23+
uses: actions/setup-go@v5
24+
with:
25+
go-version: 1.23.x
26+
cache: true
27+
28+
- name: Run golangci-lint
29+
uses: golangci/golangci-lint-action@v7
30+
with:
31+
version: v2.6.0
32+
33+
format:
34+
name: Format Check
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Checkout code
38+
uses: actions/checkout@v4
39+
40+
- name: Install Go
41+
uses: actions/setup-go@v5
42+
with:
43+
go-version: 1.23.x
44+
cache: true
45+
46+
- name: Check formatting
47+
run: |
48+
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
49+
echo "The following files are not formatted:"
50+
gofmt -s -l .
51+
exit 1
52+
fi
53+
54+
vet:
55+
name: Static Analysis
56+
runs-on: ubuntu-latest
57+
steps:
58+
- name: Checkout code
59+
uses: actions/checkout@v4
60+
61+
- name: Install Go
62+
uses: actions/setup-go@v5
63+
with:
64+
go-version: 1.23.x
65+
cache: true
66+
67+
- name: Run go vet
68+
run: go vet ./...
69+
70+
unit-tests:
71+
name: Unit Tests
1672
runs-on: ubuntu-latest
73+
steps:
74+
- name: Checkout code
75+
uses: actions/checkout@v4
76+
77+
- name: Install Go
78+
uses: actions/setup-go@v5
79+
with:
80+
go-version: 1.23.x
81+
cache: true
82+
83+
- name: Add dependencies
84+
run: |
85+
sudo apt-get update
86+
sudo apt-get install rsyslog -y
87+
sudo service rsyslog start
1788
89+
- name: Run tests with coverage
90+
run: |
91+
go install gotest.tools/gotestsum@latest
92+
mkdir -p test-reports
93+
gotestsum --junitfile test-reports/unit-tests.xml -- -coverprofile=coverage.out -covermode=atomic ./...
94+
95+
- name: Upload coverage to Codecov
96+
uses: codecov/codecov-action@v4
97+
with:
98+
files: ./coverage.out
99+
flags: unittests
100+
fail_ci_if_error: false
101+
102+
- name: Publish Unit Test Results
103+
uses: EnricoMi/publish-unit-test-result-action@v2
104+
if: always()
105+
with:
106+
files: test-reports/unit-tests.xml
107+
108+
race:
109+
name: Race Detection
110+
runs-on: ubuntu-latest
111+
steps:
112+
- name: Checkout code
113+
uses: actions/checkout@v4
114+
115+
- name: Install Go
116+
uses: actions/setup-go@v5
117+
with:
118+
go-version: 1.23.x
119+
cache: true
120+
121+
- name: Add dependencies
122+
run: |
123+
sudo apt-get update
124+
sudo apt-get install rsyslog -y
125+
sudo service rsyslog start
126+
127+
- name: Run tests with race detector
128+
run: go test -race -short ./...
129+
130+
# This is the job that branch protection looks for
131+
test:
132+
runs-on: ubuntu-latest
133+
needs: [lint, format, vet, unit-tests, race]
134+
if: always()
18135
steps:
19-
- name: Checkout code
20-
uses: actions/checkout@v2
21-
22-
- name: Install Go
23-
uses: actions/setup-go@v2
24-
with:
25-
go-version: 1.23.x
26-
27-
- name: Add dependencies
28-
run: |
29-
sudo apt-get update
30-
sudo apt-get install rsyslog -y
31-
sudo service rsyslog start
32-
33-
- name: Run tests
34-
run: |
35-
go install gotest.tools/gotestsum@latest
36-
mkdir -p test-reports
37-
gotestsum --junitfile test-reports/unit-tests.xml
38-
39-
- name: Publish Unit Test Results
40-
uses: EnricoMi/publish-unit-test-result-action@v1
41-
if: always()
42-
with:
43-
files: test-reports/unit-tests.xml
136+
- name: All checks passed
137+
if: ${{ !(contains(needs.*.result, 'failure')) }}
138+
run: exit 0
139+
- name: Some checks failed
140+
if: ${{ contains(needs.*.result, 'failure') }}
141+
run: exit 1

.golangci.yml

Lines changed: 57 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,73 @@
11
version: "2"
2-
32
linters:
4-
disable-all: true
3+
default: none
54
enable:
65
- bidichk
76
- errcheck
87
- govet
98
- ineffassign
109
- makezero
1110
- misspell
12-
# - revive # Disabled for now - will enable specific rules in future PR
11+
- revive
1312
- staticcheck
1413
- unconvert
1514
- unused
1615
- whitespace
17-
18-
linters-settings:
19-
govet:
20-
enable-all: true
21-
disable:
22-
- fieldalignment
23-
16+
settings:
17+
govet:
18+
disable:
19+
- fieldalignment
20+
enable-all: true
21+
exclusions:
22+
generated: lax
23+
presets:
24+
- comments
25+
- std-error-handling
26+
rules:
27+
# Exclude test files from certain checks
28+
- linters:
29+
- errcheck
30+
- unused
31+
- govet
32+
path: _test\.go
33+
# Exclude generated mock files
34+
- linters:
35+
- revive
36+
- staticcheck
37+
path: mock_.*\.go
38+
# Exclude test helper files from errcheck
39+
- linters:
40+
- errcheck
41+
path: test/.*\.go
42+
# Exclude common revive warnings that are acceptable in this codebase
43+
- linters:
44+
- revive
45+
text: "unused-parameter|indent-error-flow|receiver-naming|var-naming"
46+
# Exclude stuttering names in test package (TestMetrics, etc)
47+
- linters:
48+
- revive
49+
path: test/
50+
text: "exported.*stutters"
51+
paths:
52+
- third_party$
53+
- vendor$
54+
formatters:
55+
enable:
56+
- gofmt
57+
- goimports
58+
settings:
59+
gofmt:
60+
simplify: true
61+
# Disable interface{} -> any rewrite for now; can enable in future PR
62+
# rewrite-rules:
63+
# - pattern: interface{}
64+
# replacement: any
65+
exclusions:
66+
generated: lax
67+
paths:
68+
- third_party$
69+
- vendor$
70+
- mock.*
2471
issues:
2572
max-issues-per-linter: 0
2673
max-same-issues: 0
27-
exclude-rules:
28-
# Exclude test files from certain checks
29-
- path: _test\.go
30-
linters:
31-
- errcheck
32-
- unused
33-
# Exclude generated files
34-
- path: mock_.*\.go
35-
linters:
36-
- revive
37-
- staticcheck
38-
# Exclude test helper files from errcheck
39-
- path: test/.*\.go
40-
linters:
41-
- errcheck
42-
43-
run:
44-
timeout: 5m
45-
tests: true
46-
build-tags: []
47-
skip-dirs:
48-
- vendor
49-
- third_party
50-
51-
output:
52-
format: colored-line-number
53-
print-issued-lines: true
54-
print-linter-name: true
55-
sort-results: true

0 commit comments

Comments
 (0)