Skip to content

Commit db86f0e

Browse files
committed
Add CI pipeline for testing and style checks
1 parent 09b834f commit db86f0e

File tree

7 files changed

+415
-18
lines changed

7 files changed

+415
-18
lines changed

.github/CONTRIBUTING.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,41 @@ Thank you for your interest in contributing to StackRox MCP! This document provi
88

99
All code must pass the following checks before being merged:
1010

11-
- **Formatting:** Run `go fmt ./...` to format your code
12-
- **Linting:** Run `golint ./...` to check for style issues
13-
- **Vetting:** Run `go vet ./...` to check for suspicious constructs
14-
- **Testing:** All tests must pass with `go test ./...`
11+
- **Formatting:** Run `make fmt` to format your code
12+
- **Format Check:** Run `make fmt-check` to verify code is formatted
13+
- **Linting:** Run `make lint` to check for style issues
14+
- **Testing:** All tests must pass with `make test`
1515

1616
These checks are automatically run in CI for all pull requests.
1717

18+
### Available Make Targets
19+
20+
View all available make commands:
21+
```bash
22+
make help
23+
```
24+
25+
Common development commands:
26+
- `make build` - Build the binary
27+
- `make test` - Run unit tests with coverage
28+
- `make coverage-html` - Generate and view HTML coverage report
29+
- `make fmt` - Format code
30+
- `make fmt-check` - Check code formatting (fails if not formatted)
31+
- `make lint` - Run golangci-lint
32+
- `make clean` - Clean build artifacts and coverage files
33+
1834
### Testing
1935

2036
- Write unit tests for all new functionality
2137
- Aim for 80% code coverage
22-
- All error paths tested
38+
- All error paths should be tested
2339
- Run tests with coverage:
2440
```bash
25-
go test -cover ./...
41+
make test
2642
```
27-
- Generate detailed coverage report:
43+
- Generate and view detailed coverage report:
2844
```bash
29-
go test -coverprofile=coverage.out ./...
30-
go tool cover -html=coverage.out
45+
make coverage-html
3146
```
3247

3348
## Pull Request Guidelines

.github/workflows/style.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Style
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
branches:
8+
- main
9+
pull_request:
10+
types:
11+
- opened
12+
- reopened
13+
- synchronize
14+
15+
jobs:
16+
style:
17+
name: Code Style Checks
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Go
25+
uses: actions/setup-go@v5
26+
with:
27+
go-version: '1.24'
28+
29+
- name: Check code formatting
30+
run: make fmt-check
31+
32+
- name: Run golangci-lint
33+
uses: golangci/golangci-lint-action@v8
34+
with:
35+
version: v2.6

.github/workflows/test.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
branches:
8+
- main
9+
pull_request:
10+
types:
11+
- opened
12+
- reopened
13+
- synchronize
14+
15+
jobs:
16+
test:
17+
name: Run Tests
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Go
25+
uses: actions/setup-go@v5
26+
with:
27+
go-version: '1.24'
28+
29+
- name: Download dependencies
30+
run: go mod download
31+
32+
- name: Run tests with coverage
33+
run: make test
34+
35+
# - name: Upload coverage to Codecov
36+
# uses: codecov/codecov-action@v4
37+
# with:
38+
# file: ./coverage.out
39+
# token: ${{ secrets.CODECOV_TOKEN }}
40+
# fail_ci_if_error: false

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88

99
# Build output
1010
/stackrox-mcp
11+
12+
# Lint output
13+
/report.xml

.golangci.yml

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
version: "2"
2+
run:
3+
timeout: 240m
4+
go: "1.24"
5+
build-tags:
6+
- integration
7+
- scanner_db_integration
8+
- sql_integration
9+
- test_e2e
10+
modules-download-mode: readonly
11+
output:
12+
formats:
13+
text:
14+
path: stdout
15+
junit-xml:
16+
path: report.xml
17+
linters:
18+
# please, do not use `enable-all`: it's deprecated and will be removed soon.
19+
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
20+
default: none
21+
enable:
22+
- asciicheck
23+
- copyloopvar
24+
- errcheck
25+
- forbidigo
26+
- gocritic
27+
- exptostd
28+
- gosec
29+
- govet
30+
- ineffassign
31+
- nolintlint
32+
- protogetter
33+
- revive # replaces golint
34+
- rowserrcheck
35+
- staticcheck
36+
- wrapcheck
37+
# - nakedret TODO: add in follow-up
38+
# - unconvert TODO: add in follow-up
39+
# - unparam TODO: add in follow-up
40+
# - unused // enabled in Makefile as it fails with release tag
41+
- usestdlibvars
42+
settings:
43+
errcheck:
44+
disable-default-exclusions: false
45+
check-type-assertions: false
46+
check-blank: false
47+
exclude-functions:
48+
- (*bytes.Buffer).WriteString
49+
- (*strings.Builder).WriteByte
50+
- (*strings.Builder).WriteRune
51+
- (*strings.Builder).WriteString
52+
- fmt.Fprint
53+
- fmt.Fprintf
54+
- fmt.Fprintln
55+
- fmt.Print
56+
- fmt.Printf
57+
- fmt.Println
58+
- github.com/stackrox/rox/pkg/utils.Should
59+
forbidigo:
60+
forbid:
61+
- pattern: ^print\(.*\)$
62+
- pattern: fmt\.Print.*(# Disallowed function used\. Use environments functions for printing or to a specific writer from environment\.InputOutput\(\)\.)?
63+
- pattern: os\.Stdout(# Disallowed output streams used\. Use environment\.InputOutput\(\).Out instead\.)?
64+
- pattern: os\.Stderr(# Disallowed output streams used\. Use environment\.InputOutput\(\).ErrOut instead\.)?
65+
- pattern: os\.Stdin(# Disallowed output streams used\. Use environment\.InputOutput\(\).In instead\.)?
66+
gocritic:
67+
disabled-checks:
68+
- appendAssign
69+
- argOrder
70+
- assignOp
71+
- captLocal
72+
- dupArg
73+
- elseif
74+
- exitAfterDefer
75+
- ifElseChain
76+
- mapKey
77+
- singleCaseSwitch
78+
- unlambda
79+
- wrapperFunc
80+
gosec:
81+
includes:
82+
- G101
83+
- G102
84+
- G103
85+
- G104
86+
- G106
87+
- G108
88+
- G109
89+
- G111
90+
- G201
91+
- G202
92+
- G203
93+
- G303
94+
- G307
95+
- G403
96+
- G502
97+
- G503
98+
- G504
99+
- G601
100+
govet:
101+
disable:
102+
- shadow
103+
- fieldalignment
104+
enable-all: true
105+
settings:
106+
printf:
107+
funcs:
108+
- Print
109+
- Printf
110+
- Println
111+
- Debug
112+
- Debugf
113+
- Info
114+
- Infof
115+
- Warn
116+
- Warnf
117+
- Error
118+
- Errorf
119+
- github.com/stackrox/rox/migrator/log.WritetoStderr
120+
- github.com/stackrox/rox/migrator/log.WritetoStderrf
121+
nolintlint:
122+
require-explanation: false
123+
require-specific: true
124+
allow-unused: false
125+
revive:
126+
rules:
127+
- name: package-comments
128+
disabled: true
129+
- name: error-strings
130+
disabled: true
131+
- name: unexported-return
132+
disabled: true
133+
staticcheck:
134+
checks:
135+
- all
136+
- -QF1001
137+
- -QF1002
138+
- -QF1003
139+
- -QF1006
140+
- -QF1007
141+
- -QF1008
142+
- -QF1009
143+
- -QF1011
144+
- -QF1012
145+
- -SA1019
146+
- -SA4001
147+
- -ST1000
148+
- -ST1001
149+
- -ST1003
150+
- -ST1005
151+
- -ST1017
152+
- -ST1019
153+
- -ST1020
154+
- -ST1021
155+
- -ST1022
156+
- -ST1023
157+
wrapcheck:
158+
ignore-sig-regexps:
159+
- \(\*github\.com\/stackrox\/rox\/pkg\/errorhelpers\.ErrorList\)\.ToError\(\)
160+
- backoff.Retry.*
161+
- concurrency\.WithLock.*
162+
- errox\..+\.CausedBy(f)?
163+
- policy\.NewErr.*
164+
- retry\.MakeRetryable
165+
- retry\.WithRetry
166+
- status\.Error
167+
- utils\.Should
168+
exclusions:
169+
generated: lax
170+
rules:
171+
- linters:
172+
- wrapcheck
173+
path: ^(central|compliance|integration-tests|local|migrator|operator|pkg|scanner|sensor/tests/helper|tests|tools|scale)/
174+
- linters:
175+
- forbidigo
176+
path: (central/graphql/schema/print|compliance|integration-tests|local|migrator|operator|pkg|scanner|sensor|tests|tools|scale|govulncheck|compliance/virtualmachines/agent)/
177+
- linters:
178+
- forbidigo
179+
path: roxctl/central/generate/interactive.go
180+
- linters:
181+
- forbidigo
182+
- wrapcheck
183+
path: _test\.go
184+
- linters:
185+
- forbidigo
186+
path: roxctl/common/io/io\.go # io.go will by default use os.Stdin/os.StdErr.
187+
paths:
188+
- pkg/complianceoperator/api
189+
- third_party$
190+
- builtin$
191+
- examples$
192+
issues:
193+
max-issues-per-linter: 0
194+
max-same-issues: 0
195+
formatters:
196+
enable:
197+
- gofmt
198+
- goimports
199+
exclusions:
200+
generated: lax
201+
paths:
202+
- pkg/complianceoperator/api
203+
- third_party$
204+
- builtin$
205+
- examples$

0 commit comments

Comments
 (0)