-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
246 lines (209 loc) · 6.7 KB
/
Makefile
File metadata and controls
246 lines (209 loc) · 6.7 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
# GoViz Makefile
# Professional build system for GoViz CLI tool
# Metadata
BINARY_NAME := goviz
VERSION ?= v0.1.0
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_TIME := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
# Go settings
GOCMD := go
GOBUILD := $(GOCMD) build
GOCLEAN := $(GOCMD) clean
GOTEST := $(GOCMD) test
GOGET := $(GOCMD) get
GOMOD := $(GOCMD) mod
# Build flags
LDFLAGS := -w -s -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.buildTime=$(BUILD_TIME)
BUILD_FLAGS := -ldflags="$(LDFLAGS)"
# Directories
DIST_DIR := dist
SCRIPTS_DIR := scripts
# Default target
.PHONY: all
all: clean test build
# Help target
.PHONY: help
help: ## Show this help message
@echo "GoViz Build System"
@echo ""
@echo "Available targets:"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
# Development targets
.PHONY: build
build: ## Build the binary
@echo "🔨 Building $(BINARY_NAME)..."
$(GOBUILD) $(BUILD_FLAGS) -o $(BINARY_NAME) .
@echo "✅ Build completed: ./$(BINARY_NAME)"
.PHONY: build-debug
build-debug: ## Build with debug information
@echo "🔨 Building $(BINARY_NAME) with debug info..."
$(GOBUILD) -gcflags="all=-N -l" -o $(BINARY_NAME) .
@echo "✅ Debug build completed: ./$(BINARY_NAME)"
.PHONY: install
install: build ## Install binary to system
@echo "📦 Installing $(BINARY_NAME) to /usr/local/bin..."
sudo cp $(BINARY_NAME) /usr/local/bin/
@echo "✅ Installation completed"
.PHONY: uninstall
uninstall: ## Remove binary from system
@echo "🗑️ Uninstalling $(BINARY_NAME)..."
sudo rm -f /usr/local/bin/$(BINARY_NAME)
@echo "✅ Uninstallation completed"
# Testing targets
.PHONY: test
test: ## Run tests
@echo "🧪 Running tests..."
$(GOTEST) -v ./...
.PHONY: test-coverage
test-coverage: ## Run tests with coverage
@echo "🧪 Running tests with coverage..."
$(GOTEST) -race -coverprofile=coverage.out ./...
$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "📊 Coverage report: coverage.html"
.PHONY: test-race
test-race: ## Run tests with race detection
@echo "🧪 Running tests with race detection..."
$(GOTEST) -race ./...
.PHONY: benchmark
benchmark: ## Run benchmarks
@echo "⚡ Running benchmarks..."
$(GOTEST) -bench=. -benchmem ./...
# Code quality targets
.PHONY: lint
lint: ## Run linter
@echo "🔍 Running linter..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run; \
else \
echo "⚠️ golangci-lint not found. Install with: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
fi
.PHONY: fmt
fmt: ## Format code
@echo "💄 Formatting code..."
$(GOCMD) fmt ./...
.PHONY: vet
vet: ## Run go vet
@echo "🔍 Running go vet..."
$(GOCMD) vet ./...
.PHONY: tidy
tidy: ## Tidy go modules
@echo "🧹 Tidying go modules..."
$(GOMOD) tidy
.PHONY: verify
verify: fmt vet lint test ## Run all verification steps
@echo "✅ All verification steps completed"
# Release targets
.PHONY: build-releases
build-releases: ## Build releases for all platforms
@echo "🏗️ Building releases for all platforms..."
@chmod +x $(SCRIPTS_DIR)/build-releases.sh
VERSION=$(VERSION) $(SCRIPTS_DIR)/build-releases.sh
.PHONY: release
release: verify build-releases ## Create a full release (verify + build all platforms)
@echo "🚀 Release $(VERSION) ready in $(DIST_DIR)/"
@ls -la $(DIST_DIR)/
.PHONY: docker-build
docker-build: ## Build Docker image
@echo "🐳 Building Docker image..."
docker build -t $(BINARY_NAME):$(VERSION) .
docker tag $(BINARY_NAME):$(VERSION) $(BINARY_NAME):latest
# Utility targets
.PHONY: run
run: build ## Build and run the application
@echo "🚀 Running $(BINARY_NAME)..."
./$(BINARY_NAME) --help
.PHONY: demo
demo: build ## Run demo commands
@echo "🎮 Running demo..."
./$(BINARY_NAME) generate --format tree
@echo ""
./$(BINARY_NAME) analyze
@echo ""
./$(BINARY_NAME) doctor
.PHONY: clean
clean: ## Clean build artifacts
@echo "🧹 Cleaning..."
$(GOCLEAN)
rm -f $(BINARY_NAME)
rm -rf $(DIST_DIR)
rm -f coverage.out coverage.html
@echo "✅ Clean completed"
.PHONY: deps
deps: ## Download dependencies
@echo "📦 Downloading dependencies..."
$(GOMOD) download
$(GOMOD) tidy
.PHONY: upgrade-deps
upgrade-deps: ## Upgrade all dependencies
@echo "⬆️ Upgrading dependencies..."
$(GOGET) -u ./...
$(GOMOD) tidy
# Development helpers
.PHONY: watch
watch: ## Watch for changes and rebuild (requires entr)
@echo "👀 Watching for changes..."
@if command -v entr >/dev/null 2>&1; then \
find . -name "*.go" | entr -r make build; \
else \
echo "⚠️ entr not found. Install with your package manager"; \
fi
.PHONY: serve-docs
serve-docs: ## Serve documentation locally (requires Python)
@echo "📚 Serving documentation on http://localhost:8000"
@if command -v python3 >/dev/null 2>&1; then \
python3 -m http.server 8000; \
elif command -v python >/dev/null 2>&1; then \
python -m SimpleHTTPServer 8000; \
else \
echo "⚠️ Python not found"; \
fi
# Security targets
.PHONY: vuln-check
vuln-check: ## Check for vulnerabilities
@echo "🔒 Checking for vulnerabilities..."
@if command -v govulncheck >/dev/null 2>&1; then \
govulncheck ./...; \
else \
echo "⚠️ govulncheck not found. Install with: go install golang.org/x/vuln/cmd/govulncheck@latest"; \
fi
.PHONY: audit
audit: vuln-check ## Run security audit
@echo "🔍 Running security audit..."
@if command -v gosec >/dev/null 2>&1; then \
gosec ./...; \
else \
echo "⚠️ gosec not found. Install with: go install github.com/securecodewarrior/gosec/v2/cmd/gosec@latest"; \
fi
# Information targets
.PHONY: info
info: ## Show build information
@echo "📋 Build Information:"
@echo " Binary Name: $(BINARY_NAME)"
@echo " Version: $(VERSION)"
@echo " Commit: $(COMMIT)"
@echo " Build Time: $(BUILD_TIME)"
@echo " Go Version: $(shell $(GOCMD) version)"
.PHONY: size
size: build ## Show binary size
@echo "📏 Binary size:"
@ls -lh $(BINARY_NAME) | awk '{print " Size: " $$5}'
@file $(BINARY_NAME)
# Setup targets for new developers
.PHONY: setup
setup: deps ## Setup development environment
@echo "🛠️ Setting up development environment..."
@echo "Installing development tools..."
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
@go install golang.org/x/vuln/cmd/govulncheck@latest
@go install github.com/securecodewarrior/gosec/v2/cmd/gosec@latest
@echo "✅ Development environment ready"
.PHONY: pre-commit
pre-commit: verify vuln-check ## Run pre-commit checks
@echo "✅ Pre-commit checks passed"
# CI/CD targets
.PHONY: ci
ci: verify build-releases ## CI pipeline
@echo "🤖 CI pipeline completed"
.PHONY: cd
cd: release ## CD pipeline
@echo "🚀 CD pipeline completed"