From 25f33e14f9f332e339c2bfe27e3674d74342ae6e Mon Sep 17 00:00:00 2001 From: Nils Pukropp Date: Thu, 19 Feb 2026 16:33:39 +0100 Subject: [PATCH] added pre-push integrity hook for automated frontend and backend checks --- scripts/install-hooks.sh | 18 +++++++++++++ scripts/pre-push.sh | 58 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 scripts/install-hooks.sh create mode 100755 scripts/pre-push.sh diff --git a/scripts/install-hooks.sh b/scripts/install-hooks.sh new file mode 100644 index 0000000..2aeaccf --- /dev/null +++ b/scripts/install-hooks.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Get the root directory +ROOT_DIR=$(git rev-parse --show-toplevel) + +# Path to the hook script +HOOK_SRC="$ROOT_DIR/scripts/pre-push.sh" +HOOK_DEST="$ROOT_DIR/.git/hooks/pre-push" + +# Make the source script executable +chmod +x "$HOOK_SRC" + +# Copy/Link to git hooks +cp "$HOOK_SRC" "$HOOK_DEST" +chmod +x "$HOOK_DEST" + +echo "✅ Pre-push hook installed successfully!" +echo "It will now run frontend builds and backend checks automatically before every 'git push'." diff --git a/scripts/pre-push.sh b/scripts/pre-push.sh new file mode 100755 index 0000000..0afd962 --- /dev/null +++ b/scripts/pre-push.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# Get the root directory of the project +ROOT_DIR=$(git rev-parse --show-toplevel) + +# Set environment variables for non-interactive backend checks +export SECRET_KEY="pre-push-check-key" +export DEBUG="false" +export ALLOWED_HOSTS="localhost" + +echo "========================================" +echo " Running Pre-Push Integrity Checks " +echo "========================================" + +# 1. Frontend Build +echo "" +echo "Step 1: Checking Frontend Build..." +cd "$ROOT_DIR/frontend" +if ! npm run build; then + echo "" + echo "❌ ERROR: Frontend build failed." + echo " Please fix build errors before pushing." + exit 1 +fi + +# 2. Backend Check +echo "" +echo "Step 2: Checking Backend Integrity..." +cd "$ROOT_DIR/backend" + +# Detect python executable (prefer venv if exists) +if [ -f "venv/bin/python" ]; then + PYTHON_EXEC="venv/bin/python" +elif command -v python3 &>/dev/null; then + PYTHON_EXEC="python3" +else + PYTHON_EXEC="python" +fi + +# Check for missing migrations +if ! $PYTHON_EXEC manage.py makemigrations --check --dry-run &>/dev/null; then + echo "" + echo "❌ ERROR: Missing migrations detected." + echo " Please run 'python manage.py makemigrations' locally." + exit 1 +fi + +# Run Django system checks +if ! $PYTHON_EXEC manage.py check; then + echo "" + echo "❌ ERROR: Django system check failed." + exit 1 +fi + +echo "" +echo "✅ All checks passed! Proceeding with push..." +echo "========================================" +exit 0