Files
agenticCode/rebuild-and-refresh.sh
Ingo Schnabel d4b14a3b6d Bug fixes
2026-07-27 16:20:42 +02:00

79 lines
3.3 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# rebuild-and-refresh.sh — stop the server, rebuild + redeploy it, then run a deep refresh
# of the given project(s) and announce when all refreshes have finished.
#
# Usage:
# ./rebuild-and-refresh.sh <project> [<project> ...]
#
# Example:
# ./rebuild-and-refresh.sh upms
# ./rebuild-and-refresh.sh upms pur
#
# Notes:
# * At least one project is required (no default) — the script exits with usage if none is given.
# * A deep refresh is long and mutates the graph — do not interrupt it once running.
# * `manage-ac.sh deploy` already bumps the version, rebuilds ac-code-server + ac-ui and
# brings the stack up; we stop first (explicit) so the sequence is unambiguous.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
AC="${AC:-ac}" # ac-cli launcher (on PATH: ~/.local/bin/ac)
SERVER_URL="${AC_SERVER_URL:-http://localhost:8787}"
READY_PROBE="$SERVER_URL/api/projects"
READY_TIMEOUT="${READY_TIMEOUT:-300}" # seconds to wait for the server to come up
log() { printf '\n\033[1;34m[%(%H:%M:%S)T] %s\033[0m\n' -1 "$*"; }
fail() { printf '\n\033[1;31m[%(%H:%M:%S)T] %s\033[0m\n' -1 "$*" >&2; exit 1; }
usage() { echo "Usage: ./rebuild-and-refresh.sh <project> [<project> ...]" >&2; exit 2; }
# Mandatory: one or more projects to deep-refresh, given as arguments.
if (( $# == 0 )); then
echo "Error: no project given — at least one is required." >&2
usage
fi
PROJECTS=("$@")
# 1. Stop the server -----------------------------------------------------------------------
log "Stopping ac-code-server ..."
./manage-ac.sh stop
# 2. Build + deploy ------------------------------------------------------------------------
log "Building and deploying (version bump, server + UI rebuild) ..."
./manage-ac.sh deploy
# 3. Wait for readiness -------------------------------------------------------------------
log "Waiting for the server to answer at $READY_PROBE (timeout ${READY_TIMEOUT}s) ..."
deadline=$(( $(date +%s) + READY_TIMEOUT ))
until curl -fsS -o /dev/null "$READY_PROBE" 2>/dev/null; do
if (( $(date +%s) >= deadline )); then
fail "Server did not become ready within ${READY_TIMEOUT}s — aborting before refresh."
fi
sleep 3
done
log "Server is up."
# 4. Deep refresh each project (synchronous; each blocks until its refresh completes) ------
declare -A ELAPSED
for proj in "${PROJECTS[@]}"; do
log "Deep refresh: $proj (this can take several minutes) ..."
start=$(date +%s)
"$AC" refresh --deep -p "$proj" || fail "Deep refresh failed for project '$proj'."
ELAPSED[$proj]=$(( $(date +%s) - start ))
log "Deep refresh done: $proj (${ELAPSED[$proj]}s)."
done
# 5. Announce completion ------------------------------------------------------------------
printf '\n\033[1;32m======================================================================\033[0m\n'
printf '\033[1;32m Both deep refreshes finished.\033[0m\n'
for proj in "${PROJECTS[@]}"; do
printf '\033[1;32m %-6s : %ss\033[0m\n' "$proj" "${ELAPSED[$proj]}"
done
printf '\033[1;32m======================================================================\033[0m\n'
printf '\a' # terminal bell
command -v notify-send >/dev/null 2>&1 && \
notify-send "AgenticCode" "Deep refresh finished for: ${PROJECTS[*]}" || true