diff --git a/.githooks/post-merge b/.githooks/post-merge new file mode 100755 index 0000000..846b677 --- /dev/null +++ b/.githooks/post-merge @@ -0,0 +1,29 @@ +#!/bin/bash +# post-merge: auto-detect changes and reinstall/restart services on the board +set -euo pipefail + +REPO="$(cd "$(dirname "$0")/.." && pwd)" +CHANGED=$(git diff HEAD@{1} --name-only 2>/dev/null || echo "") + +if [ -z "$CHANGED" ]; then + exit 0 +fi + +SYSTEMD_CHANGED=$(echo "$CHANGED" | grep -c "^system/" || true) +SCRIPT_CHANGED=$(echo "$CHANGED" | grep -c "^scripts/" || true) + +# Reinstall systemd units if any changed +if [ "$SYSTEMD_CHANGED" -gt 0 ]; then + echo "[githook:post-merge] Systemd units changed — reinstalling..." + sudo systemctl daemon-reload +fi + +# Restart services if scripts or systemd changed +if [ "$SYSTEMD_CHANGED" -gt 0 ] || [ "$SCRIPT_CHANGED" -gt 0 ]; then + echo "[githook:post-merge] Scripts/services changed — restarting..." + sudo chmod +x "$REPO/scripts/"*.py "$REPO/scripts/"*.sh 2>/dev/null || true + for svc in midi-bridge pd-synth-onboard led-matrix-viz prometheus-exporter; do + sudo systemctl restart "$svc" 2>/dev/null || true + done + echo "[githook:post-merge] Services restarted" +fi diff --git a/.githooks/pre-push b/.githooks/pre-push new file mode 100755 index 0000000..2988453 --- /dev/null +++ b/.githooks/pre-push @@ -0,0 +1,23 @@ +#!/bin/bash +# pre-push: validate Pd patches before pushing +set -euo pipefail + +REPO="$(cd "$(dirname "$0")/.." && pwd)" + +# Only check if there are any .pd files staged or changed +STAGED_PD=$(git diff --cached --name-only -- '*.pd' 2>/dev/null || true) +CHANGED_PD=$(git diff --name-only -- '*.pd' 2>/dev/null || true) + +if [ -z "$STAGED_PD" ] && [ -z "$CHANGED_PD" ]; then + exit 0 +fi + +echo "[githook:pre-push] Validating Pd patches..." +cd "$REPO" +if python3 pd-validator/validate.py pd/*.pd; then + echo "[githook:pre-push] All patches valid" + exit 0 +else + echo "[githook:pre-push] Patch validation FAILED — fix before pushing" + exit 1 +fi diff --git a/install.sh b/install.sh index 6f889eb..f274ebc 100755 --- a/install.sh +++ b/install.sh @@ -27,4 +27,7 @@ for svc in "${SERVICES[@]}"; do sudo systemctl enable "$svc" done +# Install git hooks: point to repo's .githooks so post-merge auto-restarts services +git config core.hooksPath "$REPO/.githooks" + echo "[OK] Services installed and enabled" diff --git a/justfile b/justfile index 23019f7..4d3f43b 100644 --- a/justfile +++ b/justfile @@ -102,6 +102,7 @@ deploy: @git push origin HEAD 2>&1 @ssh {{SSH_OPTS}} "{{BOARD_USER}}@{{BOARD_HOST}}" "\ cd {{REPO_DIR}} && git pull && \ + git config core.hooksPath .githooks && \ chmod +x scripts/*.py scripts/*.sh 2>/dev/null; \ echo '{{BOARD_PASS}}' | sudo -S systemctl daemon-reload && \ echo '{{BOARD_PASS}}' | sudo -S systemctl stop midi-bridge pd-synth-onboard led-matrix-viz && \