Files
ersatztv/scripts/e2e-local.sh
T
timothy 279052ccd4
Build ErsatzTV Image / Build & test (.NET) (pull_request) Failing after 2m45s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Failing after 2s
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 11s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
fix(e2e): stale-asset gotcha — rm build wwwroot before copy in e2e-local.sh (+doc)
2026-07-10 07:56:34 +02:00

85 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# scripts/e2e-local.sh — launch a local ErsatzTV instance for live E2E verification.
#
# See docs/e2e-local.md for the full recipe and the "why" behind each step. This script assumes
# `dotnet build ErsatzTV.sln` and (if the SPA changed) `cd web && npm run build` have ALREADY been
# run — it only does the wwwroot copy + launch + ready-wait, since rebuilding on every invocation
# is slow and this is meant to be re-run often during a debugging session.
#
# Usage:
# scripts/e2e-local.sh [CONFIG_DIR]
#
# CONFIG_DIR defaults to a fresh `mktemp -d` if omitted. NEVER reuse a config dir across runs.
#
# On success, prints:
# PID=<pid>
# PORT=<port>
# CONFIG_DIR=<dir>
# LOG=<log file path>
# and exits 0, leaving the server RUNNING in the background. The caller is responsible for
# stopping it (`kill <PID>`) and for freeing the port before starting another run.
set -euo pipefail
REPO_ROOT="$(git rev-parse --show-toplevel)"
BUILD_DIR="$REPO_ROOT/ErsatzTV/bin/Debug/net10.0"
PORT="${ETV_UI_PORT:-8409}"
READY_LINE="Done migrating search index"
TIMEOUT_SECS=120
CONFIG_DIR="${1:-$(mktemp -d)}"
mkdir -p "$CONFIG_DIR"
if [ ! -d "$BUILD_DIR" ]; then
echo "error: $BUILD_DIR does not exist — run 'dotnet build ErsatzTV.sln' first" >&2
exit 1
fi
if [ ! -d "$REPO_ROOT/ErsatzTV/wwwroot/app" ]; then
echo "warning: $REPO_ROOT/ErsatzTV/wwwroot/app does not exist — the SPA hasn't been built" \
"('cd web && npm run build'). The /app UI will 404 until it exists AND the server is" \
"(re)started after copying it in." >&2
fi
echo "Copying wwwroot into build output (static middleware resolves its file root at startup;" \
"a running process will never see files added later)..."
# rm first: with an existing destination dir, `cp -R src dst` copies INTO it (dst/wwwroot/...),
# silently leaving a previous run's stale assets in place.
rm -rf "$BUILD_DIR/wwwroot"
cp -R "$REPO_ROOT/ErsatzTV/wwwroot" "$BUILD_DIR/wwwroot"
LOG_FILE="$(mktemp)"
echo "Launching dotnet ErsatzTV.dll (log: $LOG_FILE, config: $CONFIG_DIR, port: $PORT)..."
(
cd "$BUILD_DIR"
ETV_CONFIG_FOLDER="$CONFIG_DIR" ETV_UI_PORT="$PORT" dotnet ErsatzTV.dll
) >"$LOG_FILE" 2>&1 &
PID=$!
echo "Waiting up to ${TIMEOUT_SECS}s for '$READY_LINE'..."
elapsed=0
until grep -q "$READY_LINE" "$LOG_FILE" 2>/dev/null; do
if ! kill -0 "$PID" 2>/dev/null; then
echo "error: process $PID exited before becoming ready. Log tail:" >&2
tail -n 40 "$LOG_FILE" >&2
exit 1
fi
if [ "$elapsed" -ge "$TIMEOUT_SECS" ]; then
echo "error: timed out after ${TIMEOUT_SECS}s waiting for readiness. Log tail:" >&2
tail -n 40 "$LOG_FILE" >&2
kill "$PID" 2>/dev/null || true
exit 1
fi
sleep 1
elapsed=$((elapsed + 1))
done
echo "Server ready."
echo "PID=$PID"
echo "PORT=$PORT"
echo "CONFIG_DIR=$CONFIG_DIR"
echo "LOG=$LOG_FILE"