-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
144 lines (122 loc) · 5.43 KB
/
Makefile
File metadata and controls
144 lines (122 loc) · 5.43 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
.PHONY: test test-update-golden test-coverage coverage coverage-html clean help build-dev release-check lint security housekeeping tools format format-check setup-hooks install-web build-web test-web clean-web
# Version information (can be overridden via command line)
# Try to get version from git tag, otherwise use "dev"
GIT_TAG := $(shell git describe --tags --exact-match 2>/dev/null || git describe --tags 2>/dev/null || echo "")
VERSION ?= $(if $(GIT_TAG),$(GIT_TAG),dev)
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
# Check for uncommitted changes (staged, unstaged, or untracked) and add -dirty suffix if present
DIRTY_CHECK := $(shell test -z "$$(git status --porcelain 2>/dev/null)" || echo "-dirty")
COMMIT := $(COMMIT)$(DIRTY_CHECK)
# Default target
help:
@echo "Available targets:"
@echo ""
@echo "Testing:"
@echo " tools - Install/update local tooling (bin/)"
@echo " format - Run gofmt -s on all Go files"
@echo " lint - Run golangci-lint"
@echo " vulncheck - Run govulncheck"
@echo " housekeeping - Run go mod tidy"
@echo " test - Run all tests (Go + frontend)"
@echo " test-web - Run frontend tests (Vitest)"
@echo " test-update-golden - Update golden test fixtures"
@echo " test-coverage - Run tests with coverage percentage"
@echo " coverage - Generate coverage profile (coverage.out)"
@echo " coverage-html - Generate HTML coverage report (coverage.html)"
@echo ""
@echo "Building:"
@echo " install-web - Install frontend dependencies"
@echo " build-web - Build frontend assets"
@echo " build-dev - Build for current platform with CGO (includes frontend)"
@echo ""
@echo "Releasing:"
@echo " release-check - Validate GoReleaser configuration"
@echo " (For actual releases: push a git tag to trigger GitHub Actions)"
@echo ""
@echo "Cleanup:"
@echo " clean - Remove coverage files and binary"
# Tooling (installed locally into ./.gotools)
TOOLS_BIN := $(CURDIR)/.gotools
GOLANGCI_LINT_VERSION ?= latest
GO_CONSISTENT_VERSION ?= latest
GOVULNCHECK_VERSION ?= latest
tools:
@mkdir -p $(TOOLS_BIN)
@[ -x $(TOOLS_BIN)/golangci-lint ] || GOBIN=$(TOOLS_BIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
@[ -x $(TOOLS_BIN)/go-consistent ] || GOBIN=$(TOOLS_BIN) go install github.com/quasilyte/go-consistent@$(GO_CONSISTENT_VERSION)
@[ -x $(TOOLS_BIN)/govulncheck ] || GOBIN=$(TOOLS_BIN) go install golang.org/x/vuln/cmd/govulncheck@$(GOVULNCHECK_VERSION)
# Format Go source files
format:
gofmt -s -w $$(find . -name '*.go' -not -path './.git/*')
# Activate the in-repo .githooks/ directory for this clone
setup-hooks:
git config core.hooksPath .githooks
# Verify tracked Go source files are gofmt-clean (used by pre-commit hook)
format-check:
@diff=$$(gofmt -s -l $$(git ls-files '*.go')); \
if [ -n "$$diff" ]; then \
echo "gofmt -s would reformat the following files; run 'make format':"; \
echo "$$diff"; \
exit 1; \
fi
# Run linters
lint: tools
$(TOOLS_BIN)/golangci-lint run ./...
$(TOOLS_BIN)/go-consistent ./...
# Run govulncheck
security: tools
$(TOOLS_BIN)/govulncheck ./...
# Normalize module dependencies
housekeeping:
go mod tidy
# Run all tests
test:
go test ./...
$(MAKE) test-web
# Frontend tests using Vitest
test-web:
cd cmd/watch/web && npm test
# Update golden test fixtures (only packages using goldie)
test-update-golden:
go test ./tests/litmus/... ./tests/integration/graph/... ./tests/languagespecs/java/tests/... ./cmd/graph/formatters/dot/... ./cmd/graph/formatters/mermaid/... -args -update
# Run tests with coverage percentage (excludes cmd packages which have no tests)
test-coverage:
@go list ./... | grep -Ev '/cmd($$|/)' | xargs go test -cover
# Generate coverage profile (exclude cmd packages as they have no tests)
coverage:
@echo "mode: atomic" > coverage.out
@go list ./... | grep -Ev '/cmd($$|/)' | while read pkg; do \
go test -coverprofile=coverage.tmp -covermode=atomic $$pkg || true; \
if [ -f coverage.tmp ]; then \
tail -n +2 coverage.tmp >> coverage.out; \
rm coverage.tmp; \
fi; \
done
# Generate HTML coverage report (requires coverage.out)
coverage-html: coverage
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
# Install frontend dependencies
install-web:
cd cmd/watch/web && npm install
# Build frontend assets
build-web:
cd cmd/watch/web && npm run build
# Build for current platform only (RECOMMENDED for local testing)
# No cross-compilation, no GoReleaser, no Zig required
build-dev: build-web
@echo "Building for current platform with version: $(VERSION), commit: $(COMMIT)"
CGO_ENABLED=1 go build -tags dev -ldflags "-s -w -X github.com/LegacyCodeHQ/clarity/cmd.version=$(VERSION) -X github.com/LegacyCodeHQ/clarity/cmd.buildDate=$(BUILD_DATE) -X github.com/LegacyCodeHQ/clarity/cmd.commit=$(COMMIT) -X github.com/LegacyCodeHQ/clarity/cmd.enableDevCommands=true" -o clarity ./main.go
@echo ""
@echo "Build successful! Run './clarity --version' to test"
# Validate the GoReleaser configuration
release-check:
goreleaser check
# Clean frontend build artifacts
clean-web:
rm -rf cmd/watch/web/node_modules cmd/watch/dist
# Clean coverage files and binary
clean: clean-web
rm -f coverage.out coverage.html coverage.tmp *.coverprofile *.cover clarity
rm -rf dist/