-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
582 lines (526 loc) Β· 26.4 KB
/
Makefile
File metadata and controls
582 lines (526 loc) Β· 26.4 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
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
# HT Status Development Makefile
# Integrates UV (Python dependency management) and Docker Compose (services)
.PHONY: help setup dev services stop install update shell lint format fileformat fileformat-fix typecheck security test test-coverage test-integration clean reset changelog release-detect release-notes release-tag release-docs db-migrate db-upgrade db-apply check-uv lint-templates lint-templates-fix
# Variables
PYTHON := uv run python
PIP := uv pip
UV := uv
DOCKER_COMPOSE := docker-compose
# Common service startup function (consolidation)
define start_services
@echo "π³ Starting Docker Compose services..."
@$(DOCKER_COMPOSE) up -d postgres redis 2>&1 | tee -a /tmp/docker-services.log
@echo "β
Services started (PostgreSQL, Redis)"
endef
# Check if UV is available, provide helpful error message if not
check-uv:
@command -v uv >/dev/null 2>&1 || { \
echo "β ERROR: UV is not installed"; \
echo ""; \
echo "UV is required for this project. Install it using one of these methods:"; \
echo ""; \
echo "π¦ Using package managers:"; \
echo " # macOS:"; \
echo " brew install uv"; \
echo ""; \
echo " # Linux (Ubuntu/Debian):"; \
echo " curl -LsSf https://astral.sh/uv/install.sh | sh"; \
echo ""; \
echo " # Linux (Arch):"; \
echo " pacman -S uv"; \
echo ""; \
echo " # Or using pip (cross-platform):"; \
echo " pip install uv"; \
echo ""; \
echo "π After installation, restart your terminal and try again."; \
echo "π For more info: https://docs.astral.sh/uv/getting-started/installation/"; \
exit 1; \
}
# Default target
help: ## Show this help message
@echo "HT Status Development Commands"
@echo "=============================="
@echo ""
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
@echo ""
@echo "Quick Start:"
@echo " make setup # Initialize development environment"
@echo " make dev # Start development server"
@echo ""
# Development Environment Commands
setup: check-uv ## Initialize development environment (UV sync, Docker setup)
@echo "π Setting up HT Status development environment..."
@$(UV) sync --dev
@$(DOCKER_COMPOSE) pull
@echo "β
Development environment ready!"
@echo " Next: 'make dev' to start development server"
check-venv: check-uv ## Verify virtual environment is healthy
@if [ -d .venv ]; then \
if ! .venv/bin/python --version >/dev/null 2>&1; then \
echo "β ERROR: Virtual environment is broken"; \
echo ""; \
echo "This usually happens after Python was upgraded via Homebrew."; \
echo ""; \
echo "π§ Fix it by recreating the virtual environment:"; \
echo " rm -rf .venv && uv sync --dev"; \
echo ""; \
exit 1; \
fi \
fi
dev: check-uv check-venv services changelog ## Start development server (equivalent to run.sh)
@echo "π Starting HT Status development server..."
@$(PYTHON) run.py
stop: ## Stop dev server and Docker Compose services
@echo "π Stopping HT Status development services..."
@$(DOCKER_COMPOSE) stop 2>&1 | tee -a /tmp/docker-stop.log || docker compose stop 2>&1 | tee -a /tmp/docker-stop.log || true
@pkill -f "uv run python.*run.py" 2>&1 | tee -a /tmp/flask-stop.log || true
@pkill -f "flask run" 2>&1 | tee -a /tmp/flask-stop.log || true
@echo "β
Services stopped (Flask, Docker Compose)"
services: ## Start Docker Compose services only
$(call start_services)
services-dev: ## Start services with development configuration
@echo "π³ Starting Docker Compose services (development)..."
@$(DOCKER_COMPOSE) -f docker-compose.yml -f configs/docker-compose.development.yml up -d 2>&1 | tee -a /tmp/docker-dev.log
@echo "β
Services started (PostgreSQL, Redis, pgAdmin)"
services-staging: ## Start services with staging configuration
@echo "π³ Starting Docker Compose services (staging)..."
@$(DOCKER_COMPOSE) -f docker-compose.yml -f configs/docker-compose.staging.yml up -d 2>&1 | tee -a /tmp/docker-staging.log
@echo "β
Services started (PostgreSQL, Redis) with staging configuration"
services-stop: ## Stop all Docker Compose services
@echo "π Stopping Docker Compose services..."
@$(DOCKER_COMPOSE) down 2>&1 | tee -a /tmp/docker-down.log || docker compose down 2>&1 | tee -a /tmp/docker-down.log || true
@echo "β
Services stopped"
config-validate: check-uv ## Validate configuration for current environment
@echo "π Validating configuration..."
@$(PYTHON) -c "from config import get_config; cfg = get_config(); cfg.validate_config(); print('β
Configuration is valid')"
config-help: ## Show configuration setup help
@echo "βοΈ HTStatus Configuration Help"
@echo "=============================="
@echo ""
@echo "Environment Templates:"
@echo " Development: cp environments/.env.development.example .env"
@echo " Staging: cp environments/.env.staging.example .env"
@echo " Production: cp environments/.env.production.example .env"
@echo ""
@echo "Environment Detection:"
@echo " Set FLASK_ENV=development|staging|production"
@echo ""
@echo "Validation:"
@echo " make config-validate # Check current configuration"
@echo ""
@echo "Templates provide:"
@echo " - Environment-specific defaults"
@echo " - Security guidelines"
@echo " - Required vs optional settings"
@echo " - Deployment instructions"
# Python Development Commands
install: check-uv ## Install dependencies using UV
@echo "π¦ Installing dependencies..."
@$(UV) sync
update: check-uv ## Update dependencies and sync environment
@echo "π Updating dependencies..."
@$(UV) sync --upgrade
@$(UV) lock --upgrade
shell: check-uv ## Open Python shell in UV environment
@echo "π Opening Python shell..."
@$(PYTHON) -c "import IPython; IPython.start_ipython()" 2>&1 | tee /tmp/ipython-start.log || $(PYTHON)
# Code Quality Commands
lint: check-uv ## Run ruff linting
@echo "π Running ruff linting..."
@mkdir -p out/tests && rm -f out/tests/$@.json
@$(UV) run ruff check . 2>&1 | tee /tmp/ruff-output.txt; \
if [ $${PIPESTATUS[0]} -eq 0 ]; then \
echo "All checks passed!"; \
scripts/qi-json.sh out/tests/lint.json "Code Quality" "make lint" PASSED 0 0 "0 errors" "excellent code quality"; \
else \
error_count=$$(grep -c "error" /tmp/ruff-output.txt || echo "0"); \
app_errors=$$(grep -E '^(app/|models\.py|config\.py)' /tmp/ruff-output.txt | wc -l | tr -d ' '); \
if [ "$$app_errors" = "0" ] 2>/dev/null; then \
scripts/qi-json.sh out/tests/lint.json "Code Quality" "make lint" ISSUES $$error_count 0 "$$error_count errors" "dev scripts only"; \
else \
scripts/qi-json.sh out/tests/lint.json "Code Quality" "make lint" ISSUES 0 $$error_count "$$error_count errors" "$$app_errors in production code"; \
fi; \
exit 1; \
fi
lint-fix: check-uv ## Auto-fix linting issues using ruff
@echo "π§ Auto-fixing linting issues..."
@$(UV) run ruff check . --fix
@echo "β
Linting auto-fix completed"
lint-templates: check-uv ## Check Jinja2 template syntax and formatting
@mkdir -p out/tests && rm -f out/tests/$@.json
@echo "π Running djlint template linting..."
@error_count=0; \
if ! $(UV) run djlint app/templates/ --check --statistics; then \
error_count=$$($(UV) run djlint app/templates/ --check --statistics 2>&1 | grep -o '[0-9]\+ error' | head -1 | grep -o '[0-9]\+' || echo "0"); \
echo "β Template linting failed with $$error_count errors"; \
scripts/qi-json.sh out/tests/$@.json "Template Linting" "make lint-templates" FAILED 0 $$error_count "$$error_count template errors" "fix with make lint-templates-fix"; \
exit 1; \
fi
@echo "β
Template linting passed"
@scripts/qi-json.sh out/tests/$@.json "Template Linting" "make lint-templates" PASSED 0 0 "0 errors" "all templates valid"
lint-templates-fix: check-uv ## Auto-fix template formatting issues
@echo "π§ Auto-fixing template formatting..."
@$(UV) run djlint app/templates/ --reformat || true
@echo "β
Template auto-fix completed"
fileformat: ## Check file formatting (newline EOF, no trailing whitespace)
@mkdir -p out/tests && rm -f out/tests/$@.json
@echo "π Checking file formatting standards..."
@echo " β Checking for newline at end of file..."
@failed=false; \
failed_count=0; \
for file in $$(git ls-files | grep -E '\.(py|js|ts|tsx|html|css|scss|json|md|txt|yml|yaml|sh|sql|toml|cfg|ini|env)$$|^(Dockerfile|Makefile)'); do \
if [ -f "$$file" ] && test "$$(tail -c1 "$$file" | wc -l)" -eq 0; then \
echo "β Missing newline at EOF: $$file"; \
failed=true; \
failed_count=$$((failed_count + 1)); \
fi; \
done; \
if [ "$$failed" = "true" ]; then \
scripts/qi-json.sh out/tests/$@.json "File Format" "make fileformat" FAILED 0 $$failed_count "$$failed_count files" "missing newline at end of file"; \
exit 1; \
fi
@echo " β Checking for trailing whitespace..."
@failed=false; \
failed_count=0; \
for file in $$(git ls-files | grep -E '\.(py|js|ts|tsx|html|css|scss|json|md|txt|yml|yaml|sh|sql|toml|cfg|ini|env)$$|^(Dockerfile|Makefile)'); do \
if [ -f "$$file" ] && grep -q '[[:space:]]$$' "$$file"; then \
echo "β Trailing whitespace found in: $$file"; \
failed=true; \
failed_count=$$((failed_count + 1)); \
fi; \
done; \
if [ "$$failed" = "true" ]; then \
scripts/qi-json.sh out/tests/$@.json "File Format" "make fileformat" FAILED 0 $$failed_count "$$failed_count files" "files have trailing whitespace"; \
exit 1; \
fi
@total_files=$$(git ls-files | grep -E '\.(py|js|ts|tsx|html|css|scss|json|md|txt|yml|yaml|sh|sql|toml|cfg|ini|env)$$|^(Dockerfile|Makefile)' | while read f; do [ -f "$$f" ] && echo "$$f"; done | wc -l | tr -d ' '); \
echo "β
File formatting checks passed"; \
scripts/qi-json.sh out/tests/$@.json "File Format" "make fileformat" PASSED 0 0 "$$total_files files" "consistent formatting"
fileformat-fix: ## Auto-fix file formatting issues (newline EOF, trailing whitespace)
@echo "π§ Auto-fixing file formatting issues..."
@echo " β Adding newlines at end of files..."
@git ls-files | grep -E '\.(py|js|ts|tsx|html|css|scss|json|md|txt|yml|yaml|sh|sql|toml|cfg|ini|env)$$|^(Dockerfile|Makefile)' | \
while read -r file; do \
if [ -f "$$file" ] && test "$$(tail -c1 "$$file" | wc -l)" -eq 0; then \
echo "Adding newline to: $$file"; \
echo "" >> "$$file"; \
fi; \
done
@echo " β Removing trailing whitespace..."
@git ls-files | grep -E '\.(py|js|ts|tsx|html|css|scss|json|md|txt|yml|yaml|sh|sql|toml|cfg|ini|env)$$|^(Dockerfile|Makefile)' | \
while read -r file; do \
if [ -f "$$file" ] && grep -q '[[:space:]]$$' "$$file"; then \
echo "Cleaned: $$file"; \
sed -i '' 's/[[:space:]]*$$//' "$$file"; \
fi; \
done
@echo "β
File formatting auto-fix completed"
typecheck: check-uv ## Run mypy type checking
@echo "π¬ Running type checking..."
@mkdir -p out/tests && rm -f out/tests/$@.json
@$(UV) run mypy app/ models.py config.py --ignore-missing-imports --exclude="migrations|tests" 2>&1 | tee /tmp/typecheck-output.txt; \
error_count=$$(grep -c "error:" /tmp/typecheck-output.txt || echo "0"); \
if [ "$$error_count" -eq 0 ]; then \
echo "β
Type checking passed"; \
scripts/qi-json.sh out/tests/$@.json "Type Checking" "make typecheck" PASSED 0 0 "type-safe code" "mypy validation successful"; \
else \
echo "β Type checking found $$error_count errors"; \
scripts/qi-json.sh out/tests/$@.json "Type Checking" "make typecheck" FAILED 0 $$error_count "$$error_count type errors" "run 'mypy app/' to see details"; \
exit 1; \
fi
security-bandit: check-uv ## Run bandit code security analysis
@mkdir -p out/tests
@echo "π Running bandit code security analysis..."
@$(UV) run bandit -r app/ -c .bandit -f json 2>&1 | tee /tmp/bandit-results.json || $(UV) run bandit -r app/ -c .bandit 2>&1 | tee /tmp/bandit-results.txt || true
@bandit_status="CLEAN"; \
if [ -f /tmp/bandit-results.json ]; then \
bandit_issues=$$(jq -r '.metrics._totals."SEVERITY.MEDIUM" + .metrics._totals."SEVERITY.HIGH"' /tmp/bandit-results.json 2>/dev/null || echo "0"); \
if [ "$$bandit_issues" = "0" ]; then \
echo "β
No code security issues found"; \
bandit_status="CLEAN"; \
else \
echo "β οΈ $$bandit_issues code security issue(s) found (run 'make security-bandit' for details)"; \
bandit_status="$$bandit_issues ISSUE(S)"; \
fi; \
fi; \
scripts/qi-json.sh out/tests/security-bandit.json "Bandit Code Analysis" "make security-bandit" PASSED 0 0 "bandit analysis complete" "code security validation" bandit="$$bandit_status"
security-deps: check-uv ## Run safety dependency vulnerability analysis
@mkdir -p out/tests
@echo "π Running dependency vulnerability analysis..."
@if $(UV) run safety scan --short-report 2>&1 | tee /tmp/safety-results.txt; then \
safety_exit_code=0; \
else \
safety_exit_code=$$?; \
fi; \
total_cves=$$(grep -o "[0-9]* vulnerabilities found" /tmp/safety-results.txt | tail -1 | grep -o "[0-9]*" || echo "0"); \
ignored_cves=$$(grep -o "[0-9]* ignored due to policy" /tmp/safety-results.txt | head -1 | grep -o "[0-9]*" || echo "0"); \
active_cves=$$(( total_cves - ignored_cves )); \
cve_status="NONE"; \
deps_result="PASSED"; \
if [ "$$total_cves" = "0" ]; then \
echo "β
No CVE vulnerabilities in dependencies"; \
cve_status="NONE"; \
elif [ "$$active_cves" = "0" ] && [ "$$total_cves" != "0" ]; then \
echo "β οΈ $$total_cves CVE vulnerability(s) found but all ignored by policy"; \
cve_status="$$total_cves IGNORED"; \
deps_result="ISSUES"; \
elif [ "$$ignored_cves" != "0" ]; then \
echo "β $$active_cves active CVE vulnerability(s) found ($$ignored_cves ignored)"; \
cve_status="$$active_cves ACTIVE, $$ignored_cves IGNORED"; \
deps_result="FAILED"; \
else \
echo "β $$total_cves CVE vulnerability(s) found"; \
cve_status="$$total_cves FOUND"; \
deps_result="FAILED"; \
fi; \
scripts/qi-json.sh out/tests/security-deps.json "Dependency Analysis" "make security-deps" $$deps_result $$ignored_cves $$active_cves "dependency analysis complete" "CVE vulnerability validation" cve="$$cve_status"
test-single: check-uv services ## π§ͺ Run a single test file (usage: make test-single FILE=tests/test_database.py)
@test -n "$(FILE)" || { echo "β Usage: make test-single FILE=tests/test_something.py"; exit 1; }
@echo "π§ͺ Running single test file: $(FILE)..."
@mkdir -p out/tests && rm -f out/tests/test-single.json
@$(UV) run pytest $(FILE) $${PYTEST_VERBOSE-"-v"} --tb=short --cov-fail-under=0 --json-report --json-report-file=out/tests/test-single.json
@echo "β
Single test file completed: $(FILE)"
EXCEPTIONS = __init__.py test_factories.py constants.py error_handlers.py
test-python: check-uv services ## π§ͺ Run all Python tests with coverage
@echo "π§ͺ Running all Python tests with coverage..."
@mkdir -p out/tests && rm -f out/tests/$@.json out/tests/$@-cov.json
@$(UV) run pytest tests/ $${PYTEST_VERBOSE-"-v"} --tb=short --cov=app --cov=models --cov=config --cov-report=term-missing --cov-report=html --cov-report=json:out/tests/$@-cov.json --cov-fail-under=50 --json-report --json-report-file=out/tests/$@.json
coverage-report: check-uv ## π Generate detailed coverage analysis and testing priorities
@echo "π Generating coverage analysis for test prioritization..."
@mkdir -p out/tests && rm -f out/tests/$@.json
@$(PYTHON) scripts/coverage_report.py --json > /tmp/coverage-analysis.json
@coverage_pct=$$(jq -r '.total_coverage' /tmp/coverage-analysis.json); \
gap_pct=$$(jq -r '.gap_to_target' /tmp/coverage-analysis.json); \
priority_files=$$(jq -r '.priority_files | length' /tmp/coverage-analysis.json); \
if [ "$$gap_pct" != "null" ] && [ $$(echo "$$gap_pct > 0" | bc -l) -eq 1 ]; then \
printf "β οΈ Coverage: %.1f%% (%.1f%% below 50%% target)\n" "$$coverage_pct" "$$gap_pct"; \
scripts/qi-json.sh out/tests/$@.json "Test Coverage Analysis" "make coverage-report" ISSUES 0 $$priority_files "$$priority_files priority files" "$$(printf "%.1f%% coverage, %.1f%% gap to target" "$$coverage_pct" "$$gap_pct")"; \
else \
printf "β
Coverage: %.1f%% (target met)\n" "$$coverage_pct"; \
scripts/qi-json.sh out/tests/$@.json "Test Coverage Analysis" "make coverage-report" PASSED 0 0 "coverage target met" "$$(printf "%.1f%% coverage exceeds 50%% target" "$$coverage_pct")"; \
fi
@$(PYTHON) scripts/coverage_report.py
coverage-json: check-uv ## π Generate coverage analysis in JSON format
@$(PYTHON) scripts/coverage_report.py --json
test-coverage-files: check-uv ## Check if all Python files have corresponding test files
@echo "π Checking for untested Python files..."
@mkdir -p out/tests && rm -f out/tests/$@.json
@missing_tests=""; \
missing_count=0; \
total_files=0; \
excluded_count=0; \
for pyfile in $$(find app/ -name "*.py" -type f | grep -v __pycache__ | sort) models.py config.py; do \
if [ -f "$$pyfile" ]; then \
basename=$$(basename $$pyfile .py); \
filename=$$(basename $$pyfile); \
skip_file=false; \
for exception in $(EXCEPTIONS); do \
if [ "$$filename" = "$$exception" ]; then \
echo "βοΈ Skipping $$pyfile (exception: $$exception)"; \
skip_file=true; \
excluded_count=$$((excluded_count + 1)); \
break; \
fi; \
done; \
if [ "$$skip_file" = "false" ]; then \
total_files=$$((total_files + 1)); \
if [ "$$pyfile" = "models.py" ] || [ "$$pyfile" = "config.py" ]; then \
testfile="tests/test_$$basename.py"; \
else \
testfile="tests/test_$$basename.py"; \
fi; \
if [ ! -f "$$testfile" ]; then \
echo "β Missing test file: $$testfile (for $$pyfile)"; \
missing_tests="$$missing_tests $$pyfile"; \
missing_count=$$((missing_count + 1)); \
fi; \
fi; \
fi; \
done; \
echo "π Excluded $$excluded_count files, checked $$total_files files"; \
if [ "$$missing_count" -eq 0 ]; then \
echo "β
All $$total_files Python files have corresponding test files"; \
scripts/qi-json.sh out/tests/$@.json "Test Coverage (files)" "make test-coverage-files" PASSED 0 0 "$$total_files files tested" "complete test file coverage ($$excluded_count excluded)"; \
else \
echo "β $$missing_count of $$total_files Python files missing test files:$$missing_tests"; \
scripts/qi-json.sh out/tests/$@.json "Test Coverage (files)" "make test-coverage-files" FAILED 0 $$missing_count "$$missing_count missing tests" "$$missing_count files need test files ($$excluded_count excluded)"; \
exit 1; \
fi
check-chpp: ## Check CHPP API usage policy compliance
@echo "π Checking CHPP API usage policy..."
@./scripts/check-chpp-usage.sh
# Removed security-deps until further notice
GATES = fileformat lint lint-templates security-bandit test-coverage-files coverage-report check-chpp
test-all: check-uv services fileformat-fix lint-fix lint-templates-fix ## π§ͺ Run complete quality gate validation
@echo "π Running complete quality gate validation"
@mkdir -p out/tests && rm -f out/tests/*.json
@count=1; \
echo "π [$$count] Running test-python..."; \
PYTEST_VERBOSE="" $(MAKE) test-python || true; \
for gate in $(GATES); do \
count=$$((count + 1)); \
echo "π [$$count] Running $$gate..."; \
PYTEST_VERBOSE="" $(MAKE) $$gate &>/dev/null || true; \
done; \
scripts/quality-intelligence.sh --expected-results $${count}
# Utility Commands
clean: ## Clean up temporary files, caches
@echo "π§Ή Cleaning up..."
@find . -type f -name "*.pyc" -delete
@find . -type f -name "*.pyo" -delete
@find . -type f -name "*.pyd" -delete
@find . -type f -name ".DS_Store" -delete
@find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
@find . -type d -name ".pytest_cache" -exec rm -rf {} + 2>/dev/null || true
@find . -type d -name ".mypy_cache" -exec rm -rf {} + 2>/dev/null || true
@find . -type d -name ".ruff_cache" -exec rm -rf {} + 2>/dev/null || true
@rm -rf .coverage htmlcov/ *.log
@echo "β
Cleanup complete"
reset: clean ## Reset environment (clean + fresh install)
@echo "π Resetting environment..."
@rm -rf .venv/
@$(UV) sync --dev
@echo "β
Environment reset complete"
changelog: ## Generate changelog (from scripts/changelog.sh)
@echo "π Generating changelog..."
@bash scripts/changelog.sh
# Release Commands
release-detect: ## Detect if changes warrant a version release
@echo "π Detecting release-worthy changes..."
@./scripts/release/detect_version_changes.sh
release-notes: ## Generate release notes (usage: make release-notes VERSION=1.2)
@test -n "$(VERSION)" || { echo "β Usage: make release-notes VERSION=1.2"; exit 1; }
@echo "π Generating release notes for version $(VERSION)..."
@./scripts/release/update_releases.sh $(VERSION)
release-tag: ## Create git tag (usage: make release-tag VERSION=1.2 MESSAGE="Release description")
@test -n "$(VERSION)" || { echo "β Usage: make release-tag VERSION=1.2 MESSAGE=\"description\""; exit 1; }
@test -n "$(MESSAGE)" || { echo "β Usage: make release-tag VERSION=1.2 MESSAGE=\"description\""; exit 1; }
@echo "π·οΈ Creating git tag $(VERSION)..."
@git tag $(VERSION) -m "Release $(VERSION) - $(MESSAGE)"
@echo "β
Tag $(VERSION) created"
release-docs: ## Update all release documentation after tagging
@echo "π Updating release documentation..."
@$(MAKE) changelog
@echo "β
Release documentation updated"
# Database Commands
db-migrate: check-uv ## Create database migration (usage: make db-migrate MESSAGE="description")
@echo "ποΈ Creating database migration..."
@if [ -z "$(MESSAGE)" ]; then \
echo "β Error: MESSAGE parameter required"; \
echo "Usage: make db-migrate MESSAGE=\"description\""; \
echo "Alternative: uv run alembic -c migrations/alembic.ini revision --autogenerate -m \"description\""; \
exit 1; \
fi
@echo "Using Alembic directly to avoid Flask context issues..."
@uv run alembic -c migrations/alembic.ini revision --autogenerate -m "$(MESSAGE)"
db-upgrade: check-uv services ## Apply database upgrades
@echo "ποΈ Applying database upgrades..."
@./scripts/database/upgrade_local_database.sh --force
db-apply: check-uv ## Apply database migrations using production-safe script
@echo "ποΈ Applying database migrations (production-safe)..."
@uv run python scripts/database/apply_migrations.py
db-backup: check-uv ## Create full database backup
@echo "πΎ Creating database backup..."
@uv run python scripts/database/backup_database.py
db-restore: check-uv ## Restore database from backup file (usage: make db-restore BACKUP_FILE="path/to/backup.sql")
@echo "π Restoring database from backup..."
@if [ -z "$(BACKUP_FILE)" ]; then \
echo "β Error: BACKUP_FILE parameter required"; \
echo "Usage: make db-restore BACKUP_FILE=\"path/to/backup.sql\""; \
echo "Alternative: uv run python scripts/database/restore_database.py backup.sql"; \
exit 1; \
fi
@uv run python scripts/database/restore_database.py "$(BACKUP_FILE)"
db-backup-auto: check-uv ## Run automated backup to kloker.local (for cron/deployment)
@echo "π Running automated backup to kloker.local..."
@./scripts/database/backup_to_kloker.sh
# Deployment Commands
deploy-prepare: ## Prepare deployment environment (git, dependencies)
@echo "π Preparing deployment environment..."
@echo "Installing system dependencies..."
@if command -v apt-get >/dev/null 2>&1; then \
sudo apt-get update -qq && sudo apt-get install -y jq; \
elif command -v yum >/dev/null 2>&1; then \
sudo yum install -y jq; \
elif command -v brew >/dev/null 2>&1; then \
brew install jq; \
else \
echo "β οΈ Could not detect package manager - please install jq manually"; \
fi
@echo "Installing uv..."
@export PATH="$$HOME/.local/bin:$$PATH"; \
if ! command -v uv >/dev/null 2>&1; then \
pip3 install --user uv; \
fi
@echo "Ensuring ~/.local/bin in PATH..."
@if ! grep -q 'export PATH="$$HOME/.local/bin:$$PATH"' ~/.bashrc 2>/dev/null; then \
echo 'export PATH="$$HOME/.local/bin:$$PATH"' >> ~/.bashrc; \
echo "β Added ~/.local/bin to PATH in ~/.bashrc"; \
fi
@echo "β
Environment prepared"
deploy-sync: check-uv ## Sync code and dependencies
@echo "π Syncing code and dependencies..."
@git fetch --all
@git reset --hard $${DEPLOY_GIT_BRANCH:-next/main}
@echo "Cleaning migration conflicts..."
@find migrations/versions/ -name "*.py" -not -path "*/__pycache__/*" | while read -r file; do \
if ! git ls-files --error-unmatch "$$file" >/dev/null 2>&1; then \
echo "Removing untracked migration file: $$file"; \
rm -f "$$file"; \
fi; \
done
@export PATH="$$HOME/.local/bin:$$PATH"; \
rm -rf .venv 2>/dev/null || true; \
uv sync --python 3.14; \
uv pip install requests requests-oauthlib
@echo "β
Code and dependencies synced"
deploy-docs: ## Update release documentation and changelog
@echo "π Updating documentation..."
@if $(MAKE) release-detect 2>/dev/null; then \
echo "Version changes detected - updating release documentation..."; \
$(MAKE) release-docs || echo "Release update failed, continuing..."; \
else \
echo "No version changes detected - generating changelog only..."; \
$(MAKE) changelog; \
fi
@echo "β
Documentation updated"
deploy-migrate: check-uv ## Apply database migrations safely
@echo "ποΈ Applying database migrations..."
@export PATH="$$HOME/.local/bin:$$PATH"; \
uv run python scripts/database/apply_migrations.py
@echo "β
Database migrations completed"
deploy-finalize: ## Finalize deployment (restart service, cleanup)
@echo "π Finalizing deployment..."
@find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
@find . -type f -name "*.pyc" -delete 2>/dev/null || true
@touch app/routes.py
@sudo systemctl restart htstatus
@if [ $$? -eq 0 ]; then \
echo "β
Service restarted successfully"; \
sudo systemctl status htstatus --no-pager -l | head -10; \
else \
echo "β Service restart failed!"; \
exit 1; \
fi
@echo "β
Finalization completed"
deploy: ## Smart deployment: --run if pushed, --dry-run if not (override with FORCE_DEPLOY=true)
@echo "π Preparing deployment..."
@if [ "$${FORCE_DEPLOY}" = "true" ]; then \
echo "π FORCE_DEPLOY=true - skipping git push check"; \
./scripts/deployment/deploy.sh --run; \
elif git diff --quiet && git diff --cached --quiet; then \
if git log --oneline @{u}.. 2>/dev/null | grep -q .; then \
echo "β οΈ WARNING: Local commits not pushed to remote"; \
echo " Use 'git push' first or set FORCE_DEPLOY=true"; \
echo " Running dry-run instead..."; \
./scripts/deployment/deploy.sh --run --dry-run; \
else \
echo "β
Working directory clean and up to date with remote"; \
./scripts/deployment/deploy.sh --run; \
fi; \
else \
echo "β οΈ WARNING: Uncommitted changes detected"; \
echo " Commit and push changes first or set FORCE_DEPLOY=true"; \
echo " Running dry-run instead..."; \
./scripts/deployment/deploy.sh --run --dry-run; \
fi