Hook detects staged changes to stack.toml or .woodpecker/templates/, runs gen_config.py, and stages the 5 generated files into the same commit. Zero manual steps — change the domain in stack.toml and commit, everything propagates automatically. Hook source tracked in dev/hooks/pre-commit for reproducibility.
52 lines
1.7 KiB
Bash
Executable File
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 templates changed
|
|
CONF_CHANGED=$(git diff --cached --name-only -- stack.toml '.woodpecker/templates/*.yml')
|
|
if [ -n "$CONF_CHANGED" ]; then
|
|
echo "==> pre-commit: regenerating config from stack.toml"
|
|
uv run python dev/scripts/gen_config.py
|
|
git add .woodpecker/deploy.yml .woodpecker/harden.yml .woodpecker/rebuild-all.yml coredns/hosts coredns/Corefile
|
|
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"
|