-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
146 lines (115 loc) · 4.89 KB
/
Copy pathMakefile
File metadata and controls
146 lines (115 loc) · 4.89 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
.DEFAULT_GOAL := help
.PHONY: help all build clean fmt fmt-check vet lint lint-changed lint-full install-tools \
test test-uncached test-race test-race-full test-verbose test-cover \
test-integration test-junit \
cover-report cover-check tidy tidy-check generate generate-check docs \
docs-check check verify
GO ?= go
GOFMT ?= gofmt
GOLANGCI_LINT ?= $(shell command -v golangci-lint 2>/dev/null || printf '%s/bin/golangci-lint' "$$($(GO) env GOPATH)")
GOLANGCI_LINT_VERSION ?= v2.12.2
GOLANGCI_LINT_BIN ?= $(shell $(GO) env GOPATH)/bin
GOTESTSUM ?= $(shell command -v gotestsum 2>/dev/null || printf '%s/bin/gotestsum' "$$($(GO) env GOPATH)")
# Most repository tests are I/O-heavy and opt into t.Parallel. Keep this
# overridable for constrained machines while allowing local and CI runs to
# use more than the historical four-test cap.
TEST_PARALLELISM ?= 8
TEST_PACKAGE_PARALLELISM ?= 8
INTEGRATION_PARALLELISM ?= 4
GOTESTSUM_FLAGS ?= --rerun-fails=2 --rerun-fails-max-failures=5
help:
@echo "Common targets:"
@echo " make test cached local test suite (packages=$(TEST_PACKAGE_PARALLELISM), tests=$(TEST_PARALLELISM))"
@echo " make check fast formatting, test, and changed-code lint checks"
@echo " make verify complete uncached local validation"
@echo " make test-race focused race tests for stateful packages"
@echo " make test-junit run tests with gotestsum for timing and flaky detection"
@echo " make test-integration run integration tests"
@echo " make lint-full enforce the complete repository lint baseline"
@echo " make fmt format all Go packages"
@echo " make generate refresh generated outputs"
@echo " make install-tools install the pinned golangci-lint version"
all: build
build:
$(GO) build ./...
clean:
$(GO) clean ./...
rm -f coverage.out coverage.html
fmt:
$(GO) fmt ./...
fmt-check:
@unformatted="$$($(GOFMT) -l .)" || exit 1; \
if [ -n "$$unformatted" ]; then \
echo "The following Go files need formatting:"; \
echo "$$unformatted"; \
exit 1; \
fi
vet:
$(GO) vet ./...
lint: lint-changed
lint-changed:
$(GOLANGCI_LINT) run --new-from-rev=HEAD ./...
lint-full:
$(GOLANGCI_LINT) run ./...
install-tools:
@installer=$$(mktemp); \
trap 'rm -f "$$installer"' EXIT; \
curl -sSfL https://golangci-lint.run/install.sh -o "$$installer"; \
sh "$$installer" -b "$(GOLANGCI_LINT_BIN)" "$(GOLANGCI_LINT_VERSION)"
test:
$(GO) test -short -p=$(TEST_PACKAGE_PARALLELISM) -parallel=$(TEST_PARALLELISM) -timeout 120s ./...
test-uncached:
$(GO) test -short -p=$(TEST_PACKAGE_PARALLELISM) -parallel=$(TEST_PARALLELISM) -count=1 -timeout 120s ./...
test-race:
# Keep package-level overlap for cross-package race coverage while bounding
# in-process test concurrency for the CPU-heavy SQLite tests.
$(GO) test -short -race -p=4 -parallel=2 -timeout 600s ./internal/app ./internal/corpus ./internal/workspace
test-race-full:
# Keep package-level overlap for cross-package race coverage while bounding
# in-process test concurrency for the CPU-heavy SQLite tests.
$(GO) test -race -p=4 -parallel=2 -count=1 -timeout 900s ./...
test-verbose:
$(GO) test -short -v -p=$(TEST_PACKAGE_PARALLELISM) -parallel=$(TEST_PARALLELISM) -timeout 120s ./...
test-cover:
$(GO) test -short -p=$(TEST_PACKAGE_PARALLELISM) -parallel=$(TEST_PARALLELISM) \
-coverprofile=coverage.out \
-covermode=set \
-coverpkg=./internal/... \
-timeout 180s \
./...
cover-report: test-cover
$(GO) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"
cover-check: test-cover
@coverage=$$($(GO) tool cover -func=coverage.out | tail -n1 | awk '{print $$NF}' | tr -d '%'); \
awk -v coverage="$$coverage" 'BEGIN { if (coverage < 70) exit 1 }' || { \
echo "Coverage $$coverage% is below 70% threshold"; \
exit 1; \
}; \
echo "Coverage: $$coverage% (passes 70% threshold)"
tidy:
$(GO) mod tidy
tidy-check:
$(GO) mod tidy -diff
generate:
$(GO) generate ./...
generate-check:
./scripts/check-generated.sh
docs: docs-check
docs-check:
./scripts/validate-agents-md.sh
# gotestsum provides flaky test detection (--rerun-fails) and test timing
# reports (--junitfile) for CI. Falls back to plain go test locally.
test-junit:
@if command -v gotestsum >/dev/null 2>&1; then \
gotestsum $(GOTESTSUM_FLAGS) --junitfile test-results.xml -- \
$(GO) test -short -p=$(TEST_PACKAGE_PARALLELISM) -parallel=$(TEST_PARALLELISM) -timeout 120s ./...; \
else \
$(GO) test -short -p=$(TEST_PACKAGE_PARALLELISM) -parallel=$(TEST_PARALLELISM) -timeout 120s ./...; \
fi
# Integration tests exercise the application end-to-end through the Service
# contracts, using temporary databases and no external network access.
test-integration:
$(GO) test -short -p=$(INTEGRATION_PARALLELISM) -parallel=$(INTEGRATION_PARALLELISM) -timeout 180s ./tests/integration/...
check: fmt-check test lint-changed
verify: fmt-check test-uncached lint-full tidy-check generate-check docs-check