forked from qf-studio/pilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
289 lines (246 loc) · 9.92 KB
/
Makefile
File metadata and controls
289 lines (246 loc) · 9.92 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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
.PHONY: build run test test-e2e clean install lint fmt deps dev install-hooks check-secrets gate check-integration auto-fix test-short test-integration test-chaos test-wiring package release docker-build docker-push desktop-dev desktop-build desktop-build-windows desktop-build-linux desktop desktop-deps desktop-package desktop-dmg desktop-clean build-with-dashboard
# Variables
BINARY_NAME=pilot
VERSION?=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_TIME=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.buildTime=$(BUILD_TIME)"
# Default target
all: build
# Build the binary
build:
@echo "Building $(BINARY_NAME)..."
go build $(LDFLAGS) -o bin/$(BINARY_NAME) ./cmd/pilot
# Build for all platforms
build-all:
@echo "Building for all platforms..."
GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o bin/$(BINARY_NAME)-darwin-amd64 ./cmd/pilot
GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o bin/$(BINARY_NAME)-darwin-arm64 ./cmd/pilot
GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o bin/$(BINARY_NAME)-linux-amd64 ./cmd/pilot
GOOS=linux GOARCH=arm64 go build $(LDFLAGS) -o bin/$(BINARY_NAME)-linux-arm64 ./cmd/pilot
# Package binaries into tar.gz archives for release
# Binary inside tar is named "pilot" (not pilot-darwin-arm64) to match upgrade code.
# COPYFILE_DISABLE=1 prevents macOS tar from adding ._* resource fork entries.
package: build-all
@echo "📦 Packaging binaries..."
@for arch in darwin-amd64 darwin-arm64 linux-amd64 linux-arm64; do \
cp bin/$(BINARY_NAME)-$$arch bin/$(BINARY_NAME) && \
COPYFILE_DISABLE=1 tar czf bin/$(BINARY_NAME)-$$arch.tar.gz -C bin $(BINARY_NAME) && \
rm bin/$(BINARY_NAME); \
done
@shasum -a 256 bin/*.tar.gz > bin/checksums.txt
@echo "✅ Packages created"
# Run the daemon
run: build
./bin/$(BINARY_NAME) start
# Run in development mode with auto-reload
dev:
@echo "Running in development mode..."
go run ./cmd/pilot start
# Install dependencies
deps:
go mod download
go mod tidy
# Run tests
test:
go test -v -race ./...
# Run tests with coverage
test-coverage:
go test -v -race -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
# Run end-to-end tests (Go-based workflow tests + shell tests)
test-e2e: build
@echo "Running E2E workflow tests..."
go test -v -count=1 -timeout 60s ./e2e/...
@echo "Running E2E shell tests..."
./scripts/test-e2e.sh
# Run only Go-based E2E workflow tests (faster, no external deps)
test-e2e-go:
@echo "Running E2E workflow tests..."
go test -v -count=1 -timeout 60s ./e2e/...
# Run end-to-end tests with live Claude Code execution
test-e2e-live: build
@echo "Running E2E tests (including live Claude Code)..."
RUN_LIVE_TESTS=true ./scripts/test-e2e.sh
# Lint the code
lint:
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run; \
else \
echo "golangci-lint not installed, skipping..."; \
fi
# Format the code
fmt:
go fmt ./...
@if command -v goimports >/dev/null 2>&1; then \
goimports -w .; \
fi
# Clean build artifacts
clean:
rm -rf bin/
rm -f coverage.out coverage.html
# Install to ~/go/bin (or GOBIN)
install:
go install $(LDFLAGS) ./cmd/pilot
# Install to /usr/local/bin (requires sudo)
install-global: build
sudo cp bin/$(BINARY_NAME) /usr/local/bin/
# Generate mocks for testing
mocks:
@if command -v mockgen >/dev/null 2>&1; then \
go generate ./...; \
else \
echo "mockgen not installed, skipping..."; \
fi
# Run the orchestrator tests (Python)
test-orchestrator:
cd orchestrator && python -m pytest -v
# Install git hooks (pre-commit for secret pattern detection)
install-hooks:
@./scripts/install-hooks.sh
# Check for realistic secret patterns in test files
check-secrets:
@./scripts/check-secret-patterns.sh
# Run short tests (for pre-push gate)
test-short:
go test -short -race ./...
# Run integration tests (build tag separated from unit tests)
test-integration:
go test -v -race -tags=integration ./...
# Run chaos tests for fault injection scenarios
# Tests system behavior under adverse conditions: network failures, API errors, timeouts
test-chaos:
@echo "🔥 Running chaos tests..."
go test -v -race -timeout 5m ./internal/chaos/...
# Run wiring tests (component initialization parity)
test-wiring:
go test -v -count=1 -timeout 30s ./internal/wiring/...
# Run integration checks (orphan commands, build tags, etc.)
check-integration:
@./scripts/check-integration.sh
# Auto-fix common issues (formatting, imports, lint)
auto-fix:
@./scripts/auto-fix.sh
# Pre-push validation gate - runs all checks
gate:
@./scripts/pre-push-gate.sh
# Release - creates tag, builds, packages, and publishes to GitHub
# Usage: make release V=0.14.6 NOTES="Release notes here"
release:
ifndef V
$(error V is required. Usage: make release V=0.14.6 NOTES="Release notes")
endif
@echo "🚀 Creating release v$(V)..."
@if [ -n "$$(git status --porcelain)" ]; then \
echo "❌ Error: Working directory not clean. Commit or stash changes first."; \
exit 1; \
fi
@if [ "$$(git branch --show-current)" != "main" ]; then \
echo "❌ Error: Must be on main branch to release."; \
exit 1; \
fi
@echo "📌 Creating and pushing git tag v$(V)..."
git tag v$(V)
git push origin v$(V)
@echo "🔨 Building and packaging binaries..."
$(MAKE) package VERSION=v$(V)
@echo "📦 Creating GitHub release..."
gh release create v$(V) \
bin/$(BINARY_NAME)-darwin-amd64.tar.gz \
bin/$(BINARY_NAME)-darwin-arm64.tar.gz \
bin/$(BINARY_NAME)-linux-amd64.tar.gz \
bin/$(BINARY_NAME)-linux-arm64.tar.gz \
bin/checksums.txt \
--title "pilot v$(V)" \
--notes "$(if $(NOTES),$(NOTES),Release v$(V))"
@echo "✅ Released v$(V)"
@echo " Run 'pilot upgrade' to update"
# Build Docker image for standalone Pilot
docker-build:
docker build \
--build-arg VERSION=$(VERSION) \
--build-arg BUILD_TIME=$(BUILD_TIME) \
-t pilot:$(VERSION) \
.
# Push Docker image to GitHub Container Registry
docker-push:
docker tag pilot:$(VERSION) ghcr.io/alekspetrov/pilot:$(VERSION)
docker push ghcr.io/alekspetrov/pilot:$(VERSION)
# Build with embedded React dashboard at /dashboard/ (GH-1612)
build-with-dashboard: desktop-deps
@echo "Building frontend for gateway embedding..."
cd desktop/frontend && VITE_BASE_PATH=/dashboard/ npm run build
@rm -rf cmd/pilot/dashboard_dist
@cp -r desktop/frontend/dist cmd/pilot/dashboard_dist
@echo "Building $(BINARY_NAME) with embedded dashboard..."
go build -tags embed_dashboard $(LDFLAGS) -o bin/$(BINARY_NAME) ./cmd/pilot
@rm -rf cmd/pilot/dashboard_dist
# Desktop app (Wails v2 + React)
desktop-deps:
cd desktop/frontend && npm ci
desktop-dev:
cd desktop && wails dev
desktop-build: desktop-deps
cd desktop && wails build -platform darwin/universal -ldflags "-X main.version=$(VERSION)"
desktop: desktop-build
desktop-package: desktop-build
@echo "Packaging Pilot.app..."
@mkdir -p bin
cd desktop/build/bin && COPYFILE_DISABLE=1 zip -r ../../../bin/Pilot-macOS-$(VERSION).zip Pilot.app
@echo "Created bin/Pilot-macOS-$(VERSION).zip"
desktop-build-windows: desktop-deps
cd desktop && wails build -platform windows/amd64 -ldflags "-X main.version=$(VERSION)"
desktop-build-linux: desktop-deps
cd desktop && wails build -platform linux/amd64 -ldflags "-X main.version=$(VERSION)"
desktop-dmg: desktop-build
@echo "Creating Pilot.dmg..."
@mkdir -p bin
@mkdir -p /tmp/pilot-dmg-staging
@cp -R desktop/build/bin/Pilot.app /tmp/pilot-dmg-staging/
@ln -sf /Applications /tmp/pilot-dmg-staging/Applications
@hdiutil create -volname "Pilot" -srcfolder /tmp/pilot-dmg-staging \
-ov -format UDZO bin/Pilot-macOS-$(VERSION).dmg
@rm -rf /tmp/pilot-dmg-staging
@echo "Created bin/Pilot-macOS-$(VERSION).dmg"
desktop-clean:
rm -rf desktop/build/bin desktop/frontend/dist desktop/frontend/node_modules
# Help
help:
@echo "Pilot Makefile Commands:"
@echo ""
@echo " make build Build the binary"
@echo " make build-all Build for all platforms"
@echo " make run Build and run the daemon"
@echo " make dev Run in development mode"
@echo " make deps Install dependencies"
@echo " make test Run unit tests"
@echo " make test-coverage Run tests with coverage"
@echo " make test-e2e Run end-to-end tests (Go + shell)"
@echo " make test-e2e-go Run Go-based E2E workflow tests"
@echo " make test-e2e-live Run E2E tests with live Claude"
@echo " make lint Run linter"
@echo " make fmt Format code"
@echo " make clean Clean build artifacts"
@echo " make install Install to GOPATH/bin"
@echo " make install-global Install to /usr/local/bin"
@echo " make install-hooks Install git pre-commit/pre-push hooks"
@echo " make check-secrets Check for secret patterns in tests"
@echo " make check-integration Check for orphan code"
@echo " make gate Run pre-push validation gate"
@echo " make auto-fix Auto-fix common issues"
@echo " make test-short Run tests in short mode"
@echo " make test-integration Run integration tests"
@echo " make test-chaos Run chaos/fault injection tests"
@echo " make package Package binaries into tar.gz archives"
@echo " make release Create release (V=0.x.x required)"
@echo " make docker-build Build Docker image (tag: pilot:VERSION)"
@echo " make docker-push Push image to ghcr.io/alekspetrov/pilot"
@echo " make build-with-dashboard Build with embedded React dashboard"
@echo " make desktop-deps Install desktop frontend dependencies"
@echo " make desktop-dev Run desktop app in dev mode"
@echo " make desktop-build Build desktop app (darwin/universal)"
@echo " make desktop-build-windows Build desktop app (windows/amd64)"
@echo " make desktop-build-linux Build desktop app (linux/amd64)"
@echo " make desktop-package Package Pilot.app into zip (VERSION=vX.Y.Z)"
@echo " make desktop-dmg Create Pilot.dmg installer (VERSION=vX.Y.Z)"
@echo " make desktop-clean Clean desktop build artifacts"
@echo ""