-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
521 lines (426 loc) · 16.9 KB
/
Makefile
File metadata and controls
521 lines (426 loc) · 16.9 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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
# Ampel Root Makefile
# Unified interface for build, test, and deployment operations
.PHONY: help
.PHONY: install build build-release clean
.PHONY: dev dev-api dev-worker dev-frontend
.PHONY: test test-backend test-frontend test-integration test-coverage test-backend-coverage test-frontend-coverage
.PHONY: lint lint-backend lint-frontend lint-docs lint-fix lint-fix-backend lint-fix-frontend lint-fix-docs
.PHONY: format format-backend format-frontend format-docs format-check format-check-docs
.PHONY: audit audit-backend audit-frontend
.PHONY: license-check license-check-backend license-check-frontend
.PHONY: outdated outdated-backend outdated-frontend
.PHONY: upgrade upgrade-backend upgrade-frontend upgrade-latest
.PHONY: docker docker-build docker-up docker-down docker-restart docker-logs
.PHONY: deploy deploy-fly
.PHONY: gh-ci gh-release gh-watch gh-runs gh-status
.PHONY: i18n build-i18n build-i18n-release test-i18n install-i18n clean-i18n
# =============================================================================
# Help
# =============================================================================
help:
@echo "Ampel Makefile - Unified build interface"
@echo ""
@echo "Setup & Dependencies:"
@echo " install - Install all dependencies (backend + frontend)"
@echo ""
@echo "Build:"
@echo " build - Build everything (debug)"
@echo " build-release - Build everything (release)"
@echo " clean - Clean all build artifacts"
@echo ""
@echo "Development:"
@echo " dev - Start all services for development"
@echo " dev-api - Start API server only"
@echo " dev-worker - Start background worker only"
@echo " dev-frontend - Start frontend dev server only"
@echo ""
@echo "Testing:"
@echo " test - Run all tests"
@echo " test-backend - Run backend tests only"
@echo " test-frontend - Run frontend tests only"
@echo " test-integration - Run integration tests with PostgreSQL (same as CI)"
@echo " test-coverage - Run all tests with coverage reports"
@echo " test-backend-coverage - Backend tests with coverage (uses cargo-llvm-cov)"
@echo " test-frontend-coverage - Frontend tests with coverage"
@echo ""
@echo "Code Quality:"
@echo " lint - Run all linters"
@echo " lint-fix - Auto-fix lint issues"
@echo " format - Format all code"
@echo " format-check - Check formatting without changes"
@echo ""
@echo "Security & Dependencies:"
@echo " audit - Run security audits"
@echo " license-check - Check license compliance"
@echo " outdated - List outdated dependencies"
@echo " upgrade - Upgrade dependencies to latest compatible"
@echo ""
@echo "Docker:"
@echo " docker-build - Build all Docker images"
@echo " docker-up - Start all services with Docker Compose"
@echo " docker-down - Stop all Docker services"
@echo " docker-restart - Restart services with rebuild (down + up --build)"
@echo " docker-logs - View Docker logs"
@echo ""
@echo "Deployment:"
@echo " deploy-fly - Deploy to Fly.io"
@echo ""
@echo "GitHub Actions (requires gh CLI):"
@echo " gh-ci - Trigger CI workflow on current branch"
@echo " gh-release V=x.y.z - Create and push a release tag"
@echo " gh-watch - Watch the latest workflow run"
@echo " gh-runs - List recent workflow runs"
@echo " gh-status - View CI workflow status"
@echo ""
@echo "Internationalization (i18n):"
@echo " build-i18n - Build ampel-i18n CLI tool (debug)"
@echo " build-i18n-release - Build ampel-i18n (release)"
@echo " test-i18n - Run tests for i18n-builder crate"
@echo " install-i18n - Install ampel-i18n CLI tool locally"
@echo " clean-i18n - Clean i18n-builder build artifacts"
@echo " i18n ARGS='...' - Run ampel-i18n tool (e.g., make i18n ARGS='--help')"
# =============================================================================
# Setup & Dependencies
# =============================================================================
install: install-backend install-frontend
install-backend:
@echo "==> Checking Rust toolchain..."
rustup show
install-frontend:
@echo "==> Installing frontend dependencies..."
cd frontend && pnpm install
# =============================================================================
# Build
# =============================================================================
build: build-backend build-frontend
build-backend:
@echo "==> Building backend..."
cargo build
build-release: build-release-backend build-frontend
build-release-backend:
@echo "==> Building backend (release)..."
cargo build --release
build-frontend:
@echo "==> Building frontend..."
cd frontend && pnpm run build
clean: clean-backend clean-frontend
clean-backend:
@echo "==> Cleaning backend..."
cargo clean
clean-frontend:
@echo "==> Cleaning frontend..."
cd frontend && rm -rf dist node_modules/.vite
# =============================================================================
# Development
# =============================================================================
dev:
@echo "Starting all services..."
@echo "Run these in separate terminals:"
@echo " make dev-api"
@echo " make dev-worker"
@echo " make dev-frontend"
@echo ""
@echo "Or use: docker compose up"
dev-api:
@echo "==> Starting API server..."
cargo run --bin ampel-api
dev-worker:
@echo "==> Starting background worker..."
cargo run --bin ampel-worker
dev-frontend:
@echo "==> Starting frontend dev server..."
cd frontend && pnpm run dev
# =============================================================================
# Testing
# =============================================================================
test: test-backend test-frontend
test-backend:
@echo "==> Running backend tests..."
cargo test --all-features
# Run integration tests with PostgreSQL (same as CI)
# Uses JWT_SECRET and ENCRYPTION_KEY from .env file
test-integration:
@echo "==> Running integration tests with PostgreSQL (CI mode)..."
@command -v cargo-nextest >/dev/null 2>&1 || { \
echo "Installing cargo-nextest..."; \
cargo install cargo-nextest --locked; \
}
@# Ensure PostgreSQL is running
@docker compose -f docker/docker-compose.yml up -d postgres
@echo "Waiting for PostgreSQL to be ready..."
@until docker compose -f docker/docker-compose.yml exec -T postgres pg_isready -U ampel >/dev/null 2>&1; do \
sleep 1; \
done
@# Create test database if it doesn't exist
@docker compose -f docker/docker-compose.yml exec -T postgres \
psql -U ampel -c "CREATE DATABASE ampel_test;" 2>/dev/null || true
@# Run tests with CI environment, sourcing secrets from .env
@set -a && . ./.env && set +a && \
DATABASE_URL=postgres://ampel:ampel@localhost:5432/ampel_test \
TEST_DATABASE_URL=postgres://ampel:ampel@localhost:5432 \
TEST_DATABASE_TYPE=postgres \
RUST_LOG=info \
cargo nextest run \
--all-features \
--no-fail-fast \
--test-threads 2 \
--retries 3 \
--failure-output immediate-final
test-frontend:
@echo "==> Running frontend tests..."
cd frontend && pnpm run test -- --run
# Coverage targets - auto-install tools if missing
# Uses cargo-llvm-cov for 5-10x faster coverage than tarpaulin
test-coverage: test-backend-coverage test-frontend-coverage
@echo ""
@echo "==> Coverage reports generated:"
@echo " Backend: coverage/lcov.info, coverage/html/"
@echo " Frontend: frontend/coverage/"
test-backend-coverage:
@echo "==> Running backend tests with coverage (cargo-llvm-cov)..."
@command -v cargo-llvm-cov >/dev/null 2>&1 || { \
echo "Installing cargo-llvm-cov..."; \
cargo install cargo-llvm-cov --locked; \
}
@rustup component add llvm-tools-preview 2>/dev/null || true
@mkdir -p coverage
cargo llvm-cov \
--all-features \
--workspace \
--html \
--output-dir coverage
cargo llvm-cov \
--all-features \
--workspace \
--lcov \
--output-path coverage/lcov.info
@echo ""
@echo "==> Backend coverage report: coverage/html/index.html"
test-frontend-coverage:
@echo "==> Running frontend tests with coverage..."
cd frontend && pnpm run test -- --run --coverage
@echo ""
@echo "==> Frontend coverage report: frontend/coverage/"
# =============================================================================
# Code Quality
# =============================================================================
lint: lint-backend lint-frontend lint-docs
lint-backend:
@echo "==> Linting backend..."
cargo clippy --all-targets --all-features -- -D warnings
lint-frontend:
@echo "==> Linting frontend..."
cd frontend && pnpm run lint && pnpm run type-check
lint-docs:
@echo "==> Linting markdown files..."
pnpm run lint:md
lint-fix: lint-fix-backend lint-fix-frontend lint-fix-docs
lint-fix-backend:
@echo "==> Auto-fixing backend lint issues..."
cargo clippy --all-targets --all-features --fix --allow-dirty --allow-staged
lint-fix-frontend:
@echo "==> Auto-fixing frontend lint issues..."
cd frontend && pnpm run lint --fix
lint-fix-docs:
@echo "==> Auto-fixing markdown lint issues..."
pnpm run lint:md:fix
format: format-backend format-frontend format-docs
format-backend:
@echo "==> Formatting backend..."
cargo fmt --all
format-frontend:
@echo "==> Formatting frontend..."
cd frontend && pnpm run format
format-docs:
@echo "==> Formatting markdown files..."
pnpm run format
format-check: format-check-backend format-check-frontend format-check-docs
format-check-backend:
@echo "==> Checking backend formatting..."
cargo fmt --all -- --check
format-check-frontend:
@echo "==> Checking frontend formatting..."
cd frontend && pnpm run format:check
format-check-docs:
@echo "==> Checking markdown formatting..."
pnpm run format:check
# =============================================================================
# Security
# =============================================================================
audit: audit-backend audit-frontend
audit-backend:
@echo "==> Auditing backend dependencies..."
@command -v cargo-audit >/dev/null 2>&1 || { echo "Installing cargo-audit..."; cargo install cargo-audit; }
cargo audit
audit-frontend:
@echo "==> Auditing frontend dependencies..."
cd frontend && pnpm audit
license-check: license-check-backend license-check-frontend
license-check-backend:
@echo "==> Checking backend license compliance..."
@command -v cargo-deny >/dev/null 2>&1 || { echo "Installing cargo-deny..."; cargo install cargo-deny; }
cargo deny check licenses
license-check-frontend:
@echo "==> Checking frontend license compliance..."
cd frontend && npx license-checker --summary
# =============================================================================
# Dependency Management
# =============================================================================
outdated: outdated-backend outdated-frontend
outdated-backend:
@echo "==> Checking for outdated backend dependencies..."
@command -v cargo-outdated >/dev/null 2>&1 || { echo "Installing cargo-outdated..."; cargo install cargo-outdated; }
cargo outdated -R
outdated-frontend:
@echo "==> Checking for outdated frontend dependencies..."
cd frontend && pnpm outdated || true
upgrade: upgrade-backend upgrade-frontend
upgrade-backend:
@echo "==> Upgrading backend dependencies..."
cargo update
@echo "Dependencies updated in Cargo.lock"
upgrade-frontend:
@echo "==> Upgrading frontend dependencies..."
cd frontend && pnpm update
@echo "Dependencies updated in pnpm-lock.yaml"
# Upgrade to latest versions (may break semver constraints)
upgrade-latest: upgrade-latest-backend upgrade-latest-frontend
upgrade-latest-backend:
@echo "==> Upgrading backend to latest versions..."
@command -v cargo-edit >/dev/null 2>&1 || { echo "Installing cargo-edit..."; cargo install cargo-edit; }
cargo upgrade
cargo update
upgrade-latest-frontend:
@echo "==> Upgrading frontend to latest versions..."
cd frontend && pnpm update --latest
# =============================================================================
# Docker
# =============================================================================
docker-build:
@echo "==> Building Docker images..."
cd docker && docker compose build
docker-up:
@echo "==> Starting Docker services..."
cd docker && docker compose up -d
docker-down:
@echo "==> Stopping Docker services..."
cd docker && docker compose down
docker-restart:
@echo "==> Restarting Docker services with rebuild..."
cd docker && docker compose down && docker compose up -d --build
docker-logs:
cd docker && docker compose logs -f
docker-clean:
@echo "==> Cleaning Docker resources..."
cd docker && docker compose down -v --rmi local
# =============================================================================
# Deployment
# =============================================================================
deploy-fly: deploy-fly-api deploy-fly-worker deploy-fly-frontend
@echo "==> Deployment complete!"
deploy-fly-api:
@echo "==> Deploying API to Fly.io..."
fly deploy --config fly.api.toml
deploy-fly-worker:
@echo "==> Deploying worker to Fly.io..."
fly deploy --config fly.worker.toml
deploy-fly-frontend:
@echo "==> Deploying frontend to Fly.io..."
fly deploy --config fly.frontend.toml
# =============================================================================
# CI helpers (used by GitHub Actions)
# =============================================================================
ci-backend: format-check-backend lint-backend test-backend build-release-backend
ci-frontend: lint-frontend test-frontend build-frontend
ci: ci-backend ci-frontend
@echo "==> All CI checks passed!"
# =============================================================================
# GitHub Actions (requires gh CLI)
# =============================================================================
# Check if gh CLI is available
.PHONY: _check-gh
_check-gh:
@command -v gh >/dev/null 2>&1 || { echo "Error: gh CLI is not installed. Install from https://cli.github.com/"; exit 1; }
@gh auth status >/dev/null 2>&1 || { echo "Error: gh CLI is not authenticated. Run 'gh auth login'"; exit 1; }
# Trigger CI workflow on current branch
gh-ci: _check-gh
@echo "==> Triggering CI workflow..."
@BRANCH=$$(git rev-parse --abbrev-ref HEAD); \
gh workflow run ci.yml --ref $$BRANCH; \
echo "CI workflow triggered on branch: $$BRANCH"; \
echo "Run 'make gh-watch' to monitor progress"
# Create a release tag and trigger release workflow
# Usage: make gh-release V=1.0.0
gh-release: _check-gh
ifndef V
$(error Version not specified. Usage: make gh-release V=x.y.z)
endif
@echo "==> Creating release v$(V)..."
@if git rev-parse "v$(V)" >/dev/null 2>&1; then \
echo "Error: Tag v$(V) already exists"; \
exit 1; \
fi
@git tag -a "v$(V)" -m "Release v$(V)"
@git push origin "v$(V)"
@echo "Release v$(V) tag pushed. Release workflow will start automatically."
@echo "Run 'make gh-watch' to monitor progress"
# Watch the latest workflow run
gh-watch: _check-gh
@echo "==> Watching latest workflow run..."
@gh run watch
# List recent workflow runs
gh-runs: _check-gh
@gh run list --limit 10
# View CI workflow status
gh-status: _check-gh
@gh run list --workflow=ci.yml --limit 5
# =============================================================================
# Internationalization (i18n)
# =============================================================================
# Build the ampel-i18n CLI tool (debug mode)
build-i18n:
@echo "==> Building ampel-i18n CLI tool..."
cargo build --package ampel-i18n-builder --bin ampel-i18n
# Build the ampel-i18n CLI tool (release mode)
build-i18n-release:
@echo "==> Building ampel-i18n CLI tool (release)..."
cargo build --package ampel-i18n-builder --bin ampel-i18n --release
# Run tests for the i18n-builder crate only
test-i18n:
@echo "==> Running i18n-builder tests..."
cargo test --package ampel-i18n-builder --all-features
# Run tests for i18n-builder with coverage
test-i18n-coverage:
@echo "==> Running i18n-builder tests with coverage..."
@command -v cargo-llvm-cov >/dev/null 2>&1 || { \
echo "Installing cargo-llvm-cov..."; \
cargo install cargo-llvm-cov --locked; \
}
@rustup component add llvm-tools-preview 2>/dev/null || true
@mkdir -p coverage/i18n
cargo llvm-cov \
--package ampel-i18n-builder \
--all-features \
--html \
--output-dir coverage/i18n
@echo ""
@echo "==> I18n coverage report: coverage/i18n/index.html"
# Install the ampel-i18n tool to ~/.cargo/bin
install-i18n:
@echo "==> Installing ampel-i18n CLI tool..."
cargo install --path crates/ampel-i18n-builder --bin ampel-i18n --force
@echo ""
@echo "ampel-i18n installed to ~/.cargo/bin/ampel-i18n"
@echo "Run 'cargo i18n --help' to get started"
# Clean i18n-builder build artifacts
clean-i18n:
@echo "==> Cleaning i18n-builder artifacts..."
cargo clean --package ampel-i18n-builder
# Run the ampel-i18n tool with custom arguments
# Usage: make i18n ARGS='--help'
# Usage: make i18n ARGS='generate --lang es'
i18n:
@echo "==> Running ampel-i18n..."
cargo run --package ampel-i18n-builder --bin ampel-i18n -- $(ARGS)
# Monitoring targets
include Makefile.monitoring