Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
282 lines (237 loc) · 8.27 KB
/
Copy pathMakefile
File metadata and controls
282 lines (237 loc) · 8.27 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
.PHONY: help build test test-race test-coverage clean lint lint-fix security fmt vet install-tools deps tidy run-regtest stop-regtest check-all vuln ai-check release-dry-run
# Default target
.DEFAULT_GOAL := help
# Project variables
PROJECT_NAME := go-regtest
GO := go
GOTEST := $(GO) test
GOVET := $(GO) vet
GOFMT := $(GO) fmt
COVERAGE_FILE := coverage.out
COVERAGE_HTML := coverage.html
## help: Display this help message
help:
@echo "$(PROJECT_NAME) - Bitcoin Regtest Development Tools"
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@awk 'BEGIN {FS = ":.*##"; printf ""} /^[a-zA-Z_-]+:.*?##/ { printf " %-20s %s\n", $$1, $$2 } /^##@/ { printf "\n%s\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Development
## build: Build the project
build:
@echo "Building..."
$(GO) build -v ./...
## test: Run all tests
test:
@echo "Running tests..."
$(GOTEST) -v ./...
## test-race: Run tests with race detector
test-race:
@echo "Running tests with race detector..."
$(GOTEST) -v -race ./...
## test-coverage: Run tests with coverage
test-coverage:
@echo "Running tests with coverage..."
$(GOTEST) -v -coverprofile=$(COVERAGE_FILE) -covermode=atomic ./...
@echo "Coverage summary:"
$(GO) tool cover -func=$(COVERAGE_FILE)
@echo ""
@echo "Coverage percentage:"
$(GO) tool cover -func=$(COVERAGE_FILE) | tail -1
@echo ""
@echo "Generating HTML coverage report..."
$(GO) tool cover -html=$(COVERAGE_FILE) -o $(COVERAGE_HTML)
@echo "Coverage report generated: $(COVERAGE_HTML)"
## test-coverage-func: Show detailed function coverage
test-coverage-func:
@echo "Running tests with detailed function coverage..."
$(GOTEST) -v -coverprofile=$(COVERAGE_FILE) -covermode=atomic ./...
@echo "Detailed function coverage:"
$(GO) tool cover -func=$(COVERAGE_FILE)
## test-coverage-html: Generate HTML coverage report only
test-coverage-html:
@if [ ! -f $(COVERAGE_FILE) ]; then \
echo "No coverage file found. Run 'make test-coverage' first."; \
exit 1; \
fi
@echo "Generating HTML coverage report..."
$(GO) tool cover -html=$(COVERAGE_FILE) -o $(COVERAGE_HTML)
@echo "Coverage report generated: $(COVERAGE_HTML)"
## test-coverage-check: Check if coverage meets threshold
test-coverage-check:
@echo "Running tests with coverage check..."
$(GOTEST) -v -coverprofile=$(COVERAGE_FILE) -covermode=atomic ./...
@echo "Checking coverage threshold..."
@COVERAGE=$$($(GO) tool cover -func=$(COVERAGE_FILE) | tail -1 | awk '{print $$3}' | sed 's/%//'); \
COVERAGE_INT=$$(echo "$$COVERAGE" | cut -d. -f1); \
if [ $$COVERAGE_INT -lt 70 ]; then \
echo "ERROR: Coverage $$COVERAGE% is below 70% threshold"; \
exit 1; \
else \
echo "SUCCESS: Coverage $$COVERAGE% meets 70% threshold"; \
fi
## test-short: Run short tests only
test-short:
@echo "Running short tests..."
$(GOTEST) -v -short ./...
## bench: Run benchmarks
bench:
@echo "Running benchmarks..."
$(GOTEST) -bench=. -benchmem ./...
##@ Code Quality
## fmt: Format code using gofmt
fmt:
@echo "Formatting code..."
$(GOFMT) ./...
## vet: Run go vet
vet:
@echo "Running go vet..."
$(GOVET) ./...
## lint: Run golangci-lint using .golangci.yml
lint:
@echo "Running golangci-lint..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run ./...; \
else \
echo "golangci-lint not installed. Run 'make install-tools' to install it."; \
exit 1; \
fi
## lint-fix: Run golangci-lint with auto-fix
lint-fix:
@echo "Running golangci-lint with auto-fix..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run --fix ./...; \
else \
echo "golangci-lint not installed. Run 'make install-tools' to install it."; \
exit 1; \
fi
## security: Run security checks with gosec (optional - install separately)
security:
@echo "Running security checks..."
@if command -v gosec >/dev/null 2>&1; then \
gosec -fmt=json -out=gosec-report.json ./...; \
gosec ./...; \
else \
echo "WARNING: gosec not installed (optional tool)"; \
echo " Install: go install github.com/securego/gosec/v2/cmd/gosec@latest"; \
fi
## staticcheck: Run staticcheck (optional - requires Go version match)
staticcheck:
@echo "Running staticcheck..."
@if command -v staticcheck >/dev/null 2>&1; then \
staticcheck ./... 2>&1 || echo "WARNING: staticcheck version mismatch (optional tool)"; \
else \
echo "WARNING: staticcheck not installed (optional tool)"; \
echo " Install: go install honnef.co/go/tools/cmd/staticcheck@latest"; \
fi
## vuln: Run govulncheck against the module (auto-installs if missing)
# Pinned because govulncheck >= v1.2.0 requires Go 1.25+ (CI runs 1.23).
GOVULNCHECK_VERSION ?= v1.1.4
vuln:
@echo "Running govulncheck..."
@if ! command -v govulncheck >/dev/null 2>&1; then \
echo " govulncheck not found, installing $(GOVULNCHECK_VERSION)..."; \
go install golang.org/x/vuln/cmd/govulncheck@$(GOVULNCHECK_VERSION); \
fi
@govulncheck ./...
## ai-check: Full green-gate before committing AI-assisted changes
ai-check: fmt vet lint test-race vuln
@echo ""
@echo "ai-check passed!"
## release-dry-run: Build a snapshot release locally (no publish)
release-dry-run:
@echo "Running goreleaser snapshot..."
@if ! command -v goreleaser >/dev/null 2>&1; then \
echo " goreleaser not found. Install: brew install goreleaser/tap/goreleaser"; \
exit 1; \
fi
@goreleaser release --snapshot --clean
##@ Dependencies
## deps: Download dependencies
deps:
@echo "Downloading dependencies..."
$(GO) mod download
## tidy: Tidy up go.mod and go.sum
tidy:
@echo "Tidying up dependencies..."
$(GO) mod tidy
## verify: Verify dependencies
verify:
@echo "Verifying dependencies..."
$(GO) mod verify
## install-tools: Install development tools
# Uses the official install.sh to grab a precompiled golangci-lint binary —
# avoids requiring Go >= 1.25 just to build the linter from source.
GOLANGCI_LINT_VERSION ?= v2.11.4
install-tools:
@echo "Installing required development tools..."
@echo "Installing golangci-lint $(GOLANGCI_LINT_VERSION)..."
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $$(go env GOPATH)/bin $(GOLANGCI_LINT_VERSION)
@echo ""
@echo "Required tools installed!"
@echo ""
@echo "Optional tools (install manually if needed):"
@echo " - gosec: go install github.com/securego/gosec/v2/cmd/gosec@latest"
@echo " - staticcheck: go install honnef.co/go/tools/cmd/staticcheck@latest"
##@ Regtest Operations
## run-regtest: Start a regtest node for manual testing
run-regtest:
@echo "Starting Bitcoin regtest node..."
@bash scripts/bitcoind_manager.sh start
## stop-regtest: Stop the regtest node
stop-regtest:
@echo "Stopping Bitcoin regtest node..."
@bash scripts/bitcoind_manager.sh stop
## status-regtest: Check regtest node status
status-regtest:
@echo "Checking Bitcoin regtest node status..."
@bash scripts/bitcoind_manager.sh status
##@ Coverage
## coverage: Alias for test-coverage
coverage: test-coverage
## coverage-open: Open HTML coverage report in browser
coverage-open: test-coverage-html
@echo "Opening coverage report in browser..."
@if command -v xdg-open >/dev/null 2>&1; then \
xdg-open $(COVERAGE_HTML); \
elif command -v open >/dev/null 2>&1; then \
open $(COVERAGE_HTML); \
else \
echo "Please open $(COVERAGE_HTML) in your browser"; \
fi
## coverage-clean: Clean only coverage files
coverage-clean:
@echo "Cleaning coverage files..."
@rm -f $(COVERAGE_FILE) $(COVERAGE_HTML)
## coverage-script: Use the coverage analysis script
coverage-script:
@echo "Using coverage analysis script..."
@bash scripts/coverage.sh $(filter-out $@,$(MAKECMDGOALS))
##@ Cleanup
## clean: Clean build artifacts and test data
clean: coverage-clean
@echo "Cleaning up..."
@rm -f gosec-report.json
@rm -rf ./bitcoind_regtest*
@rm -rf ./bitcoin_regtest*
@$(GO) clean -cache -testcache
@echo "Cleanup complete!"
## clean-all: Clean everything including dependencies
clean-all: clean
@echo "Removing downloaded dependencies..."
@$(GO) clean -modcache
@echo "Full cleanup complete!"
##@ Combined Checks
## check-all: Run all checks (fmt, vet, lint, test-race)
check-all: fmt vet lint test-race
@echo ""
@echo "All checks passed!"
## ci: Run CI pipeline checks
ci: deps tidy fmt vet lint test-coverage-check
@echo ""
@echo "CI checks passed!"
## pre-commit: Run pre-commit checks (quick)
pre-commit: fmt vet lint test
@echo ""
@echo "Pre-commit checks passed!"