#!/bin/bash # auto-rebuild.sh — Auto-rebuild garden: fetch API data → hugo → checkpoint # # Called by auto-rebuild-watcher.sh when content/ changes. # Also callable manually: bash scripts/auto-rebuild.sh set -euo pipefail DIR="$(cd "$(dirname "$0")/.." && pwd)" cd "$DIR" echo "=== Garden auto-rebuild: $(date -u +%Y-%m-%dT%H:%M:%SZ) ===" # 1. Fetch Estate API snapshots echo "" bash scripts/prebuild-fetch.sh || echo "⚠️ prebuild-fetch.sh failed, continuing..." # 2. Build Hugo site echo "" echo "→ Running hugo..." hugo 2>&1 HUGO_EXIT=$? if [ $HUGO_EXIT -ne 0 ]; then echo "✗ Hugo build failed (exit $HUGO_EXIT)" # Still write checkpoint so next agent knows state fi # 3. Gather stats for checkpoint PUBLISHED_COUNT=$(find content/ -name '*.md' -not -path '*/_index.md' -not -name '_index.md' | wc -l) PUBLIC_PAGE_COUNT=$(find public/ -name '*.html' | wc -l) NEXT_ACTION="check garden estate dashboard health at next patrol" # 4. Write checkpoint CHECKPOINT="$DIR/.garden_checkpoint" cat > "$CHECKPOINT" <