-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
237 lines (203 loc) · 12.1 KB
/
Makefile
File metadata and controls
237 lines (203 loc) · 12.1 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
SHELL=/bin/bash -o pipefail
#
# ERE Makefile: Developer-friendly interface for testing & quality assurance
#
# This Makefile provides quick, discoverable targets for common development tasks.
# It uses your active Poetry environment for fast feedback during development.
#
# For CI/CD: Use `tox` (see tox.ini) for reproducible, isolated test environments.
# tox is independent of Poetry and manages its own dependencies in CI.
#
# Three-environment model (Cosmic Python / Clean Code):
# make test-unit → pytest + coverage (your venv, fast)
# make lint → pylint checks (your venv, fast)
# make check-clean-code → tox isolated: pylint + radon + xenon
# make check-architecture → tox isolated: import-linter
# make all-quality-checks → full pipeline: lint + architecture + clean-code
#
# For CI/CD in GitHub Actions:
# tox -e py312,architecture,clean-code
#
BUILD_PRINT = \e[1;34m
END_BUILD_PRINT = \e[0m
PROJECT_PATH = $(shell pwd)
SRC_PATH = ${PROJECT_PATH}/src
TEST_PATH = ${PROJECT_PATH}/test
BUILD_PATH = ${PROJECT_PATH}/dist
INFRA_PATH = ${PROJECT_PATH}/src/infra
COMPOSE_FILE = ${INFRA_PATH}/compose.dev.yaml
ENV_FILE = ${INFRA_PATH}/.env
# Auto-export all .env variables to every recipe shell (if the file exists)
ifneq ($(wildcard $(ENV_FILE)),)
include $(ENV_FILE)
export $(shell sed -n 's/^\([^#= ][^= ]*\)[ ]*=.*/\1/p' $(ENV_FILE))
endif
PACKAGE_NAME = ere
ICON_DONE = [✔]
ICON_ERROR = [x]
ICON_WARNING = [!]
ICON_PROGRESS = [-]
#-----------------------------------------------------------------------------
# Dev commands
#-----------------------------------------------------------------------------
.PHONY: help install-poetry install build
help: ## Display available targets
@ echo -e "$(BUILD_PRINT)Available targets:$(END_BUILD_PRINT)"
@ echo ""
@ echo -e " $(BUILD_PRINT)Development:$(END_BUILD_PRINT)"
@ echo " install - Install project dependencies via Poetry"
@ echo " install-poetry - Install Poetry if not present"
@ echo " build - Build the package distribution"
@ echo ""
@ echo -e " $(BUILD_PRINT)Testing:$(END_BUILD_PRINT)"
@ echo " test - Run all tests"
@ echo " test-unit - Run unit tests with coverage (fast, your venv)"
@ echo " test-integration - Run integration tests only"
@ echo " test-coverage - Generate HTML coverage report"
@ echo ""
@ echo -e " $(BUILD_PRINT)Code Quality (Developer):$(END_BUILD_PRINT)"
@ echo " format - Format code with Ruff"
@ echo " lint - Run pylint checks (your venv, fast)"
@ echo " lint-fix - Auto-fix with Ruff"
@ echo ""
@ echo -e " $(BUILD_PRINT)Code Quality (CI/Isolated):$(END_BUILD_PRINT)"
@ echo " check-clean-code - Clean-code checks: pylint + radon + xenon (tox)"
@ echo " check-architecture - Validate layer contracts (tox)"
@ echo " all-quality-checks - Run all quality checks"
@ echo " ci - Full CI pipeline for GitHub Actions"
@ echo ""
@ echo -e " $(BUILD_PRINT)Infrastructure (Docker):$(END_BUILD_PRINT)"
@ echo " infra-build - Build the ERE Docker image"
@ echo " infra-up - Start services (docker compose up -d)"
@ echo " infra-down - Stop and remove stack containers and networks"
@ echo " infra-down-volumes - Stop services and remove volumes (clean slate)"
@ echo " infra-rebuild - Rebuild images and start services"
@ echo " infra-rebuild-clean - Rebuild from scratch (no cache) and start"
@ echo " infra-logs - Follow service logs"
@ echo " infra-watch - Start services with file watching (sync src/ and src/config/)"
@ echo ""
@ echo -e " $(BUILD_PRINT)Utilities:$(END_BUILD_PRINT)"
@ echo " clean - Remove build artifacts and caches"
@ echo " help - Display this help message"
@ echo ""
install-poetry: ## Install Poetry if not present
@ echo -e "$(BUILD_PRINT)$(ICON_PROGRESS) Installing Poetry $(END_BUILD_PRINT)"
@ pip install "poetry>=2.0.0"
@ echo -e "$(BUILD_PRINT)$(ICON_DONE) Poetry is installed$(END_BUILD_PRINT)"
install: install-poetry ## Install project dependencies
@ echo -e "$(BUILD_PRINT)$(ICON_PROGRESS) Installing ERE requirements$(END_BUILD_PRINT)"
@ cd src && poetry lock
@ cd src && poetry install --with dev
@ echo -e "$(BUILD_PRINT)$(ICON_DONE) ERE requirements are installed$(END_BUILD_PRINT)"
build: ## Build the package distribution
@ echo -e "$(BUILD_PRINT)$(ICON_PROGRESS) Building package$(END_BUILD_PRINT)"
@ cd src && poetry build
@ echo -e "$(BUILD_PRINT)$(ICON_DONE) Package built successfully$(END_BUILD_PRINT)"
#-----------------------------------------------------------------------------
# Testing commands
#-----------------------------------------------------------------------------
.PHONY: test test-unit test-integration test-coverage
test: ## Run all tests
@ echo -e "$(BUILD_PRINT)$(ICON_PROGRESS) Running all tests$(END_BUILD_PRINT)"
@ cd src && poetry run pytest --rootdir=$(SRC_PATH) $(TEST_PATH)
@ echo -e "$(BUILD_PRINT)$(ICON_DONE) All tests passed$(END_BUILD_PRINT)"
test-unit: ## Run unit tests with coverage (fast, uses your venv)
@ echo -e "$(BUILD_PRINT)$(ICON_PROGRESS) Running unit tests with coverage$(END_BUILD_PRINT)"
@ cd src && poetry run pytest --rootdir=$(SRC_PATH) $(TEST_PATH) -m "not integration" \
--cov=ere --cov-report=term-missing --cov-report=html:htmlcov
@ echo -e "$(BUILD_PRINT)$(ICON_DONE) Unit tests passed (coverage: htmlcov/index.html)$(END_BUILD_PRINT)"
test-integration: check-env ## Run integration tests only (requires Redis — run make infra-up first)
@ echo -e "$(BUILD_PRINT)$(ICON_PROGRESS) Running integration tests$(END_BUILD_PRINT)"
@ cd src && poetry run pytest --rootdir=$(SRC_PATH) $(TEST_PATH) -m "integration"
@ echo -e "$(BUILD_PRINT)$(ICON_DONE) Integration tests passed$(END_BUILD_PRINT)"
test-coverage: ## Generate detailed HTML coverage report
@ echo -e "$(BUILD_PRINT)$(ICON_PROGRESS) Generating coverage report$(END_BUILD_PRINT)"
@ cd src && poetry run pytest --rootdir=$(SRC_PATH) $(TEST_PATH) -m "not integration" \
--cov=ere --cov-report=html:htmlcov --cov-report=term-missing
@ echo -e "$(BUILD_PRINT)$(ICON_DONE) Coverage report: htmlcov/index.html$(END_BUILD_PRINT)"
#-----------------------------------------------------------------------------
# Code quality commands
#-----------------------------------------------------------------------------
.PHONY: format lint lint-fix check-clean-code check-architecture all-quality-checks ci
format: ## Format code with Ruff
@ echo -e "$(BUILD_PRINT)$(ICON_PROGRESS) Formatting code$(END_BUILD_PRINT)"
@ cd src && poetry run ruff format $(SRC_PATH) $(TEST_PATH)
@ echo -e "$(BUILD_PRINT)$(ICON_DONE) Format complete$(END_BUILD_PRINT)"
lint: ## Run pylint checks (style, naming, SOLID principles) — uses your venv
@ echo -e "$(BUILD_PRINT)$(ICON_PROGRESS) Running pylint checks$(END_BUILD_PRINT)"
@ cd src && poetry run pylint --rcfile=$(PROJECT_PATH)/.pylintrc $(SRC_PATH)/ere $(TEST_PATH)
@ echo -e "$(BUILD_PRINT)$(ICON_DONE) Pylint checks passed$(END_BUILD_PRINT)"
lint-fix: ## Auto-fix code style with Ruff
@ echo -e "$(BUILD_PRINT)$(ICON_PROGRESS) Auto-fixing with Ruff$(END_BUILD_PRINT)"
@ cd src && poetry run ruff check --fix $(SRC_PATH) $(TEST_PATH)
@ echo -e "$(BUILD_PRINT)$(ICON_DONE) Auto-fix complete$(END_BUILD_PRINT)"
check-clean-code: ## Clean-code checks: pylint + radon + xenon (isolated tox)
@ echo -e "$(BUILD_PRINT)$(ICON_PROGRESS) Running clean-code checks (tox isolated)$(END_BUILD_PRINT)"
@ cd src && poetry run tox -e clean-code
@ echo -e "$(BUILD_PRINT)$(ICON_DONE) Clean-code checks passed$(END_BUILD_PRINT)"
check-architecture: ## Validate architectural boundaries (isolated tox)
@ echo -e "$(BUILD_PRINT)$(ICON_PROGRESS) Checking architecture contracts (tox isolated)$(END_BUILD_PRINT)"
@ cd src && poetry run tox -e architecture
@ echo -e "$(BUILD_PRINT)$(ICON_DONE) Architecture checks passed$(END_BUILD_PRINT)"
all-quality-checks: lint check-clean-code check-architecture ## Run all: lint + clean-code + architecture
@ echo -e "$(BUILD_PRINT)$(ICON_DONE) All quality checks passed!$(END_BUILD_PRINT)"
ci: ## Full CI pipeline for GitHub Actions (tox)
@ echo -e "$(BUILD_PRINT)$(ICON_PROGRESS) Running full CI pipeline$(END_BUILD_PRINT)"
@ set -a && . $(ENV_FILE) && set +a && poetry -C ./src run tox -e py312,architecture,clean-code
@ echo -e "$(BUILD_PRINT)$(ICON_DONE) CI pipeline complete$(END_BUILD_PRINT)"
#-----------------------------------------------------------------------------
# Infrastructure commands (Docker)
#-----------------------------------------------------------------------------
.PHONY: check-env infra-build infra-up infra-down infra-down-volumes infra-rebuild infra-rebuild-clean infra-logs infra-watch
check-env:
@ test -f $(ENV_FILE) || (echo -e "$(BUILD_PRINT)$(ICON_ERROR) Missing $(ENV_FILE). Run: cp infra/.env.example infra/.env$(END_BUILD_PRINT)" && exit 1)
infra-build: check-env ## Build the ERE Docker image
@ echo -e "$(BUILD_PRINT)$(ICON_PROGRESS) Building ERE Docker image$(END_BUILD_PRINT)"
@ docker compose -f $(COMPOSE_FILE) --env-file $(ENV_FILE) build
@ echo -e "$(BUILD_PRINT)$(ICON_DONE) ERE image built$(END_BUILD_PRINT)"
infra-up: check-env ## Start services (docker compose up -d)
@ docker network create ersys-local || true
@ echo -e "$(BUILD_PRINT)$(ICON_PROGRESS) Starting ERE stack$(END_BUILD_PRINT)"
@ docker compose -f $(COMPOSE_FILE) --env-file $(ENV_FILE) up -d
@ echo -e "$(BUILD_PRINT)$(ICON_DONE) ERE stack is running — use 'make infra-logs' to follow output$(END_BUILD_PRINT)"
infra-down: check-env ## Stop and remove ERE stack containers and networks
@ echo -e "$(BUILD_PRINT)$(ICON_PROGRESS) Stopping ERE stack$(END_BUILD_PRINT)"
@ docker compose -f $(COMPOSE_FILE) --env-file $(ENV_FILE) down
@ echo -e "$(BUILD_PRINT)$(ICON_DONE) ERE stack stopped$(END_BUILD_PRINT)"
infra-down-volumes: check-env ## Stop services and remove volumes (clean slate)
@ echo -e "$(BUILD_PRINT)$(ICON_PROGRESS) Stopping ERE stack and removing volumes$(END_BUILD_PRINT)"
@ docker compose -f $(COMPOSE_FILE) --env-file $(ENV_FILE) down -v
@ echo -e "$(BUILD_PRINT)$(ICON_DONE) ERE stack stopped and volumes removed$(END_BUILD_PRINT)"
infra-rebuild: check-env ## Rebuild images and start services
@ echo -e "$(BUILD_PRINT)$(ICON_PROGRESS) Rebuilding ERE stack$(END_BUILD_PRINT)"
@ docker compose -f $(COMPOSE_FILE) --env-file $(ENV_FILE) up -d --build
@ echo -e "$(BUILD_PRINT)$(ICON_DONE) ERE stack rebuilt and started$(END_BUILD_PRINT)"
infra-rebuild-clean: check-env ## Rebuild from scratch (no cache) and start
@ echo -e "$(BUILD_PRINT)$(ICON_PROGRESS) Rebuilding ERE stack (no cache)$(END_BUILD_PRINT)"
@ docker compose -f $(COMPOSE_FILE) --env-file $(ENV_FILE) build --no-cache
@ docker compose -f $(COMPOSE_FILE) --env-file $(ENV_FILE) up -d
@ echo -e "$(BUILD_PRINT)$(ICON_DONE) ERE stack rebuilt (clean) and started$(END_BUILD_PRINT)"
infra-logs: check-env ## Follow service logs
@ docker compose -f $(COMPOSE_FILE) --env-file $(ENV_FILE) logs -f
infra-watch: check-env ## Start services with file watching (sync src/ and src/config/)
@ echo -e "$(BUILD_PRINT)$(ICON_PROGRESS) Starting ERE stack with watch$(END_BUILD_PRINT)"
@ docker compose -f $(COMPOSE_FILE) --env-file $(ENV_FILE) watch
#-----------------------------------------------------------------------------
# Utility commands
#-----------------------------------------------------------------------------
.PHONY: clean
clean: ## Remove build artifacts and caches
@ echo -e "$(BUILD_PRINT)$(ICON_PROGRESS) Cleaning build artifacts and caches$(END_BUILD_PRINT)"
@ rm -rf $(BUILD_PATH)
@ rm -rf .pytest_cache
@ rm -rf .tox
@ rm -rf *.egg-info
@ rm -rf src/*.egg-info
@ rm -rf htmlcov coverage.xml
@ cd src && poetry run ruff clean
@ find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
@ find . -type f -name "*.pyc" -delete 2>/dev/null || true
@ find . -type f -name "*.pyo" -delete 2>/dev/null || true
@ echo -e "$(BUILD_PRINT)$(ICON_DONE) Clean complete$(END_BUILD_PRINT)"
# Default target
.DEFAULT_GOAL := help