/
helixdevelopment
/
helix_ota
Обзор
Документация
Войти
/
helixdevelopment
/
helix_ota
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
main
scripts/git_hooks/pre-commit
95 строк
4 KB
Milos Vasic
feat(distribution+boot): SSH+remote-compose distribute_stack (podman/docker) + boot setsid detachment fix
22 июн 2026, 20:50
22 июн 2026, 20:50
8e5db50
Код
Авторство
О чём код?
#!/usr/bin/env bash # ============================================================================= # pre-commit — HelixTrack auto-sync hook (§11.4.148) # ----------------------------------------------------------------------------- # Before every commit, try to sync all workable items to HelixTrack. # Skips gracefully if HelixTrack Core is not running. # ============================================================================= set -euo pipefail PROJECT_ROOT="$(cd "$(dirname "$0")/../.." && pwd)" SYNC_SCRIPT="$PROJECT_ROOT/scripts/sync_helixtrack_push.sh" # Only run if sync script exists and we have staged workable item changes STAGED_DB=$(git diff --cached --name-only -- 'docs/workable_items.db' 2>/dev/null || true) STAGED_ISSUES=$(git diff --cached --name-only -- 'docs/Issues.md' 'docs/Fixed.md' 2>/dev/null || true) if [ -z "$STAGED_DB" ] && [ -z "$STAGED_ISSUES" ]; then exit 0 fi if [ ! -f "$SYNC_SCRIPT" ]; then exit 0 fi # Check HelixTrack reachability — boot if not running if ! curl -sf -X POST "http://localhost:8080/do" \ -H "Content-Type: application/json" \ -d '{"action":"version"}' -o /dev/null 2>/dev/null; then # Try local boot (must run from Core's Application dir for Configurations/ path) # Prefer sibling path (has Configurations/) HT_CORE_DIR="/Volumes/T7/Projects/helix_track/core/Application" HT_CORE="$HT_CORE_DIR/htCore" if [ ! -f "$HT_CORE" ]; then HT_CORE_DIR="$PROJECT_ROOT/helix_track/core/Application" HT_CORE="$HT_CORE_DIR/htCore" fi if [ -f "$HT_CORE" ]; then echo "[HELIXTRACK] Booting Core locally from $HT_CORE_DIR..." cd "$HT_CORE_DIR" SPACE_ROOT="$PROJECT_ROOT/helix_track/spaces/helix_ota" nohup ./htCore --space-root="$SPACE_ROOT" \ > /tmp/helixtrack_core.log 2>&1 & cd "$PROJECT_ROOT" for i in $(seq 1 30); do if curl -sf -X POST "http://localhost:8080/do" -H "Content-Type: application/json" \ -d '{"action":"version"}' -o /dev/null 2>/dev/null; then echo "[HELIXTRACK] Core online after ${i}s" break fi sleep 1 done if ! curl -sf -X POST "http://localhost:8080/do" -H "Content-Type: application/json" \ -d '{"action":"version"}' -o /dev/null 2>/dev/null; then echo "[HELIXTRACK] Failed to boot — sync skipped" exit 0 fi else # No local HelixTrack Core. The pre-commit hook stays LIGHTWEIGHT: it # only needs a reachable HelixTrack endpoint for the workable-items sync; # it does NOT fire a heavy remote container deploy on every commit. # # Remote container distribution (rsync + remote ROOTLESS podman compose, # §11.4.161) is an EXPLICIT, on-demand action via # scripts/distribute_stack.sh. It runs here only when the operator opts # in with HELIX_DISTRIBUTE_ON_COMMIT=1 (default OFF), so routine commits # never trigger a remote deploy. if [ "${HELIX_DISTRIBUTE_ON_COMMIT:-0}" = "1" ] && [ -x "$PROJECT_ROOT/scripts/distribute_stack.sh" ]; then echo "[HELIXTRACK] HELIX_DISTRIBUTE_ON_COMMIT=1 — distributing via remote rootless podman compose..." bash "$PROJECT_ROOT/scripts/distribute_stack.sh" 2>&1 | sed 's/^/ /' || true else echo "[HELIXTRACK] Core not running locally; remote distribution is on-demand (run scripts/distribute_stack.sh) — sync skipped this commit" exit 0 fi # If the on-demand deploy did not bring up a locally-reachable endpoint, # the auth probe below fails gracefully and sync is skipped (no bluff). fi fi # Get JWT HT_USER="${HELIXTRACK_USER:-admin}" HT_PASS="${HELIXTRACK_PASS:-admin1234}" JWT=$(curl -s -X POST "http://localhost:8080/do" \ -H "Content-Type: application/json" \ -d "{\"action\":\"authenticate\",\"jwt\":\"\",\"object\":\"\",\"data\":{\"username\":\"${HT_USER}\",\"password\":\"${HT_PASS}\"}}" \ | python3 -c "import sys,json; print(json.load(sys.stdin).get('data',{}).get('token',''))" 2>/dev/null || true) if [ -z "$JWT" ]; then echo "[HELIXTRACK] Auth failed — sync skipped" exit 0 fi echo "[HELIXTRACK] Syncing all workable items before commit..." HELIXTRACK_API="http://localhost:8080/do" HELIXTRACK_JWT="$JWT" bash "$SYNC_SCRIPT" 2>&1 | tail -2 echo "[HELIXTRACK] Sync complete" exit 0