Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-21 08:46:24

0001 #!/bin/bash
0002 # Fast pre-commit checks for swf-monitor — target: under ten seconds.
0003 #
0004 # Encodes the exact invocations (venv, env, manage.py) so no session has to
0005 # rediscover them. Checks only what changed: compiles modified .py files,
0006 # runs the Django system check once, and lints modified templates for the
0007 # two known silent page-breakers (unterminated one-line {# #} comments,
0008 # unbalanced double quotes on tag-bearing lines).
0009 #
0010 # Usage: bash scripts/pre-commit-checks.sh   (from anywhere in the repo)
0011 set -e
0012 cd "$(dirname "$0")/.."
0013 
0014 source /data/wenauseic/github/swf-testbed/.venv/bin/activate
0015 # shellcheck disable=SC1090
0016 source ~/.env 2>/dev/null || true
0017 
0018 CHANGED=$( (git diff --name-only HEAD 2>/dev/null; \
0019             git diff --cached --name-only 2>/dev/null; \
0020             git ls-files --others --exclude-standard) | sort -u )
0021 
0022 # Deleted files still appear in the diff — check only files that exist.
0023 PY_CHANGED=$(echo "$CHANGED" | grep '\.py$' | while read -r f; do [ -f "$f" ] && echo "$f"; done || true)
0024 HTML_CHANGED=$(echo "$CHANGED" | grep '\.html$' | while read -r f; do [ -f "$f" ] && echo "$f"; done || true)
0025 
0026 if [ -n "$PY_CHANGED" ]; then
0027     # shellcheck disable=SC2086
0028     python -m py_compile $PY_CHANGED
0029     echo "compile: OK ($(echo "$PY_CHANGED" | wc -l) changed .py)"
0030 else
0031     echo "compile: no .py changes"
0032 fi
0033 
0034 python src/manage.py check 2>&1 | tail -1
0035 
0036 FAIL=0
0037 for f in $HTML_CHANGED; do
0038     [ -f "$f" ] || continue
0039     if grep -n '{#' "$f" | grep -v '#}' > /dev/null; then
0040         echo "FAIL: unterminated {# comment in $f:"
0041         grep -n '{#' "$f" | grep -v '#}'
0042         FAIL=1
0043     fi
0044     python3 - "$f" << 'PYEOF'
0045 import sys
0046 bad = [i for i, line in enumerate(open(sys.argv[1]), 1)
0047        if '<' in line and line.count('"') % 2]
0048 if bad:
0049     print(f"WARN: odd double-quote count in {sys.argv[1]} "
0050           f"lines {bad} — check for an unterminated attribute")
0051 PYEOF
0052 done
0053 [ "$FAIL" -eq 0 ] || exit 1
0054 
0055 echo "pre-commit checks passed"