-
Notifications
You must be signed in to change notification settings - Fork 0
347 lines (299 loc) · 10.6 KB
/
Copy pathci.yml
File metadata and controls
347 lines (299 loc) · 10.6 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
name: CI
run-name: "CI: ${{ github.ref_name }} (${{ github.event.head_commit.message || github.event.pull_request.title || 'manual' }})"
on:
push:
branches: [main]
tags:
- 'agent-v[0-9]+.[0-9]+.[0-9]+'
- 'server-v[0-9]+.[0-9]+.[0-9]+'
pull_request:
branches: [main]
workflow_dispatch: {}
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
env:
GO_VERSION: '1.25'
jobs:
# ============================================================================
# LINT & TEST - Common runs first, agent/server run in parallel after
# ============================================================================
common:
name: Common
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
cache-dependency-path: |
common/go.sum
agent/go.sum
server/go.sum
- name: Lint
working-directory: ./common
run: |
go install honnef.co/go/tools/cmd/staticcheck@latest
go vet ./...
staticcheck ./...
- name: Test
working-directory: ./common
run: go test -v -coverprofile=coverage.out ./...
- uses: codecov/codecov-action@v4
with:
file: ./common/coverage.out
flags: common
fail_ci_if_error: false
agent:
name: Agent
runs-on: ubuntu-latest
needs: [common]
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
cache-dependency-path: |
common/go.sum
agent/go.sum
- name: Lint
working-directory: ./agent
run: |
go install honnef.co/go/tools/cmd/staticcheck@latest
go vet ./...
staticcheck ./...
- name: Test
working-directory: ./agent
run: go test -v -coverprofile=coverage.out ./...
- uses: codecov/codecov-action@v4
with:
file: ./agent/coverage.out
flags: agent
fail_ci_if_error: false
server:
name: Server
runs-on: ubuntu-latest
needs: [common]
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
cache-dependency-path: |
common/go.sum
server/go.sum
- name: Lint
working-directory: ./server
run: |
go install honnef.co/go/tools/cmd/staticcheck@latest
go vet ./...
staticcheck ./...
- name: Test
working-directory: ./server
run: go test -v -coverprofile=coverage.out ./...
- uses: codecov/codecov-action@v4
with:
file: ./server/coverage.out
flags: server
fail_ci_if_error: false
- name: Integration Tests (Postgres)
working-directory: ./server
run: go test -v -tags=integration -coverprofile=coverage-integration.out ./storage/...
- uses: codecov/codecov-action@v4
with:
file: ./server/coverage-integration.out
flags: server-integration
fail_ci_if_error: false
# ============================================================================
# JAVASCRIPT - Jest unit tests + Playwright UI tests
# ============================================================================
javascript:
name: JavaScript
runs-on: ubuntu-latest
env:
PLAYWRIGHT_BROWSERS_PATH: ~/.cache/ms-playwright
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Jest unit tests
run: npm run test:js
- name: Cache Playwright browsers
id: playwright-cache
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-playwright-
- name: Install Playwright browsers (cache miss)
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: npx playwright install --with-deps chromium firefox webkit
- name: Validate Playwright browsers (cache hit)
if: steps.playwright-cache.outputs.cache-hit == 'true'
run: npx playwright install chromium firefox webkit
- uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
cache-dependency-path: |
common/go.sum
agent/go.sum
server/go.sum
- name: Build binaries for Playwright
run: |
(cd agent && go build -o printmaster-agent .)
(cd server && go build -o printmaster-server .)
- name: Playwright tests
run: npm run test:playwright
- uses: actions/upload-artifact@v7
if: always()
with:
name: playwright-report
path: test-results/
if-no-files-found: ignore
# ============================================================================
# E2E - Runs after both agent and server pass (mock-based tests)
# ============================================================================
e2e:
name: E2E (Mock)
runs-on: ubuntu-latest
needs: [agent, server]
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
cache-dependency-path: |
common/go.sum
agent/go.sum
server/go.sum
tests/go.sum
- name: Run E2E tests (mock-based)
working-directory: ./tests
run: go test -v -count=1 ./...
- uses: actions/upload-artifact@v7
if: always()
with:
name: e2e-test-results
path: tests/*.log
if-no-files-found: ignore
# ============================================================================
# E2E Docker - Full integration tests with real containers
# ============================================================================
e2e-docker:
name: E2E (Docker)
runs-on: ubuntu-latest
needs: [agent, server]
steps:
- uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Create data directories
run: |
mkdir -p tests/testdata/server
mkdir -p tests/testdata/agent
- name: Start E2E environment
working-directory: ./tests
run: |
docker compose -f docker-compose.e2e.yml up -d --build server agent
echo "Waiting for services to be healthy..."
sleep 10
docker compose -f docker-compose.e2e.yml ps
- name: Wait for services
run: |
echo "Waiting for server..."
server_ready=false
for i in {1..30}; do
if curl -sf http://localhost:9090/health > /dev/null 2>&1; then
echo "Server is ready!"
server_ready=true
break
fi
echo "Attempt $i: Server not ready yet..."
sleep 2
done
if [ "$server_ready" = false ]; then
echo "::error::Server failed to become ready after 30 attempts"
echo "Docker logs for server:"
docker compose -f tests/docker-compose.e2e.yml logs server
exit 1
fi
echo "Waiting for agent..."
agent_ready=false
for i in {1..30}; do
if curl -sf http://localhost:8080/health > /dev/null 2>&1; then
echo "Agent is ready!"
agent_ready=true
break
fi
echo "Attempt $i: Agent not ready yet..."
sleep 2
done
if [ "$agent_ready" = false ]; then
echo "::error::Agent failed to become ready after 30 attempts"
echo "Docker logs for agent:"
docker compose -f tests/docker-compose.e2e.yml logs agent
exit 1
fi
- name: Seed test data
run: |
# Containers created the schema on startup, now seed test data
# Must seed from inside containers since they own the DB files
echo "Seeding server test data..."
docker exec pm-e2e-server sh -c "cat > /tmp/seed.sql && sqlite3 /data/server.db < /tmp/seed.sql" < tests/testdata/seed/server_data.sql
echo "Seeding agent test data..."
docker exec pm-e2e-agent sh -c "cat > /tmp/seed.sql && sqlite3 /data/agent.db < /tmp/seed.sql" < tests/testdata/seed/agent_data.sql
echo "Verifying seeded data..."
docker exec pm-e2e-server sqlite3 /data/server.db "SELECT 'Server devices: ' || COUNT(*) FROM devices;"
docker exec pm-e2e-agent sqlite3 /data/agent.db "SELECT 'Agent devices: ' || COUNT(*) FROM devices;"
- uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
cache-dependency-path: |
common/go.sum
agent/go.sum
server/go.sum
tests/go.sum
- name: Run E2E Docker tests
working-directory: ./tests
env:
E2E_SERVER_URL: http://localhost:9090
E2E_AGENT_URL: http://localhost:8080
E2E_ADMIN_PASSWORD: e2e-test-password
run: go test -tags=e2e -v -count=1 ./...
- name: Collect container logs
if: always()
working-directory: ./tests
run: |
mkdir -p results
docker compose -f docker-compose.e2e.yml logs server > results/server.log 2>&1 || true
docker compose -f docker-compose.e2e.yml logs agent > results/agent.log 2>&1 || true
- name: Stop E2E environment
if: always()
working-directory: ./tests
run: docker compose -f docker-compose.e2e.yml down -v
- uses: actions/upload-artifact@v7
if: always()
with:
name: e2e-docker-results
path: tests/results/
if-no-files-found: ignore
ci-passed:
name: CI Passed
runs-on: ubuntu-latest
needs: [agent, server, javascript, e2e, e2e-docker]
if: always()
steps:
- name: Check results
run: |
if [[ "${{ needs.agent.result }}" != "success" || "${{ needs.server.result }}" != "success" || "${{ needs.javascript.result }}" != "success" || "${{ needs.e2e.result }}" != "success" || "${{ needs.e2e-docker.result }}" != "success" ]]; then
echo "One or more jobs failed"
exit 1
fi
echo "All CI checks passed"