-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
250 lines (214 loc) Β· 9.36 KB
/
Makefile
File metadata and controls
250 lines (214 loc) Β· 9.36 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
247
248
249
250
# Makefile for gdl project
# Fast, concurrent file downloader written in Go
.PHONY: help build test lint clean install dev docs examples all
# Default target
all: lint test build
# Display help information
help: ## Show this help message
@echo "Available commands:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
# Build targets
build: ## Build the CLI binary
@echo "Building gdl CLI..."
go build -ldflags="-s -w" -o bin/gdl ./cmd/gdl/
build-all: ## Build binaries for all platforms
@echo "Building for all platforms..."
@mkdir -p bin
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o bin/gdl-linux-amd64 ./cmd/gdl/
GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o bin/gdl-linux-arm64 ./cmd/gdl/
GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o bin/gdl-darwin-amd64 ./cmd/gdl/
GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w" -o bin/gdl-darwin-arm64 ./cmd/gdl/
GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -o bin/gdl-windows-amd64.exe ./cmd/gdl/
# Testing targets
test: ## Run all tests
@echo "Running tests..."
go test ./...
test-race: ## Run tests with race detection
@echo "Running tests with race detection..."
go test -race ./...
test-coverage: ## Run tests with coverage
@echo "Running tests with coverage..."
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
test-bench: ## Run benchmark tests
@echo "Running benchmark tests..."
go test -bench=. ./...
# Code quality targets
lint: ## Run golangci-lint
@echo "Running linter..."
golangci-lint run
fmt: ## Format Go code
@echo "Formatting code..."
go fmt ./...
goimports -w .
tidy: ## Tidy Go modules
@echo "Tidying modules..."
go mod tidy
# Development targets
dev: fmt tidy lint test ## Run development checks (format, tidy, lint, test)
install: ## Install CLI tool globally
@echo "Installing gdl CLI..."
go install ./cmd/gdl/
clean: ## Clean build artifacts
@echo "Cleaning..."
rm -rf bin/
rm -f coverage.out coverage.html
go clean -testcache
# Documentation targets
docs: ## Documentation target
@echo "Documentation target complete"
examples: ## Test all examples
@echo "Testing examples..."
@for dir in examples/*/; do \
if [[ -f "$$dir/main.go" ]]; then \
echo "Testing: $$dir"; \
cd "$$dir" && timeout 30s go run main.go || echo "Example completed"; \
cd - > /dev/null; \
fi; \
done
# CI targets (used by GitHub Actions)
ci-test: ## CI test target
go test -race -coverprofile=coverage.out ./...
ci-lint: ## CI lint target
golangci-lint run --out-format=github-actions
ci-build: ## CI build target
go build -ldflags="-s -w" ./cmd/gdl/
# CI equivalent checks (run exactly what CI runs)
ci-check: ## Run full CI equivalent checks locally
@echo "π Running CI equivalent checks..."
@echo "1. Checking code formatting..."
@if [ "$$(gofmt -s -l . | wc -l)" -gt 0 ]; then \
echo "β Formatting issues found:"; \
gofmt -s -l .; \
echo "Run 'gofmt -s -w .' to fix"; \
exit 1; \
fi
@echo "β
Code formatting check passed"
@echo "2. Running go vet (excluding examples)..."
go vet $$(go list ./... | grep -v '/examples/')
@echo "β
go vet passed"
@echo "3. Checking go mod tidy..."
go mod tidy
@git diff --exit-code go.mod go.sum || (echo "β go.mod/go.sum not tidy. Run 'go mod tidy'" && exit 1)
@echo "β
go mod tidy check passed"
@echo "4. Running golangci-lint..."
golangci-lint run
@echo "β
golangci-lint passed"
@echo "5. Running quick tests with race detection..."
go test -race -short ./...
@echo "β
Quick tests with race detection passed"
@echo "π All CI equivalent checks passed!"
ci-format: ## Format code exactly like CI expects
@echo "π Applying CI formatting standards..."
gofmt -s -w .
go mod tidy
@echo "β
Code formatted to CI standards"
pre-push: ## Complete pre-push validation (runs all CI checks locally)
@echo "π Running complete pre-push validation..."
@$(MAKE) ci-format
@$(MAKE) ci-check
@echo "β
All pre-push checks passed! Safe to push."
fix-and-commit: ## Fix formatting and create a commit if needed
@echo "π§ Checking and fixing formatting..."
@if [ "$$(gofmt -s -l . | wc -l)" -gt 0 ]; then \
gofmt -s -w . && \
git add -A && \
git commit -m "style: auto-fix code formatting" && \
echo "β
Formatting fixed and committed"; \
else \
echo "β
No formatting issues found"; \
fi
# Local CI testing with act
test-ci-local: ## Run GitHub Actions locally with act (requires: brew install act)
@echo "π³ Running GitHub Actions locally with act..."
@if ! command -v act >/dev/null 2>&1; then \
echo "β act not found. Install with: brew install act"; \
exit 1; \
fi
act -j cross-platform --matrix os:ubuntu-latest --matrix go-version:1.24
test-ci-windows: ## Test Windows CI locally with act
@echo "πͺ Testing Windows CI locally..."
@if ! command -v act >/dev/null 2>&1; then \
echo "β act not found. Install with: brew install act"; \
exit 1; \
fi
@echo "π§Ή Clearing act cache..."
@rm -rf ~/.cache/act || true
@echo "π§Ή Cleaning up act containers..."
@if command -v docker >/dev/null 2>&1; then docker ps -aq --filter "name=act-" | xargs -r docker rm -f || true; fi
act workflow_dispatch -W .github/workflows/cross-platform.yml --matrix os:windows-latest --matrix go-version:1.24 --container-architecture linux/amd64
test-ci-macos: ## Test macOS CI locally with act
@echo "π Testing macOS CI locally..."
@if ! command -v act >/dev/null 2>&1; then \
echo "β act not found. Install with: brew install act"; \
exit 1; \
fi
@echo "π§Ή Clearing act cache..."
@rm -rf ~/.cache/act || true
@echo "π§Ή Cleaning up act containers..."
@if command -v docker >/dev/null 2>&1; then docker ps -aq --filter "name=act-" | xargs -r docker rm -f || true; fi
act workflow_dispatch -W .github/workflows/cross-platform.yml --matrix os:macos-latest --matrix go-version:1.24 --container-architecture linux/amd64
test-ci-ubuntu: ## Test Ubuntu CI locally with act
@echo "π§ Testing Ubuntu CI locally..."
@if ! command -v act >/dev/null 2>&1; then \
echo "β act not found. Install with: brew install act"; \
exit 1; \
fi
@echo "π§Ή Clearing act cache..."
@rm -rf ~/.cache/act || true
@echo "π§Ή Cleaning up act containers..."
@if command -v docker >/dev/null 2>&1; then docker ps -aq --filter "name=act-" | xargs -r docker rm -f || true; fi
act workflow_dispatch -W .github/workflows/cross-platform.yml --matrix os:ubuntu-latest --matrix go-version:1.24 --container-architecture linux/amd64
test-ci-all: ## Test cross-platform compatibility locally with act (Ubuntu only, Windows/macOS require GitHub Actions)
@echo "π Testing all platforms locally with act..."
@if ! command -v act >/dev/null 2>&1; then \
echo "β act not found. Install with: brew install act"; \
echo "π Install with: brew install act"; \
exit 1; \
fi
@echo "π§Ή Clearing act cache for fresh execution..."
@rm -rf ~/.cache/act || true
@echo "π§Ή Cleaning up act containers..."
@if command -v docker >/dev/null 2>&1; then docker ps -aq --filter "name=act-" | xargs -r docker rm -f || true; fi
@echo "1οΈβ£ Testing Ubuntu (cross-platform workflow)..."
@ubuntu_success=0; \
if act workflow_dispatch -W .github/workflows/cross-platform.yml --matrix os:ubuntu-latest --matrix go-version:1.24 --container-architecture linux/amd64 2>&1 | tee /tmp/ubuntu-test.log; then \
if grep -q "β
Tests Passed: ubuntu-latest" /tmp/ubuntu-test.log; then \
echo "β
Ubuntu tests passed"; \
ubuntu_success=1; \
fi; \
fi; \
echo "2οΈβ£ Testing Windows (cross-platform workflow)..."; \
act workflow_dispatch -W .github/workflows/cross-platform.yml --matrix os:windows-latest --matrix go-version:1.24 --container-architecture linux/amd64 || echo "π§ Windows test skipped (expected with act)"; \
echo "3οΈβ£ Testing macOS (cross-platform workflow)..."; \
act workflow_dispatch -W .github/workflows/cross-platform.yml --matrix os:macos-latest --matrix go-version:1.24 --container-architecture linux/amd64 || echo "π§ macOS test skipped (expected with act)"; \
echo "β
Cross-platform tests completed!"; \
echo "π‘ Note: Only Ubuntu can be fully tested locally with act."; \
echo " Windows and macOS testing requires GitHub Actions environment."; \
if [ $$ubuntu_success -eq 1 ]; then \
echo "β
Primary platform (Ubuntu) tests passed - ready for CI"; \
exit 0; \
else \
echo "β Ubuntu tests failed - check output above"; \
exit 1; \
fi
test-cross-compile: ## Quick cross-compilation test for Windows
@echo "π Testing cross-compilation for Windows..."
GOOS=windows GOARCH=amd64 go build ./...
GOOS=windows GOARCH=amd64 go test -c ./pkg/plugin/...
@echo "β
Cross-compilation successful"
ci-vet: ## Run go vet exactly like CI
@echo "π Running go vet (CI equivalent)..."
go vet $$(go list ./... | grep -v '/examples/')
ci-test-core: ## Run core library tests like CI
@echo "π§ͺ Running Core Library tests (CI equivalent)..."
go test -v -race -coverprofile=coverage-library.out . ./pkg/...
# Release targets
release-check: test-race build-all ## Pre-release validation
@echo "Release checks complete"
# Quick targets for common workflows
quick: fmt lint test ## Quick development cycle (format, lint, test)
full: clean tidy fmt lint test-race test-coverage build ## Full build and validation cycle
# Help target should be first for default
.DEFAULT_GOAL := help