11#! /bin/bash
2- set -euo pipefail
32
43echo " π Starting DKG Node RAGAS Evaluation..."
54
5+ # Store the original directory
66RAGAS_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
7+
8+ # Go back to project root to find .env file
79cd ../../
810
9- # Track PIDs and cleanup properly
11+ # Function to cleanup on exit
1012cleanup () {
1113 echo " π§Ή Cleaning up..."
12-
13- # Try graceful shutdown first
14- if [ -n " ${FRONTEND_PID:- } " ] && kill -0 $FRONTEND_PID 2> /dev/null; then
14+ if [ ! -z " $FRONTEND_PID " ] && kill -0 $FRONTEND_PID 2> /dev/null; then
1515 echo " π΄ Stopping frontend server (PID: $FRONTEND_PID )..."
16- kill -TERM $FRONTEND_PID 2> /dev/null || true
17- wait $FRONTEND_PID 2> /dev/null || true
16+ kill $FRONTEND_PID
17+ wait $FRONTEND_PID 2> /dev/null
1818 fi
19-
20- if [ -n " ${BACKEND_PID:- } " ] && kill -0 $BACKEND_PID 2> /dev/null; then
19+ if [ ! -z " $BACKEND_PID " ] && kill -0 $BACKEND_PID 2> /dev/null; then
2120 echo " π΄ Stopping backend server (PID: $BACKEND_PID )..."
22- kill -TERM $BACKEND_PID 2> /dev/null || true
23- wait $BACKEND_PID 2> /dev/null || true
21+ kill $BACKEND_PID
22+ wait $BACKEND_PID 2> /dev/null
2423 fi
25-
26- # Give Node time to close ports
27- sleep 1
28- echo " β
Cleanup complete"
24+ # Note: Dashboard process (DASHBOARD_PID) is intentionally NOT killed
25+ # to allow continued access to results after evaluation completes
26+ exit
2927}
30- trap cleanup EXIT INT TERM
3128
32- # Start servers in separate process group (isolated from Jenkins wrapper)
33- set -m
29+ # Set trap to cleanup on script exit
30+ trap cleanup EXIT INT TERM
3431
35- if ! curl -s http://localhost:8081 > /dev/null 2>&1 ; then
32+ # Check if frontend is already running
33+ if curl -s http://localhost:8081 > /dev/null 2>&1 ; then
34+ echo " β
Frontend already running at http://localhost:8081"
35+ FRONTEND_ALREADY_RUNNING=true
36+ else
3637 echo " π Starting frontend server..."
38+ # Start only the frontend (much faster)
3739 cd apps/agent
40+ # Set environment variables to prevent browser opening but not trigger CI detection
3841 export EXPO_NO_BROWSER=1
3942 export BROWSER=none
40- npm run dev:app > /dev/null 2>&1 &
43+ npm run dev:app &
4144 FRONTEND_PID=$!
4245 cd ../../
43- echo " β³ Waiting for frontend..."
46+ FRONTEND_ALREADY_RUNNING=false
47+
48+ echo " β³ Waiting for frontend to start..."
49+
50+ # Wait for frontend to be ready (up to 30 seconds)
4451 for i in {1..30}; do
45- curl -s http://localhost:8081 > /dev/null 2>&1 && break
52+ if curl -s http://localhost:8081 > /dev/null 2>&1 ; then
53+ echo " β
Frontend ready at http://localhost:8081"
54+ break
55+ fi
56+
57+ if [ $i -eq 30 ]; then
58+ echo " β Frontend failed to start within 30 seconds"
59+ exit 1
60+ fi
61+
4662 sleep 1
63+ echo -n " ."
4764 done
48- echo " β
Frontend ready"
4965fi
5066
51- if ! curl -s http://localhost:9200 > /dev/null 2>&1 ; then
67+ # Check if backend is already running
68+ if curl -s http://localhost:9200 > /dev/null 2>&1 ; then
69+ echo " β
Backend already running at http://localhost:9200"
70+ BACKEND_ALREADY_RUNNING=true
71+ else
5272 echo " π Starting backend server..."
73+ # Start only the backend using pre-built files (very fast)
5374 cd apps/agent
54- node dist/index.js --dev > /dev/null 2>&1 &
75+ node dist/index.js --dev &
5576 BACKEND_PID=$!
5677 cd ../../
57- echo " β³ Waiting for backend..."
78+ BACKEND_ALREADY_RUNNING=false
79+
80+ echo " β³ Waiting for backend to start..."
81+
82+ # Wait for backend to be ready (up to 15 seconds)
5883 for i in {1..15}; do
59- curl -s http://localhost:9200 > /dev/null 2>&1 && break
84+ if curl -s http://localhost:9200 > /dev/null 2>&1 ; then
85+ echo " β
Backend ready at http://localhost:9200"
86+ break
87+ fi
88+
89+ if [ $i -eq 15 ]; then
90+ echo " β Backend failed to start within 15 seconds"
91+ exit 1
92+ fi
93+
6094 sleep 1
95+ echo -n " ."
6196 done
62- echo " β
Backend ready"
6397fi
6498
65- # Run evaluation in its own process group
99+ # Run evaluation with useful progress info
66100echo " π Running DKG Node evaluation..."
67- ( NODE_OPTIONS=' --import tsx' tsx " ${RAGAS_DIR} /evaluate.ts" ) &
68- EVAL_PID=$!
69- PGID=$( ps -o pgid= $EVAL_PID | tr -d ' ' )
70-
71- wait $EVAL_PID
72- EXIT_CODE=$?
73-
74- # Gracefully close all background jobs
75- kill -TERM -$PGID 2> /dev/null || true
76- sleep 1
77- kill -KILL -$PGID 2> /dev/null || true
101+ NODE_OPTIONS=' --import tsx' tsx " ${RAGAS_DIR} /evaluate.ts"
78102
79- if [ $EXIT_CODE -eq 0 ]; then
103+ if [ $? -eq 0 ]; then
80104 echo " β
Evaluation complete!"
105+
106+ # Check if we're in a CI environment
107+ if [ -n " $CI " ] || [ -n " $JENKINS_URL " ] || [ -n " $GITHUB_ACTIONS " ] || [ -n " $GITLAB_CI " ]; then
108+ echo " π€ Running in CI environment - skipping dashboard"
109+ echo " π RAGAS evaluation finished!"
110+ echo " π Results available in console output"
111+ else
112+ # Local environment - start dashboard and open browser
113+ if curl -s http://localhost:3001 > /dev/null 2>&1 ; then
114+ echo " π Dashboard already running at http://localhost:3001"
115+ else
116+ echo " π Starting dashboard..."
117+ NODE_OPTIONS=' --import tsx' tsx " ${RAGAS_DIR} /dashboard.ts" &
118+ DASHBOARD_PID=$!
119+ sleep 2
120+ fi
121+
122+ # Open dashboard in browser (only on local)
123+ if command -v open > /dev/null 2>&1 ; then
124+ echo " π Opening dashboard in browser..."
125+ open http://localhost:3001
126+ elif command -v xdg-open > /dev/null 2>&1 ; then
127+ echo " π Opening dashboard in browser..."
128+ xdg-open http://localhost:3001
129+ elif command -v start > /dev/null 2>&1 ; then
130+ echo " π Opening dashboard in browser..."
131+ start http://localhost:3001
132+ else
133+ echo " π Dashboard available at: http://localhost:3001"
134+ fi
135+
136+ echo " π RAGAS evaluation finished!"
137+ echo " π View detailed results at: http://localhost:3001"
138+
139+ # Stop the evaluation servers but keep dashboard running
140+ if [ " $FRONTEND_ALREADY_RUNNING " = false ] && [ ! -z " $FRONTEND_PID " ] && kill -0 $FRONTEND_PID 2> /dev/null; then
141+ echo " π΄ Stopping frontend server (evaluation complete)..."
142+ kill $FRONTEND_PID
143+ wait $FRONTEND_PID 2> /dev/null
144+ FRONTEND_PID=" "
145+ fi
146+
147+ if [ " $BACKEND_ALREADY_RUNNING " = false ] && [ ! -z " $BACKEND_PID " ] && kill -0 $BACKEND_PID 2> /dev/null; then
148+ echo " π΄ Stopping backend server (evaluation complete)..."
149+ kill $BACKEND_PID
150+ wait $BACKEND_PID 2> /dev/null
151+ BACKEND_PID=" "
152+ fi
153+
154+ echo " β
Evaluation servers stopped"
155+ echo " π Dashboard still running at: http://localhost:3001"
156+ echo " π‘ Dashboard will continue running until manually stopped"
157+ fi
81158else
82159 echo " β Evaluation failed!"
83- fi
84-
85- # Extra sleep to let Jenkins durable log flush
86- sleep 2
87- exit $EXIT_CODE
160+ exit 1
161+ fi
0 commit comments