-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
212 lines (186 loc) · 7.85 KB
/
Copy pathMakefile
File metadata and controls
212 lines (186 loc) · 7.85 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
# =============================================================================
# Root Makefile - CI/CD and Orchestration
# =============================================================================
# This Makefile provides CI validation commands and project-wide orchestration.
# For development workflows, use subfolder Makefiles directly:
# - Backend: cd backend && make dev
# - Frontend: cd frontend && make dev
# - Docs: cd docs && make serve-docs
#
# Root targets are optimized for CI pipelines and pre-push validation.
# =============================================================================
.PHONY: help
help: ## Show available targets
@echo "============================================================================="
@echo "Root Makefile - CI/CD Orchestration"
@echo "============================================================================="
@echo ""
@echo "📋 Prerequisites:"
@echo " • make"
@echo " • npm + npx (Node.js package management)"
@echo " • uv (Python project management - for backend/docs)"
@echo " • docker (for database and containerized services)"
@echo " • helm (for Kubernetes deployments - optional)"
@echo ""
@echo "📦 Setup:"
@echo " make install Install all dependencies and git hooks"
@echo " make clean Clean all build artifacts"
@echo ""
@echo "🗄️ Database Services:"
@echo " make run-db Start PostgreSQL database (docker compose)"
@echo " make stop-db Stop database services"
@echo " make clean-db Clean database (remove volumes)"
@echo ""
@echo "🔍 CI Validation (use before pushing to dev/stage/main):"
@echo " make ci Run all CI checks (lint + type-check + test + build)"
@echo " make lint Run all linters"
@echo " make type-check Run type checking"
@echo " make test Run all tests"
@echo " make build Build all projects"
@echo ""
@echo "✨ Code Formatting:"
@echo " make format Format all code"
@echo ""
@echo "📚 Documentation:"
@echo " make build-docs Build documentation"
@echo " make serve-docs Serve documentation with live reload"
@echo ""
@echo "💡 Development:"
@echo " Run dev servers from subfolders:"
@echo " cd backend && make dev (starts backend on :8000)"
@echo " cd frontend && make dev (starts frontend on :9000)"
@echo ""
@echo "============================================================================="
# =============================================================================
# Setup & Installation
# =============================================================================
.PHONY: install
install: ## Install all dependencies and set up git hooks
@echo "Installing root npm dependencies (lefthook + prettier)..."
@command -v node >/dev/null 2>&1 || { echo "❌ node not found. Run: nvm install"; exit 1; }
@echo "Node: $$(node --version), npm: $$(npm --version)"
@npm run setup:fresh
@echo "Installing backend dependencies..."
cd backend && $(MAKE) install
@echo "Installing frontend dependencies..."
cd frontend && $(MAKE) install
@echo "Installing docs dependencies..."
cd docs && $(MAKE) install
@echo "Install env files if missing..."
@if [ ! -f .database.env ]; then cp .database.env.example .database.env; fi
@echo "✅ Setup complete!"
.PHONY: clean
clean: ## Remove all build artifacts and dependencies
@echo "Cleaning root dependencies..."
rm -rf node_modules package-lock.json
@echo "Cleaning backend..."
cd backend && $(MAKE) clean
@echo "Cleaning frontend..."
cd frontend && $(MAKE) clean
@echo "✅ Clean complete!"
# =============================================================================
# Development - Database Services
# =============================================================================
.PHONY: run-db
run-db:
docker compose up -d --pull=always postgres
.PHONY: stop-db
stop-db:
docker compose down
.PHONY: connect-db
connect-db:
docker compose exec postgres psql -U co2_user -d co2_calculator
.PHONY: clean-db
clean-db:
docker compose down -v
docker volume rm co2-calculator_postgres-data-18 || true
# =============================================================================
# CI/CD - Validation Commands
# =============================================================================
# use to include test in frontend/backend and docker build
# && \
# $(MAKE) test && \
# $(MAKE) build
.PHONY: ci
ci: ## Run all CI checks (use before pushing to dev/stage/main)
@echo "Running CI validation pipeline..."
@set -e; \
$(MAKE) lint && \
$(MAKE) type-check
@echo "✅ All CI checks passed!"
# =============================================================================
# Code Formatting
# =============================================================================
.PHONY: format
format: ## Format all code (root, backend, frontend, docs, helm)
@echo "\033[36mFormatting root files...\033[0m"
@npx prettier --write "*.md" "*.json" "*.yml" --ignore-unknown --ignore-path .prettierignore
@if [ -d "backend" ]; then $(MAKE) -C backend format FILES="."; fi
@if [ -d "frontend" ]; then $(MAKE) -C frontend format FILES="."; fi
@echo "\033[32m✅ Formatting complete!\033[0m"
# =============================================================================
# Linting
# =============================================================================
.PHONY: lint
lint: ## Run all linters (backend, frontend, docs, helm)
@echo "\033[36mRunning linters...\033[0m"
@set -e; \
if [ -d "backend" ]; then \
echo "\033[33mLinting backend...\033[0m"; \
$(MAKE) -C backend lint FILES="."; \
fi; \
if [ -d "frontend" ]; then \
echo "\033[33mLinting frontend...\033[0m"; \
$(MAKE) -C frontend lint FILES="."; \
fi; \
if [ -d "docs" ]; then \
echo "\033[33mLinting docs...\033[0m"; \
$(MAKE) -C docs lint FILES="."; \
fi; \
if [ -d "helm" ]; then \
echo "\033[33mLinting helm...\033[0m"; \
$(MAKE) -C helm lint FILES="."; \
fi
@echo "\033[32m✅ Linting complete!\033[0m"
# =============================================================================
# Type Checking
# =============================================================================
.PHONY: type-check
type-check: ## Run type checking (backend + frontend)
@echo "\033[36mRunning type checks...\033[0m"
@set -e; \
if [ -d "backend" ]; then $(MAKE) -C backend type-check FILES="."; fi; \
if [ -d "frontend" ]; then $(MAKE) -C frontend type-check FILES="."; fi
@echo "\033[32m✅ Type checking complete!\033[0m"
# =============================================================================
# Testing
# =============================================================================
.PHONY: test
test: ## Run all tests (backend + frontend)
@echo "\033[36mRunning tests...\033[0m"
@set -e; \
if [ -d "backend" ]; then $(MAKE) -C backend test; fi; \
if [ -d "frontend" ]; then $(MAKE) -C frontend test; fi
@echo "\033[32m✅ All tests passed!\033[0m"
# =============================================================================
# Building
# =============================================================================
.PHONY: build
build: ## Build all projects (backend + frontend)
@echo "\033[36mBuilding projects...\033[0m"
@set -e; \
if [ -d "backend" ]; then $(MAKE) -C backend build; fi; \
if [ -d "frontend" ]; then $(MAKE) -C frontend build; fi
@echo "\033[32m✅ Build complete!\033[0m"
# =============================================================================
# Documentation
# =============================================================================
.PHONY: build-docs
build-docs: ## Build documentation site
@echo "Building documentation..."
if [ -d "docs" ]; then cd docs && $(MAKE) build-docs; fi
@echo "✅ Documentation built!"
.PHONY: serve-docs
serve-docs: ## Serve documentation with live reload
@echo "Starting documentation server..."
if [ -d "docs" ]; then cd docs && $(MAKE) serve-docs; fi