-
Notifications
You must be signed in to change notification settings - Fork 33
221 lines (190 loc) ยท 6.74 KB
/
e2e.yml
File metadata and controls
221 lines (190 loc) ยท 6.74 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
name: E2E Tests
on:
push:
branches: [master]
pull_request:
branches: [master]
permissions:
contents: read
jobs:
e2e:
name: Run E2E Tests
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: nekobox
POSTGRES_PASSWORD: nekobox
POSTGRES_DB: nekobox_e2e
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis:7
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
mailhog:
image: mailhog/mailhog:latest
ports:
- 1025:1025
- 8025:8025
options: >-
--health-cmd "wget -qO- http://localhost:8025/api/v2/messages || exit 1"
--health-interval 5s
--health-timeout 3s
--health-retries 10
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: latest
- name: Start MinIO (pgsty/minio)
run: |
docker run -d \
--name minio \
--network host \
-e MINIO_ROOT_USER=minioadmin \
-e MINIO_ROOT_PASSWORD=minioadmin \
pgsty/minio \
server /data --console-address ":9001"
- name: Wait for MinIO
run: |
echo "Waiting for MinIO S3 API to be ready..."
for i in $(seq 1 60); do
if curl -sf http://localhost:9000/minio/health/live > /dev/null 2>&1; then
echo "MinIO is ready (health check passed)"
sleep 2
exit 0
fi
echo "Waiting for MinIO ($i/60)..."
sleep 2
done
echo "MinIO did not become ready in time"
docker logs minio || true
exit 1
- name: Create MinIO bucket
run: |
curl -fsSL https://dl.min.io/client/mc/release/linux-amd64/mc -o ./mc
chmod +x ./mc
./mc alias set local http://localhost:9000 minioadmin minioadmin
./mc mb --ignore-existing local/nekobox-e2e
./mc ls local/nekobox-e2e
echo "minio-smoke" > /tmp/minio-smoke.txt
./mc cp /tmp/minio-smoke.txt local/nekobox-e2e/health/smoke.txt
./mc stat local/nekobox-e2e/health/smoke.txt
# โโ Backend โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- name: Build backend
run: |
COVERPKG=$(go list ./... | paste -sd "," -)
go build -cover -covermode=atomic -coverpkg="$COVERPKG" -o ./nekobox-server ./cmd
- name: Start backend (port 8080)
run: |
mkdir -p coverage/backend
GOCOVERDIR=$PWD/coverage/backend NEKOBOX_CONFIG_PATH=conf/app.e2e.ini ./nekobox-server web &
echo $! > /tmp/nekobox-server.pid
# โโ Frontend โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- name: Install frontend dependencies
working-directory: web
run: pnpm install
- name: Start frontend dev server (port 3000)
working-directory: web
run: pnpm dev:e2e &
env:
VITE_EXTERNAL_URL: http://localhost:3000
- name: Wait for frontend to be ready
run: |
for i in $(seq 1 30); do
if curl -sf http://localhost:3000 > /dev/null 2>&1; then
echo "Frontend is up!"
break
fi
echo "Waiting for frontend ($i/30)..."
sleep 2
done
# โโ Playwright โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- name: Install Playwright dependencies
working-directory: e2e
run: npm install
- name: Install Playwright browsers
working-directory: e2e
run: npx playwright install --with-deps chromium
- name: Run Playwright E2E tests
working-directory: e2e
run: npx playwright test
env:
E2E_BASE_URL: http://localhost:3000
E2E_MAILHOG_URL: http://localhost:8025
- name: Stop backend and generate coverage.txt
if: always()
run: |
if [ -f /tmp/nekobox-server.pid ]; then
BACKEND_PID=$(cat /tmp/nekobox-server.pid)
if kill -0 "$BACKEND_PID" 2>/dev/null; then
kill "$BACKEND_PID"
for i in $(seq 1 20); do
if ! kill -0 "$BACKEND_PID" 2>/dev/null; then
break
fi
sleep 1
done
if kill -0 "$BACKEND_PID" 2>/dev/null; then
kill -9 "$BACKEND_PID" || true
fi
fi
fi
mkdir -p coverage
if [ -d coverage/backend ] && [ -n "$(ls -A coverage/backend)" ]; then
go tool covdata textfmt -i=coverage/backend -o=coverage/coverage.txt
echo "Route coverage entries:"
grep 'internal/route/' coverage/coverage.txt | head -n 20 || true
if ! grep -q 'internal/route/' coverage/coverage.txt; then
echo "::error::No internal/route coverage found in coverage/coverage.txt"
exit 1
fi
else
echo "No backend coverage data found" > coverage/coverage.txt
echo "::error::No backend coverage data found in coverage/backend"
exit 1
fi
- name: Upload Playwright report
uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: e2e/playwright-report/
retention-days: 30
- name: Upload backend coverage artifact
uses: actions/upload-artifact@v4
if: always()
with:
name: coverage
path: coverage/coverage.txt
retention-days: 30
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
if: always()
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage/coverage.txt
flags: e2e
name: e2e-tests