Skip to content

Commit e52681b

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

File tree

5 files changed

+338
-0
lines changed

5 files changed

+338
-0
lines changed

.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$

Makefile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Default target
2+
.DEFAULT_GOAL := help
3+
4+
# Binary name
5+
BINARY_NAME=stackrox-mcp
6+
7+
# Go parameters
8+
GOCMD=go
9+
GOBUILD=$(GOCMD) build
10+
GOTEST=$(GOCMD) test
11+
GOFMT=$(GOCMD) fmt
12+
GOCLEAN=$(GOCMD) clean
13+
14+
# Coverage files
15+
COVERAGE_OUT=coverage.out
16+
17+
# Lint files
18+
LINT_OUT=report.xml
19+
20+
.PHONY: help
21+
help: ## Display this help message
22+
@echo "Available targets:"
23+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
24+
25+
.PHONY: build
26+
build: ## Build the binary
27+
$(GOBUILD) -o $(BINARY_NAME) ./cmd/stackrox-mcp
28+
29+
.PHONY: test
30+
test: ## Run unit tests with coverage
31+
$(GOTEST) -v -cover -coverprofile=$(COVERAGE_OUT) ./...
32+
33+
.PHONY: fmt
34+
fmt: ## Format Go code
35+
$(GOFMT) ./...
36+
37+
.PHONY: fmt-check
38+
fmt-check: ## Check if Go code is formatted (fails if not)
39+
@if [ -n "$$(gofmt -l .)" ]; then \
40+
echo "The following files are not formatted:"; \
41+
gofmt -l .; \
42+
exit 1; \
43+
fi
44+
45+
.PHONY: lint
46+
lint: ## Run golangci-lint
47+
go install -v "github.com/golangci/golangci-lint/v2/cmd/[email protected]"
48+
golangci-lint run
49+
50+
.PHONY: clean
51+
clean: ## Clean build artifacts and coverage files
52+
$(GOCLEAN)
53+
rm -f $(BINARY_NAME)
54+
rm -f $(COVERAGE_OUT)
55+
rm -f $(LINT_OUT)

0 commit comments

Comments
 (0)