-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
168 lines (141 loc) · 5.49 KB
/
Makefile
File metadata and controls
168 lines (141 loc) · 5.49 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
# Makefile for Initiat CLI
.PHONY: help build build-dev build-all install deps test test-coverage lint lint-fix format format-check security vuln-check clean tidy ci dev release-test release changelog install-tools docker-build docker-test cgo-check
# Tree-sitter grammars + go-tree-sitter require CGO.
CGO_ENABLED ?= 1
GOTOOLCHAIN ?= go1.25.8
export GOTOOLCHAIN
GO ?= env CGO_ENABLED=$(CGO_ENABLED) GOTOOLCHAIN=$(GOTOOLCHAIN) go
cgo-check: ## Fail fast if CGO/toolchain missing
@if [ "$(CGO_ENABLED)" != "1" ]; then \
echo "❌ CGO must be enabled for this project (Tree-sitter grammars require CGO)."; \
echo " Set CGO_ENABLED=1 (e.g. 'make ci CGO_ENABLED=1')."; \
exit 1; \
fi
@if ! command -v cc >/dev/null 2>&1 && ! command -v gcc >/dev/null 2>&1 && ! command -v clang >/dev/null 2>&1; then \
echo "❌ No C compiler found (cc/gcc/clang)."; \
echo " Install a compiler toolchain (e.g. build-essential / build-base) and rerun."; \
exit 1; \
fi
# Default target
help: ## Show this help message
@echo 'Usage: make [target]'
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
# Build targets
build: cgo-check ## Build the CLI binary
@echo "🏗️ Building Initiat CLI..."
$(GO) build -o initiat .
build-dev: cgo-check ## Build development version with localhost API URL
@echo "🔧 Building Initiat CLI (dev mode)..."
@echo " API URL: http://localhost:4000"
$(GO) build -tags dev -o initiat_dev .
@echo "✅ Built: ./initiat_dev"
build-all: ## Build release binaries (native platform by default)
@echo "🏗️ Building release binaries..."
./scripts/build-release.sh
install: build ## Install the CLI to /usr/local/bin
@echo "📦 Installing initiat to /usr/local/bin..."
sudo mv initiat /usr/local/bin/
# Development targets
deps: ## Download and verify dependencies
@echo "📦 Downloading dependencies..."
$(GO) mod download
$(GO) mod verify
test: cgo-check ## Run tests
@echo "🧪 Running tests..."
$(GO) test -race -coverprofile=coverage.out ./...
test-coverage: test ## Run tests and show coverage
@echo "📊 Test coverage:"
$(GO) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
# Code quality targets
lint: ## Run linter
@echo "🔍 Running linter..."
env CGO_ENABLED=$(CGO_ENABLED) golangci-lint run
lint-fix: ## Run linter with auto-fix
@echo "🔧 Running linter with auto-fix..."
env CGO_ENABLED=$(CGO_ENABLED) golangci-lint run --fix
format: ## Format code
@echo "🎨 Formatting code..."
@dirs="$$( $(GO) list -f '{{.Dir}}' ./... )"; \
gofmt -s -w $$dirs; \
goimports -w $$dirs
format-check: ## Check if code is formatted
@echo "🎨 Checking code formatting..."
@dirs="$$( $(GO) list -f '{{.Dir}}' ./... )"; \
if [ "$$(gofmt -s -l $$dirs | wc -l)" -gt 0 ]; then \
echo "❌ Code is not formatted. Run 'make format' to fix."; \
gofmt -s -l $$dirs; \
exit 1; \
else \
echo "✅ Code is properly formatted."; \
fi
# Security targets
security: ## Run security scan
@echo "🔒 Running security scan..."
@if ! command -v gosec >/dev/null 2>&1; then \
echo "Installing gosec..."; \
$(GO) install github.com/securego/gosec/v2/cmd/gosec@latest; \
fi
@out=$$(mktemp); \
if ! gosec -quiet \
-exclude-dir=docs \
-exclude-dir=internal/codeanalysis/testdata \
./... >"$$out" 2>&1; then \
cat "$$out"; \
rm -f "$$out"; \
exit 1; \
fi; \
rm -f "$$out"
vuln-check: ## Check for vulnerabilities
@echo "🛡️ Checking for vulnerabilities..."
govulncheck ./...
# Utility targets
clean: ## Clean build artifacts
@echo "🧹 Cleaning build artifacts..."
rm -f initiat initiat_dev
rm -rf dist/
rm -f coverage.out coverage.html
tidy: ## Tidy go modules
@echo "🧹 Tidying go modules..."
$(GO) mod tidy
# CI targets (run all checks)
ci: deps format-check lint test security vuln-check build ## Run all CI checks locally
# Development workflow
dev: deps format lint test build ## Quick development workflow
# Release targets
release-test: ## Test release build process
@echo "🚀 Testing release build..."
./scripts/build-release.sh test
release: ## Build release binaries (usage: make release VERSION=v1.0.0)
@if [ -z "$(VERSION)" ]; then \
echo "❌ VERSION is required. Usage: make release VERSION=v1.0.0"; \
exit 1; \
fi
@echo "🚀 Building release $(VERSION)..."
./scripts/build-release.sh $(VERSION)
changelog: ## Update changelog for new version (usage: make changelog VERSION=v1.0.0)
@if [ -z "$(VERSION)" ]; then \
echo "❌ VERSION is required. Usage: make changelog VERSION=v1.0.0"; \
exit 1; \
fi
@echo "📝 Updating changelog for $(VERSION)..."
@sed -i.bak "s/## \[Unreleased\]/## [Unreleased]\n\n## [$(VERSION)] - $(shell date +%Y-%m-%d)/" CHANGELOG.md
@rm CHANGELOG.md.bak
@echo "✅ Changelog updated. Please review and commit changes."
# Tool installation targets
install-tools: ## Install development tools
@echo "🔧 Installing development tools..."
$(GO) install golang.org/x/tools/cmd/goimports@latest
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
$(GO) install github.com/securego/gosec/v2/cmd/gosec@latest
$(GO) install golang.org/x/vuln/cmd/govulncheck@latest
@echo "✅ All development tools installed successfully!"
# Docker targets (if you want to add Docker support later)
docker-build: ## Build Docker image
@echo "🐳 Building Docker image..."
docker build -t initiat-cli .
docker-test: ## Test in Docker container
@echo "🐳 Testing in Docker..."
docker run --rm initiat-cli --help