diff --git a/.github/scripts/run-backend-tests.sh b/.github/scripts/run-backend-tests.sh index cd828e5c8..9c9575178 100644 --- a/.github/scripts/run-backend-tests.sh +++ b/.github/scripts/run-backend-tests.sh @@ -3,8 +3,10 @@ set -euo pipefail DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$DIR/local-db.sh" +source "$DIR/run-backend-instance.sh" +source "$DIR/run-frontend-instance.sh" -trap db_cleanup EXIT +trap 'db_cleanup; backend_cleanup; frontend_cleanup' EXIT java -version javac -version @@ -23,4 +25,10 @@ cd .. db_startup -./mvnw clean verify -Dspring.profiles.active=ci +backend_startup + +frontend_startup + +backend_cleanup + +./mvnw clean verify -Dspring.profiles.active=ci \ No newline at end of file diff --git a/.github/scripts/run-frontend-instance.sh b/.github/scripts/run-frontend-instance.sh new file mode 100644 index 000000000..b681c5d6d --- /dev/null +++ b/.github/scripts/run-frontend-instance.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +frontend_cleanup() { + echo "[INFO] ===== FRONTEND LOGS START =====" + cat frontend.log || echo "[WARN] frontend.log not found" + echo "[INFO] ===== FRONTEND LOGS END =====" + if kill $(cat frontend_pid.txt) >/dev/null 2>&1; then + echo "Frontend process killed successfully." + else + echo "Frontend was not running or already stopped." + fi +} + +frontend_startup() { + corepack enable pnpm + cd js + pnpm i --frozen-lockfile + + echo "Generating API schema..." + pnpm run generate + + if [ ! -f "src/lib/api/types/autogen/schema.ts" ]; then + echo "Schema generation failed!" + exit 1 + fi + echo "Schema file generated successfully." + + pnpm run dev >../frontend.log 2>&1 & + echo $! >../frontend_pid.txt + cd .. + + frontend_started=false + for i in {1..30}; do + if curl -s http://localhost:5173/ | grep -q ''; then + echo "Frontend is up!" + frontend_started=true + break + fi + echo "Waiting for frontend... ($i/30)" + sleep 2 + done + + if [ "$frontend_started" = false ]; then + echo "Frontend failed to start in time." + cat frontend.log || true + exit 1 + fi +} \ No newline at end of file