-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
94 lines (74 loc) · 2.63 KB
/
Copy pathMakefile
File metadata and controls
94 lines (74 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
COVERPROFILE := coverage.out
COVERAGE_MIN := 90
PKG := ./...
GO := go
# Pinned dev-tool versions (keep in sync with CLAUDE.md).
GOLANGCI_VERSION := v2.12.2
GOSEC_VERSION := latest
GOVULN_VERSION := latest
GITLEAKS_VERSION := latest
.PHONY: all check build fmt vet lint security gosec vuln secrets test coverage \
fuzz bench tidy tools hooks clean
## all: default target — run the full gate
all: check
## check: full quality gate (the same command CI runs)
check: tidy fmt vet lint security test
## build: the library must compile cleanly
build:
$(GO) build $(PKG)
## fmt: fail if any file is not gofmt-clean
fmt:
@files=$$(gofmt -l .); if [ -n "$$files" ]; then echo "gofmt needed:"; echo "$$files"; exit 1; fi
## vet: go vet
vet:
$(GO) vet $(PKG)
## lint: golangci-lint (v2)
lint:
golangci-lint run
## security: SAST + vulnerabilities + secret scan
security: gosec vuln secrets
gosec:
gosec -quiet ./...
vuln:
govulncheck ./...
secrets:
gitleaks detect --no-git --redact
## test: race detector + atomic coverage profile
test:
$(GO) test -race -covermode=atomic -coverprofile=$(COVERPROFILE) $(PKG)
## coverage: report coverage and fail below COVERAGE_MIN%
coverage: test
$(GO) tool cover -func=$(COVERPROFILE)
$(GO) tool cover -html=$(COVERPROFILE) -o coverage.html
@total=$$($(GO) tool cover -func=$(COVERPROFILE) | awk '/^total:/ {print $$3}' | tr -d '%'); \
if awk -v t="$$total" -v m="$(COVERAGE_MIN)" 'BEGIN { exit !(t+0 >= m+0) }'; then \
printf 'coverage %s%% meets the %s%% minimum\n' "$$total" "$(COVERAGE_MIN)"; \
else \
printf 'FAIL: coverage %s%% is below the %s%% minimum\n' "$$total" "$(COVERAGE_MIN)"; exit 1; \
fi
## fuzz: short fuzz run of the deserializer/lexer (skips until Fuzz* tests exist)
fuzz:
@if grep -rql '^func Fuzz' --include='*_test.go' .; then \
$(GO) test -run='^$$' -fuzz=Fuzz -fuzztime=15s .; \
else \
echo "no Fuzz* tests yet — see CLAUDE.md (fuzz the deserializer/lexer)"; \
fi
## bench: run benchmarks
bench:
$(GO) test -run='^$$' -bench=. -benchmem $(PKG)
## tidy: ensure go.mod/go.sum are tidy and verified
tidy:
$(GO) mod tidy
$(GO) mod verify
## tools: install pinned dev tooling into GOPATH/bin
tools:
$(GO) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_VERSION)
$(GO) install github.com/securego/gosec/v2/cmd/gosec@$(GOSEC_VERSION)
$(GO) install golang.org/x/vuln/cmd/govulncheck@$(GOVULN_VERSION)
$(GO) install github.com/zricethezav/gitleaks/v8@$(GITLEAKS_VERSION)
## hooks: install git pre-commit/pre-push hooks (lefthook)
hooks:
lefthook install
## clean: remove coverage artifacts
clean:
rm -f $(COVERPROFILE) coverage.html