Public Access
175 lines
7.3 KiB
Makefile
175 lines
7.3 KiB
Makefile
.PHONY: all setup setup-ci setup-quality setup-release setup-image install update lint lint-all lint-dockerfiles test test-unit pytest-cov clean install-tools install-hooks activate-scripts checkmake check-mutable-globals check-dep-docs check-test-speed build-images push-images build-images-dry-run clean-images
|
|
.PHONY: check-workflow-artifact-deps check-workflow-tofu-init check-docker-init check-ansible-set-fact-to-json check-alert-rules
|
|
|
|
PYTHON := python3
|
|
VENV := .venv
|
|
BIN := $(VENV)/bin
|
|
|
|
all: setup
|
|
|
|
# --- devx.mak integration ----------------------------------------------------
|
|
# Include shared targets from the devx package itself (venv management,
|
|
# workflow-lint, notify-failure, checkmake, lint targets, quality checks, etc.)
|
|
# Since devx IS the package, we can include its own devx.mak.
|
|
DEVX_PYTHON := $(BIN)/python
|
|
DEVX_VENV := $(VENV)
|
|
DEVX_BIN := $(BIN)
|
|
DEVX_LINT_PATHS := src/ tests/
|
|
DEVX_COV_PKG := src/devx
|
|
DEVX_TEST_PATHS := tests/
|
|
|
|
DEVX_MAK := $(shell $(BIN)/python -c \
|
|
"from pathlib import Path; import devx; print(Path(devx.__file__).parent / 'make' / 'devx.mak')" \
|
|
2>/dev/null)
|
|
# Fallback: when the venv doesn't exist yet (chicken-and-egg), use the
|
|
# source tree copy directly. devx IS the package, so src/devx/make/devx.mak
|
|
# is always available in this repo.
|
|
ifeq ($(strip $(DEVX_MAK)),)
|
|
DEVX_MAK := $(CURDIR)/src/devx/make/devx.mak
|
|
endif
|
|
-include $(DEVX_MAK)
|
|
|
|
# venv, .env, and activate-scripts are provided by devx.mak
|
|
# (devx-venv, devx-env, devx-activate-scripts, $(DEVX_VENV)/bin/activate rule)
|
|
# Aliases for convenience and backward compatibility:
|
|
.PHONY: venv activate-scripts
|
|
venv: devx-venv
|
|
.env: devx-env
|
|
activate-scripts: devx-activate-scripts
|
|
|
|
# Full setup for local development
|
|
setup: $(VENV)/bin/activate .env activate-scripts install-tools
|
|
@$(BIN)/pip install -e '.[dev]' 2>/dev/null; \
|
|
export PATH="$(HOME)/.local/bin:$$PATH"; \
|
|
$(BIN)/python -m devx.tools.setup --bin "$(BIN)"
|
|
|
|
# Lean setup for CI jobs (pytest + lint + runtime deps)
|
|
setup-ci: $(VENV)/bin/activate .env
|
|
@$(BIN)/pip install -e '.[ci,lint]' 2>/dev/null; \
|
|
$(BIN)/python -m devx.tools.setup --bin "$(BIN)" --extras "ci,lint" --no-pre-commit --no-tea-login
|
|
|
|
# Setup for quality job (lint + test deps, actionlint tool)
|
|
setup-quality: $(VENV)/bin/activate .env install-tools
|
|
@$(BIN)/pip install -e '.[ci,lint]' 2>/dev/null; \
|
|
export PATH="$(HOME)/.local/bin:$$PATH"; \
|
|
$(BIN)/python -m devx.tools.setup --bin "$(BIN)" --extras "ci,lint" --no-pre-commit --no-tea-login
|
|
|
|
# Setup for release jobs (needs git-cliff, tea, lint tools)
|
|
setup-release: $(VENV)/bin/activate .env
|
|
@$(BIN)/pip install -e '.[ci,lint,release]' 2>/dev/null; \
|
|
$(BIN)/python -m devx.tools.install_tools --tool git-cliff --tool tea; \
|
|
export PATH="$(HOME)/.local/bin:$$PATH"; \
|
|
$(BIN)/python -m devx.tools.setup --bin "$(BIN)" --extras "ci,lint,release" --no-pre-commit
|
|
|
|
# Setup for pre-built image jobs (deps already in image, just link venv + install project)
|
|
# Note: Not aliased to devx-setup-image because devx's own CI images may have
|
|
# an older devx.mak that doesn't yet define devx-setup-image. Consumer repos
|
|
# (grm, infra) can safely alias to devx-setup-image since they install devx from PyPI.
|
|
setup-image:
|
|
@if [ -d /opt/venv ]; then ln -sf /opt/venv $(VENV); . $(VENV)/bin/activate && pip install --no-cache-dir -e . 2>/dev/null; \
|
|
else echo "[setup-image] /opt/venv not found — falling back to setup-ci"; $(MAKE) setup-ci; fi
|
|
|
|
install-hooks:
|
|
@cp hooks/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit
|
|
@cp hooks/pre-push .git/hooks/pre-push && chmod +x .git/hooks/pre-push
|
|
@echo "Git hooks installed."
|
|
|
|
install-tools: $(VENV)/bin/activate
|
|
@$(BIN)/pip install -e '.' 2>/dev/null; \
|
|
$(BIN)/python -m devx.tools.install_tools
|
|
|
|
# Aliases — project-specific names map to devx.mak targets
|
|
.PHONY: lint-ruff lint-format typecheck lint-bandit lint-deps lint
|
|
.PHONY: workflow-lint workflow-dryrun workflow-dryrun-safe workflow-check
|
|
.PHONY: notify-failure checkmake check-mutable-globals check-dep-docs
|
|
.PHONY: check-test-speed check-test-coverage check-docs check-test-isolation check-translations
|
|
.PHONY: create-task create-pr push-with-pr git-push rebase pr-rebase
|
|
.PHONY: lint-all lint-dockerfiles
|
|
lint-ruff: devx-lint-ruff
|
|
lint-format: devx-lint-format
|
|
typecheck: devx-typecheck
|
|
lint-bandit: devx-lint-bandit
|
|
lint-deps: devx-lint-deps
|
|
lint: devx-lint
|
|
workflow-lint: devx-workflow-lint
|
|
workflow-dryrun: devx-workflow-dryrun
|
|
workflow-dryrun-safe: devx-workflow-dryrun-safe
|
|
workflow-check: devx-workflow-check
|
|
notify-failure: devx-notify-failure
|
|
checkmake: devx-checkmake
|
|
check-mutable-globals: devx-check-mutable-globals
|
|
check-dep-docs: devx-check-dep-docs
|
|
check-test-speed: devx-check-test-speed
|
|
check-test-isolation: devx-check-test-isolation
|
|
check-translations: devx-check-translations
|
|
check-test-coverage: devx-check-test-coverage
|
|
check-docs: devx-check-docs
|
|
create-task: devx-create-task
|
|
create-pr: devx-create-pr
|
|
push-with-pr: devx-push-with-pr
|
|
git-push: devx-push
|
|
rebase: devx-rebase
|
|
pr-rebase: devx-pr-rebase
|
|
|
|
lint-all: lint workflow-lint lint-dockerfiles
|
|
@echo "[lint-all] All linting checks passed."
|
|
|
|
# ── Workflow / Ansible / Docker check tools ─────────────────────────────────
|
|
# Generic check tools ported from infra. These targets are no-ops in devx
|
|
# itself (no .gitea/workflows or ansible/ directory) but provide the
|
|
# canonical entry points for consumer repos that include devx.mak.
|
|
|
|
check-workflow-artifact-deps:
|
|
@$(BIN)/python -m devx.ci.check_workflow_artifact_deps || \
|
|
echo "[check-workflow-artifact-deps] No workflows directory found — skipping."
|
|
|
|
check-workflow-tofu-init:
|
|
@$(BIN)/python -m devx.ci.check_workflow_tofu_init || \
|
|
echo "[check-workflow-tofu-init] No workflows directory found — skipping."
|
|
|
|
check-docker-init:
|
|
@$(BIN)/python -m devx.tools.check_docker_init || \
|
|
echo "[check-docker-init] No ansible templates found — skipping."
|
|
|
|
check-ansible-set-fact-to-json:
|
|
@$(BIN)/python -m devx.tools.check_ansible_set_fact_to_json || \
|
|
echo "[check-ansible-set-fact-to-json] No ansible directory found — skipping."
|
|
|
|
check-alert-rules:
|
|
@$(BIN)/python -m devx.tools.check_alert_rules --template-path ansible/roles/observability/templates || \
|
|
echo "[check-alert-rules] No alert-rules template found — skipping."
|
|
|
|
# Note: Not aliased to devx-lint-dockerfiles for the same reason as setup-image —
|
|
# devx's own CI images may have an older devx.mak. Consumer repos can safely alias.
|
|
lint-dockerfiles:
|
|
@echo "[lint-dockerfiles] Linting Dockerfiles with hadolint..."
|
|
@command -v hadolint >/dev/null 2>&1 || { echo "hadolint not found" >&2; exit 1; }
|
|
@find docker -name 'Dockerfile*' -exec hadolint {} +
|
|
@echo "[lint-dockerfiles] All Dockerfiles passed."
|
|
|
|
test-unit: devx-test-unit
|
|
|
|
pytest-cov: devx-pytest-cov
|
|
|
|
test: pytest-cov
|
|
|
|
pre-push: lint-all pytest-cov
|
|
@echo "[pre-push] All checks passed. Proceeding with push."
|
|
|
|
clean: devx-clean
|
|
@echo "[clean] Done."
|
|
|
|
# ── Docker image management ──────────────────────────────────────────────────
|
|
|
|
build-images: devx-build-images
|
|
@echo "[build-images] Done."
|
|
|
|
push-images: devx-push-images
|
|
@echo "[push-images] Done."
|
|
|
|
build-images-dry-run: devx-build-images-dry-run
|
|
@echo "[build-images-dry-run] Done."
|
|
|
|
clean-images: devx-clean-images
|
|
@echo "[clean-images] Done."
|