1+ name : CI - Build and Test Application
2+
3+ on :
4+ push :
5+ branches : [ main ]
6+ pull_request :
7+ branches : [ main ]
8+
9+ permissions :
10+ contents : read
11+
12+ jobs :
13+ test :
14+ runs-on : ubuntu-latest
15+
16+ strategy :
17+ matrix :
18+ node-version : [20.x]
19+ python-version : ['3.10', '3.11']
20+
21+ steps :
22+ - name : Checkout code
23+ uses : actions/checkout@v4
24+
25+ - name : Set up Node.js ${{ matrix.node-version }}
26+ uses : actions/setup-node@v4
27+ with :
28+ node-version : ${{ matrix.node-version }}
29+ cache : ' npm'
30+
31+ - name : Set up Python ${{ matrix.python-version }}
32+ uses : actions/setup-python@v4
33+ with :
34+ python-version : ${{ matrix.python-version }}
35+
36+ - name : Cache Python dependencies
37+ uses : actions/cache@v3
38+ with :
39+ path : ~/.cache/pip
40+ key : ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
41+ restore-keys : |
42+ ${{ runner.os }}-pip-
43+
44+ - name : Install Python dependencies
45+ run : |
46+ python -m pip install --upgrade pip
47+ pip install -r requirements.txt
48+
49+ - name : Install Node.js dependencies
50+ run : npm ci
51+
52+ - name : Lint frontend code
53+ run : npm run lint
54+ continue-on-error : true
55+
56+ - name : Build frontend
57+ run : npm run build
58+
59+ - name : Run Python tests
60+ run : |
61+ python -m pytest test/ -v
62+
63+ - name : Start backend server and health check
64+ run : |
65+ # Start the backend server in the background
66+ python -m src.backend &
67+ BACKEND_PID=$!
68+
69+ # Wait for the server to start
70+ echo "Waiting for backend server to start..."
71+ sleep 10
72+
73+ # Health check - test if the server is responding
74+ max_attempts=30
75+ attempt=1
76+
77+ while [ $attempt -le $max_attempts ]; do
78+ if curl -f http://localhost:8000/health 2>/dev/null; then
79+ echo "Backend server is healthy!"
80+ break
81+ elif curl -f http://localhost:8000/ 2>/dev/null; then
82+ echo "Backend server is responding!"
83+ break
84+ else
85+ echo "Attempt $attempt/$max_attempts: Backend not ready yet..."
86+ sleep 2
87+ attempt=$((attempt + 1))
88+ fi
89+ done
90+
91+ if [ $attempt -gt $max_attempts ]; then
92+ echo "Backend server failed to start properly"
93+ kill $BACKEND_PID 2>/dev/null || true
94+ exit 1
95+ fi
96+
97+ # Test basic API endpoints if they exist
98+ echo "Testing backend endpoints..."
99+
100+ # Clean up
101+ kill $BACKEND_PID 2>/dev/null || true
102+ echo "Backend server test completed successfully!"
103+
104+ - name : Test frontend build serves correctly
105+ run : |
106+ # Start the preview server in the background
107+ npm run preview &
108+ FRONTEND_PID=$!
109+
110+ # Wait for the server to start
111+ echo "Waiting for frontend server to start..."
112+ sleep 5
113+
114+ # Health check for frontend
115+ max_attempts=15
116+ attempt=1
117+
118+ while [ $attempt -le $max_attempts ]; do
119+ if curl -f http://localhost:4173/ 2>/dev/null; then
120+ echo "Frontend server is serving correctly!"
121+ break
122+ else
123+ echo "Attempt $attempt/$max_attempts: Frontend not ready yet..."
124+ sleep 2
125+ attempt=$((attempt + 1))
126+ fi
127+ done
128+
129+ if [ $attempt -gt $max_attempts ]; then
130+ echo "Frontend server failed to start properly"
131+ kill $FRONTEND_PID 2>/dev/null || true
132+ exit 1
133+ fi
134+
135+ # Clean up
136+ kill $FRONTEND_PID 2>/dev/null || true
137+ echo "Frontend server test completed successfully!"
138+
139+ integration-test :
140+ runs-on : ubuntu-latest
141+ needs : test
142+
143+ steps :
144+ - name : Checkout code
145+ uses : actions/checkout@v4
146+
147+ - name : Set up Node.js
148+ uses : actions/setup-node@v4
149+ with :
150+ node-version : ' 20.x'
151+ cache : ' npm'
152+
153+ - name : Set up Python
154+ uses : actions/setup-python@v4
155+ with :
156+ python-version : ' 3.11'
157+
158+ - name : Install dependencies
159+ run : |
160+ python -m pip install --upgrade pip
161+ pip install -r requirements.txt
162+ npm ci
163+
164+ - name : Build frontend
165+ run : npm run build
166+
167+ - name : Test full application stack
168+ run : |
169+ # Start both frontend and backend
170+ echo "Starting full application stack..."
171+
172+ # Start backend
173+ python -m src.backend &
174+ BACKEND_PID=$!
175+
176+ # Start frontend preview
177+ npm run preview &
178+ FRONTEND_PID=$!
179+
180+ # Wait for both services
181+ sleep 15
182+
183+ # Test both services are running
184+ echo "Testing backend..."
185+ if ! curl -f http://localhost:8000/ 2>/dev/null; then
186+ echo "Backend failed to start"
187+ kill $BACKEND_PID $FRONTEND_PID 2>/dev/null || true
188+ exit 1
189+ fi
190+
191+ echo "Testing frontend..."
192+ if ! curl -f http://localhost:4173/ 2>/dev/null; then
193+ echo "Frontend failed to start"
194+ kill $BACKEND_PID $FRONTEND_PID 2>/dev/null || true
195+ exit 1
196+ fi
197+
198+ echo "Both services are running successfully!"
199+
200+ # Clean up
201+ kill $BACKEND_PID $FRONTEND_PID 2>/dev/null || true
202+
203+ echo "Integration test completed successfully!"
0 commit comments