Makefile RawHistoryFolder
1# Makefile for dumber (Clean Architecture - puregotk)
2
3.PHONY: build build-frontend test lint clean install-tools dev generate help init check-docs man
4
5# Load local overrides from .env.local if present (Makefile syntax)
6ifneq (,$(wildcard .env.local))
7include .env.local
8export
9endif
10
11# Variables
12BINARY_NAME=dumber
13MAIN_PATH=./cmd/dumber
14DIST_DIR=dist
15
16# Detect number of CPU cores for parallel compilation
17NPROCS?=$(shell nproc 2>/dev/null || echo 1)
18
19# Version information from git
20VERSION=$(shell git describe --tags --always --dirty 2>/dev/null || echo "v0.0.0-dev")
21COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
22BUILD_DATE=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
23
24# Linker flags
25LDFLAGS=-ldflags "-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.buildDate=$(BUILD_DATE)"
26
27# Default target
28help: ## Show this help message
29 @echo "Available targets:"
30 @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
31
32# Build targets
33build: build-frontend ## Build the application (pure Go, no CGO)
34 @echo "Building $(BINARY_NAME) $(VERSION) using $(NPROCS) cores..."
35 @mkdir -p $(DIST_DIR)
36 CGO_ENABLED=0 go build -p $(NPROCS) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME) $(MAIN_PATH)
37 @echo "Build successful! Binary: $(DIST_DIR)/$(BINARY_NAME)"
38
39build-frontend: ## Build homepage and error pages
40 @echo "Building webui pages (homepage + error)..."
41 @cd webui && npm install --silent && npm run build
42 @echo "Frontend build complete"
43
44build-quick: ## Build without frontend (faster for backend development)
45 @echo "Building $(BINARY_NAME) $(VERSION) (quick, no frontend)..."
46 @mkdir -p $(DIST_DIR)
47 CGO_ENABLED=0 go build -p $(NPROCS) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME) $(MAIN_PATH)
48 @echo "Build successful! Binary: $(DIST_DIR)/$(BINARY_NAME)"
49
50# Development targets
51dev: ## Run in development mode
52 @echo "Running in development mode..."
53 go run $(MAIN_PATH)
54
55run: build-quick ## Build and run
56 @echo "Running $(BINARY_NAME)..."
57 $(DIST_DIR)/$(BINARY_NAME)
58
59generate: ## Generate code (SQLC)
60 @echo "Generating code with SQLC..."
61 sqlc generate
62 @echo "Code generation complete"
63
64mocks: ## Generate mock implementations with mockery
65 @echo "Generating mocks with mockery..."
66 mockery
67 @echo "Mock generation complete"
68
69# Testing
70test: ## Run tests
71 @echo "Running tests..."
72 go test -v ./...
73
74check-docs: ## Verify README/docs match code
75 @go run ./dev/check-docs.go --fail-on-error
76
77test-race: ## Run tests with race detection
78 @echo "Running tests with race detection..."
79 go test -race -v ./...
80
81test-cover: ## Run tests with coverage
82 @echo "Running tests with coverage..."
83 go test -coverprofile=coverage.out ./...
84 go tool cover -html=coverage.out -o coverage.html
85 @echo "Coverage report: coverage.html"
86
87# Linting
88lint: ## Run golangci-lint
89 @echo "Running golangci-lint..."
90 golangci-lint run
91
92lint-fix: ## Run golangci-lint with --fix
93 @echo "Running golangci-lint with --fix..."
94 golangci-lint run --fix
95
96# Format code
97fmt: ## Format Go code with gofmt
98 @echo "Formatting Go code..."
99 go fmt ./...
100
101# Tools installation
102install-tools: ## Install development tools
103 @echo "Installing development tools..."
104 go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
105 go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
106 @echo "Tools installed successfully"
107
108# Cleanup
109clean: ## Clean build artifacts
110 @echo "Cleaning build artifacts..."
111 rm -rf $(DIST_DIR)
112 rm -f $(BINARY_NAME)
113 rm -rf webui/dist webui/node_modules
114 rm -f assets/webui/homepage.min.js assets/webui/error.min.js assets/webui/config.min.js assets/webui/index.html assets/webui/error.html assets/webui/config.html assets/webui/style.css
115 rm -f coverage.out coverage.html
116 go clean -cache
117 go clean -testcache
118
119# Project initialization
120init: install-tools ## Initialize project dependencies and tools
121 @echo "Initializing project..."
122 go mod tidy
123 @echo "Project initialized! Run 'make help' for available commands."
124
125# Check setup
126check: ## Check that all tools and dependencies are working
127 @echo "Checking project setup..."
128 @echo "Go version:"
129 @go version
130 @echo "\nSQLC version:"
131 @sqlc version
132 @echo "\nGolangci-lint version:"
133 @golangci-lint version
134 @echo "\nBuilding project..."
135 @$(MAKE) build-quick
136 @echo "\nRunning tests..."
137 @$(MAKE) test
138 @echo "\nAll checks passed!"
139
140# Documentation
141man: build-quick ## Install man pages to ~/.local/share/man/man1/
142 @echo "Installing man pages..."
143 $(DIST_DIR)/$(BINARY_NAME) gen-docs
144
145# Native release targets
146.PHONY: release-snapshot release
147
148release-snapshot: build-frontend ## Build snapshot using goreleaser
149 @echo "Building snapshot with goreleaser..."
150 goreleaser release --snapshot --clean
151
152release: ## Create full release using goreleaser
153 @echo "Building release with goreleaser..."
154 GITHUB_TOKEN=$$(gh auth token) goreleaser release --clean