-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
114 lines (95 loc) · 5.02 KB
/
Makefile
File metadata and controls
114 lines (95 loc) · 5.02 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
# ===============================================
# Makefile for the project
# ===============================================
# ───────────────────────────────────────────────
# Configuration & Variables
# ───────────────────────────────────────────────
# Default Python interpreter (uv-managed)
PYTHON := python
UV := uv
PROJECT_ENV := /usr/local/
# Common flags
.DEFAULT_GOAL := help
MAKEFLAGS += --no-print-directory
SHELL := bash
.ONESHELL: # all commands in a target run in a single shell
# Colors for output
NO_COLOR := \033[0m
OK_COLOR := \033[32;01m
ERROR_COLOR := \033[31;01m
WARN_COLOR := \033[33;01m
INFO_COLOR := \033[36;01m
# ───────────────────────────────────────────────
# Main targets
# -----------------------------------------------
.PHONY: help
help: ## Show this help message
@echo -e "$(INFO_COLOR)Makefile help:$(NO_COLOR)"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf " $(OK_COLOR)%-20s$(NO_COLOR) %s\n", $$1, $$2}'
.PHONY: setup
setup: install ## Setup the project (install dependencies)
@echo -e "$(OK_COLOR)Project setup complete$(NO_COLOR)"
.PHONY: install
install: ## Install Python dependencies using uv (locked)
@echo -e "$(INFO_COLOR)Installing Python dependencies...$(NO_COLOR)"
$(UV) sync --locked
@echo -e "$(OK_COLOR)Dependencies installed successfully$(NO_COLOR)"
.PHONY: sync
sync: ## Re-sync dependencies (after changing pyproject.toml / uv.lock)
@echo -e "$(INFO_COLOR)Syncing dependencies...$(NO_COLOR)"
$(UV) sync --locked
@echo -e "$(OK_COLOR)Dependencies synced$(NO_COLOR)"
.PHONY: lock
lock: ## Update uv.lock file (after adding/removing dependencies)
@echo -e "$(INFO_COLOR)Updating uv.lock...$(NO_COLOR)"
$(UV) lock
@echo -e "$(OK_COLOR)Lock file updated$(NO_COLOR)"
.PHONY: clean
clean: ## Remove Python cache files, __pycache__, etc.
@echo -e "$(INFO_COLOR)Cleaning Python caches...$(NO_COLOR)"
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find . -type f -name "*.py[cod]" -delete
find . -type f -name "*.pyo" -delete
find . -type f -name "*.pyc" -delete
rm -rf .pytest_cache .coverage htmlcov .ruff_cache .mypy_cache
@echo -e "$(OK_COLOR)Clean complete$(NO_COLOR)"
.PHONY: lint
lint: ## Run linters (ruff + mypy)
@echo -e "$(INFO_COLOR)Running linters...$(NO_COLOR)"
$(UV) run ruff check .
$(UV) run mypy .
@echo -e "$(OK_COLOR)Linting passed$(NO_COLOR)"
.PHONY: format
format: ## Auto-format code with ruff
@echo -e "$(INFO_COLOR)Formatting code...$(NO_COLOR)"
$(UV) run ruff format .
@echo -e "$(OK_COLOR)Formatting complete$(NO_COLOR)"
.PHONY: test
test: ## Run tests
@echo -e "$(INFO_COLOR)Running tests...$(NO_COLOR)"
$(UV) run pytest
@echo -e "$(OK_COLOR)Tests complete$(NO_COLOR)"
.PHONY: dev
dev: ## Run the application in development mode (if applicable)
@echo -e "$(WARN_COLOR)No 'dev' target defined yet. Customize this target if needed.$(NO_COLOR)"
# Example: $(UV) run python -m myproject.main
.PHONY: all
all: clean install lint test ## Run the full CI-like pipeline locally
# ───────────────────────────────────────────────
# Local GitHub Actions with act
# ───────────────────────────────────────────────
.PHONY: act
act: ## Run GitHub Actions workflows locally using act (requires GITHUB_TOKEN). Example: make act
@echo -e "$(INFO_COLOR)Running GitHub Actions locally with act...$(NO_COLOR)"
@test -n "$$GITHUB_TOKEN" || (echo -e "$(ERROR_COLOR)Environment variable GITHUB_TOKEN is not set. Create a scoped PAT and export GITHUB_TOKEN as described in CONTRIBUTING.md$(NO_COLOR)" && exit 1)
@command -v act >/dev/null 2>&1 || (echo -e "$(ERROR_COLOR)act not found in PATH. Use the project's devcontainer or install act$(NO_COLOR)" && exit 1)
act -P on-prem=harbor.peinser.com/library/github-actions-runner:latest -s GITHUB_TOKEN="$$GITHUB_TOKEN"
.PHONY: act-job
act-job: ## Run a specific job from the workflows via act. Usage: make act-job JOB=<job-name> [PLATFORM=<platform>]
@echo -e "$(INFO_COLOR)Running job '$(JOB)' with act...$(NO_COLOR)"
@test -n "$(JOB)" || (echo -e "$(ERROR_COLOR)Please set JOB variable (e.g., make act-job JOB=test)$(NO_COLOR)" && exit 1)
@test -n "$$GITHUB_TOKEN" || (echo -e "$(ERROR_COLOR)GITHUB_TOKEN is not set. See CONTRIBUTING.md$(NO_COLOR)" && exit 1)
@command -v act >/dev/null 2>&1 || (echo -e "$(ERROR_COLOR)act not found in PATH. Use the project's devcontainer or install act$(NO_COLOR)" && exit 1)
: $${PLATFORM:="on-prem=harbor.peinser.com/library/github-actions-runner:latest"}; \
act -P "$$PLATFORM" -j "$(JOB)" -s GITHUB_TOKEN="$$GITHUB_TOKEN"