-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
85 lines (71 loc) · 2.85 KB
/
Makefile
File metadata and controls
85 lines (71 loc) · 2.85 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
SHELL := /bin/sh
.PHONY: fmt lint vuln test test-coverage test-patch-coverage tools setup-hooks lint-commit cli-smoke-build cli-smoke-scaffold
GOPATH ?= $(shell go env GOPATH)
GOIMPORTS ?= $(GOPATH)/bin/goimports
GOLANGCI_LINT ?= $(GOPATH)/bin/golangci-lint
GOLANGCI_LINT_VERSION ?= v2.5.0
GOVULNCHECK ?= $(GOPATH)/bin/govulncheck
GO_PATCH_COVER ?= $(GOPATH)/bin/go-patch-cover
LEFTHOOK ?= $(GOPATH)/bin/lefthook
COMMITLINT ?= $(GOPATH)/bin/commitlint
# Find all directories with go.mod, excluding hidden dirs (like .worktrees) and vendor
MODULES = $(shell find . -type f -name "go.mod" -not -path "*/.*/*" -not -path "*/vendor/*" -exec dirname {} \;)
fmt: tools
gofmt -w .
$(GOIMPORTS) -w .
lint:
$(GOLANGCI_LINT) run
vuln:
$(GOVULNCHECK) ./...
test:
@for mod in $(MODULES); do \
echo "Testing module: $$mod"; \
(cd $$mod && go test -race -timeout=5m ./...) || exit 1; \
done
test-coverage:
@mkdir -p .coverage
@echo "mode: atomic" > .coverage/coverage.out
@for mod in $(MODULES); do \
echo "Testing coverage for module: $$mod"; \
(cd $$mod && go test -race -coverprofile=profile.out -covermode=atomic ./...) || exit 1; \
if [ -f $$mod/profile.out ]; then \
tail -n +2 $$mod/profile.out >> .coverage/coverage.out; \
rm $$mod/profile.out; \
fi; \
done
@printf "\nTotal Coverage:\n"
@go tool cover -func=.coverage/coverage.out | grep "total:"
test-patch-coverage: test-coverage
@echo "Comparing against origin/main..."
@git diff -U0 --no-color origin/main...HEAD > .coverage/diff.patch
@$(GO_PATCH_COVER) .coverage/coverage.out .coverage/diff.patch > .coverage/patch_coverage.out
@echo "Patch Coverage Report:"
@cat .coverage/patch_coverage.out
# Install all development tools (tracked in tools/tools.go)
tools:
@echo "Installing development tools..."
@cat tools/tools.go | grep _ | awk '{print $$2}' | grep -v golangci-lint | xargs -I {} sh -c 'go install {}'
@go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
@echo "Done: All tools installed"
# Install development tools and setup git hooks
setup-hooks: tools
@echo "Setting up git hooks..."
@if ! command -v lefthook >/dev/null 2>&1; then \
echo "Warning: lefthook not found in PATH. Ensure \$$GOPATH/bin is in your PATH:"; \
echo " export PATH=\"\$$(go env GOPATH)/bin:\$$PATH\""; \
fi
$(LEFTHOOK) install --force
@echo "Done: Git hooks installed"
# Validate a commit message (for manual testing)
lint-commit:
@echo "$(MSG)" | $(COMMITLINT) lint --config .commitlint.yml
cli-smoke-build:
go build -o /tmp/modkit ./cmd/modkit
cli-smoke-scaffold: cli-smoke-build
@rm -rf /tmp/cli-test
@mkdir -p /tmp/cli-test
@cd /tmp/cli-test && /tmp/modkit new app testapp
@test -f /tmp/cli-test/testapp/cmd/api/main.go
@test -f /tmp/cli-test/testapp/internal/modules/app/module.go
@test -f /tmp/cli-test/testapp/go.mod
@cd /tmp/cli-test/testapp && go build ./cmd/api