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