Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
135 lines (107 loc) · 5.81 KB
/
Copy pathMakefile
File metadata and controls
135 lines (107 loc) · 5.81 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
# RoboProbe developer entry points (docs/17 §3). Thin wrappers only: real configuration lives in
# backend/pyproject.toml and .pre-commit-config.yaml. Override any variable on the command line,
# e.g. `make test PYTEST_ARGS="-k selection"`.
UV ?= uv
BACKEND_DIR ?= backend
UV_RUN := $(UV) run --directory $(BACKEND_DIR)
PYTEST_ARGS ?=
FAST_MARKERS ?= unit or property or contract
XDIST_WORKERS ?= auto
# Paths below are relative to BACKEND_DIR because Python tools run there.
SCRIPTS_DIR ?= ../scripts
CONFIG_DOCS_SCRIPT ?= $(SCRIPTS_DIR)/gen_config_docs.py
PNPM ?= pnpm
WEB_DIR ?= web
# cd (not --dir) so corepack resolves the pnpm version pinned in web/package.json.
PNPM_WEB := cd $(WEB_DIR) && $(PNPM)
DOCS_CHECKS ?=
PYTHON ?= python3
# Docker Compose stack (docs/17 §4). `make up PROFILES="core dev"` also publishes Postgres on loopback.
DOCKER ?= docker
PROFILES ?= core
SECRETS_DIR ?= secrets
DB_PASSWORD_FILE := $(SECRETS_DIR)/db_password
API_TOKEN_FILE := $(SECRETS_DIR)/api_token
COMPOSE_FILE ?= docker/compose.yaml
# Created up front so Docker does not create the bind-mount source as root (compose.yaml mounts it).
ARTIFACTS_DIR ?= data/artifacts
COMPOSE := $(DOCKER) compose -f $(COMPOSE_FILE) $(if $(wildcard .env),--env-file .env)
COMPOSE_UP := $(COMPOSE) $(addprefix --profile ,$(PROFILES))
# `make up UP_FLAGS=` runs pulled release images instead of building the backend locally.
UP_FLAGS ?= --build
.DEFAULT_GOAL := help
.PHONY: help setup lock lint format typecheck test test-fast test-cov pre-commit docs-check clean \
config-docs config-docs-check openapi up down db-up logs ps demo backup restore observability
BACKUP_DIR ?= backups
BACKUP_RETENTION ?= 7
help: ## List available targets
@grep -hE '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-12s\033[0m %s\n", $$1, $$2}'
setup: $(DB_PASSWORD_FILE) $(API_TOKEN_FILE) ## Install backend + web deps and git hooks; create local secrets
$(UV) sync --locked --all-extras --directory $(BACKEND_DIR)
$(PNPM_WEB) install --frozen-lockfile
$(UV_RUN) pre-commit install --install-hooks
lock: ## Regenerate backend/uv.lock after changing dependencies (never hand-edit it)
$(UV) lock --directory $(BACKEND_DIR)
lint: ## Ruff + import-linter contracts (backend); ESLint (0 warnings) + Prettier + Stylelint + token freshness (web)
$(UV_RUN) ruff check . $(SCRIPTS_DIR)
$(UV_RUN) ruff format --check . $(SCRIPTS_DIR)
$(UV_RUN) lint-imports
$(PNPM_WEB) lint
format: ## Apply ruff fixes and formatting; Prettier for web
$(UV_RUN) ruff check --fix . $(SCRIPTS_DIR)
$(UV_RUN) ruff format . $(SCRIPTS_DIR)
$(PNPM_WEB) format
typecheck: ## mypy --strict on backend/src and scripts/; tsc --build (strict) for web
$(UV_RUN) mypy
$(UV_RUN) mypy $(SCRIPTS_DIR)
$(PNPM_WEB) typecheck
test: ## Default pytest run (excludes `sim` and `slow`) and Vitest for web
$(UV_RUN) pytest $(PYTEST_ARGS)
$(PNPM_WEB) test
test-fast: ## Unit, property and contract tests in parallel
$(UV_RUN) pytest -m "$(FAST_MARKERS)" -n $(XDIST_WORKERS) $(PYTEST_ARGS)
test-cov: ## Default pytest run with the coverage gate from docs/18 §3 (backend and web)
$(UV_RUN) pytest --cov --cov-report=term-missing --cov-report=xml $(PYTEST_ARGS)
$(PNPM_WEB) test:coverage
pre-commit: ## Run every pre-commit hook on the whole repository
$(UV_RUN) pre-commit run --all-files
docs-check: ## Docs gate: markdownlint, Mermaid render, links, ADR index (DOCS_CHECKS="links" to subset)
scripts/check_docs.sh $(DOCS_CHECKS)
clean: ## Remove caches and build artefacts
rm -rf $(BACKEND_DIR)/.pytest_cache $(BACKEND_DIR)/.mypy_cache $(BACKEND_DIR)/.ruff_cache \
$(BACKEND_DIR)/htmlcov $(BACKEND_DIR)/coverage.xml $(BACKEND_DIR)/.coverage $(BACKEND_DIR)/dist \
$(WEB_DIR)/dist $(WEB_DIR)/coverage
config-docs: ## Regenerate docs/27 §4 tables, .env.example and roboprobe.example.toml from settings
$(UV_RUN) python $(CONFIG_DOCS_SCRIPT)
config-docs-check: ## Fail (with a diff) if generated configuration docs/templates are stale
$(UV_RUN) python $(CONFIG_DOCS_SCRIPT) --check
openapi: ## Regenerate api/openapi.json from the FastAPI app (T-084b)
$(UV_RUN) python $(SCRIPTS_DIR)/export_openapi.py
$(DB_PASSWORD_FILE) $(API_TOKEN_FILE): ## Generate a local secret (git-ignored; never overwritten)
@mkdir -p $(SECRETS_DIR) && chmod 700 $(SECRETS_DIR)
@umask 022 && $(PYTHON) -c 'import secrets; print(secrets.token_urlsafe(32))' > $@
@echo "created $@"
up: $(DB_PASSWORD_FILE) $(if $(filter app,$(PROFILES)),$(API_TOKEN_FILE)) ## Start the stack (PROFILES, default core); fail if migrate fails
@mkdir -p $(ARTIFACTS_DIR)
$(COMPOSE_UP) up -d $(UP_FLAGS)
$(COMPOSE_UP) wait migrate
down: ## Stop and remove every container and the network (volumes kept)
$(COMPOSE) --profile '*' down --remove-orphans
db-up: $(DB_PASSWORD_FILE) ## Start only Postgres and wait until healthy (PROFILES="core dev" to publish it)
$(COMPOSE_UP) up -d --wait postgres $(if $(filter dev,$(PROFILES)),postgres-port)
logs: ## Follow logs of all running services
$(COMPOSE) --profile '*' logs -f
ps: ## List stack containers
$(COMPOSE) --profile '*' ps -a
backup: ## pg_dump custom format plus artefact archive (doc 29 §7)
BACKUP_DIR="$(BACKUP_DIR)" BACKUP_RETENTION="$(BACKUP_RETENTION)" \
scripts/backup.sh --out "$(BACKUP_DIR)"
restore: ## Restore BACKUP=path (set FORCE=1 to overwrite a non-empty database)
scripts/restore.sh $(if $(FORCE),--force,) "$(BACKUP)"
observability: $(DB_PASSWORD_FILE) $(API_TOKEN_FILE) ## Prometheus, Grafana and Jaeger (profile observability)
@mkdir -p $(ARTIFACTS_DIR)
$(COMPOSE) --profile observability up -d --wait prometheus grafana otel-collector jaeger
demo: $(DB_PASSWORD_FILE) ## Register warehouse_v1 and run the 50-run k2d S-PROBE demo (idempotent space)
@mkdir -p $(ARTIFACTS_DIR)
PROFILES="$(PROFILES)" COMPOSE_FILE="$(COMPOSE_FILE)" scripts/demo.sh