Files
stack/dev/hooks/pre-commit
kert 55847bbdc1 P19: switchable CI backend — fix #142 #143 #144-#149
stack.toml [ci] section with backend = "woodpecker" | "github".
gen_config.py dispatches to backends/woodpecker.py or
backends/github.py, both implementing emit(images, scans,
platform, ci_cfg) -> dict[str, str].

Woodpecker backend: extracted from monolithic gen_config.py,
all plugin images and docker socket now from [ci.woodpecker].

GitHub backend: generates 6 .github/workflows/*.yml using
actions/checkout, astral-sh/setup-uv, docker/build-push-action,
aquasecurity/trivy-action, softprops/action-gh-release. Matrix
strategy for parallel image builds. GHCR as default registry.

Backend switching: change ci.backend in stack.toml, commit.
gen_config.py emits to the active directory and cleans stale
files from the inactive backend directory.

Pre-commit hook triggers on changes to stack.toml,
gen_config.py, or backends/*.py — stages all generated files.
2026-03-23 20:40:19 -04:00

52 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
# Auto-recover broken venv before running any checks
if ! uv run python -c 'import sys' 2>/dev/null; then
echo "==> pre-commit: venv broken, running uv sync --dev"
uv sync --dev
fi
# Auto-regenerate derived config if stack.toml or generator changed
CONF_CHANGED=$(git diff --cached --name-only -- stack.toml 'dev/scripts/gen_config.py' 'dev/scripts/backends/*.py')
if [ -n "$CONF_CHANGED" ]; then
echo "==> pre-commit: regenerating config from stack.toml"
uv run python dev/scripts/gen_config.py
git add .woodpecker/*.yml .github/workflows/*.yml coredns/hosts coredns/Corefile 2>/dev/null || true
fi
echo "==> pre-commit: ruff check (staged)"
# Only lint files that are staged for commit (avoid dirty-tree noise).
STAGED=$(git diff --cached --name-only --diff-filter=d -- 'src/*.py' 'tests/*.py')
if [ -n "$STAGED" ]; then
echo "$STAGED" | xargs uv run ruff check --quiet
fi
echo "==> pre-commit: ruff format --check (staged)"
if [ -n "$STAGED" ]; then
echo "$STAGED" | xargs uv run ruff format --check --quiet
fi
echo "==> pre-commit: pytest"
uv run python -m pytest tests/ --no-cov --tb=short -q
echo "==> pre-commit: marimo check"
uvx marimo check notebooks/*.py
echo "==> pre-commit: notebook run check"
# Only check notebooks that run standalone (no external services).
# Notebooks needing containers (api, nessie, polaris) or optional
# deps (vega_datasets, pyzotero) are excluded.
for nb in \
notebooks/acodb_explorer.py \
notebooks/bib_explorer.py \
notebooks/cms_quality_measures.py \
notebooks/pfs_calcs.py \
notebooks/sql_generator.py \
; do
echo " running $nb"
uv run python "$nb" 2>&1 || { echo "FAILED: $nb"; exit 1; }
done
echo "==> pre-commit: all checks passed"