-
Notifications
You must be signed in to change notification settings - Fork 9
124 lines (109 loc) · 3.65 KB
/
server-test.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
on:
pull_request:
branches: [ main, master ]
paths:
- 'server/**'
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
- name: Run docker-compose up
run: |
docker-compose -f .github/docker-compose.yaml up -d
- name: Wait for Setup to complete (with timeout)
run: |
echo "Waiting for setup to complete..."
attempt=1
max_attempts=60 # Increased for complex migrations
while true; do
# Check container logs for completion message
if docker-compose -f .github/docker-compose.yaml logs setup | grep "PROCESS FINISHED" > /dev/null; then
echo "Setup has completed successfully."
break
fi
# Check for container exit
if ! docker-compose -f .github/docker-compose.yaml ps | grep -q "setup.*Up"; then
# Container exited, check if it was successful
if docker-compose -f .github/docker-compose.yaml logs setup | grep "PROCESS FINISHED" > /dev/null; then
echo "Setup completed and exited successfully."
break
else
echo "Setup container exited without completion message. Showing logs:"
docker-compose -f .github/docker-compose.yaml logs
exit 1
fi
fi
if [ $attempt -ge $max_attempts ]; then
echo "Setup did not complete within the expected time. Showing logs:"
docker-compose -f .github/docker-compose.yaml logs
exit 1
fi
echo "Attempt $attempt of $max_attempts: Setup still running. Waiting..."
sleep 10
attempt=$((attempt+1))
done
- name: Debug - Check PostgreSQL connection
run: |
sudo apt-get update
sudo apt-get install -y postgresql-client
echo "Attempting to connect to PostgreSQL..."
count=0
max_attempts=60
while [ $count -lt $max_attempts ]; do
if PGPASSWORD=abcd1234! pg_isready -h 127.0.0.1 -p 5433 -d server -U server_user > /dev/null 2>&1; then
echo "Connection to server database successful."
break
fi
echo "Connection attempt failed. Retrying in 3 seconds..."
sleep 3
count=$((count + 1))
done
if [ $count -eq $max_attempts ]; then
echo "Failed to connect after $max_attempts attempts."
docker-compose -f .github/docker-compose.yaml logs
exit 1
fi
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: |
cd server
npm ci
- name: Run Vitest tests
run: |
cd server
npm test
env:
DB_USER_SERVER: server_user
DB_PASSWORD_SERVER: abcd1234!
DB_NAME_SERVER: server
DB_HOST: 127.0.0.1
DB_PORT: 5433
APP_ENV: development
DB_TYPE: postgres
NODE_OPTIONS: --experimental-vm-modules
- name: Build
run: |
cd server
npm run build
env:
NODE_ENV: production
DB_USER_SERVER: server_user
DB_PASSWORD_SERVER: abcd1234!
DB_NAME_SERVER: server
DB_HOST: 127.0.0.1
DB_PORT: 5433
APP_ENV: development
DB_TYPE: postgres
NODE_OPTIONS: --experimental-vm-modules
- name: Cleanup
if: always()
run: |
docker-compose -f .github/docker-compose.yaml down -v