-
Notifications
You must be signed in to change notification settings - Fork 2
313 lines (282 loc) · 13.6 KB
/
Copy pathci-tests.yml
File metadata and controls
313 lines (282 loc) · 13.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
name: Test
on:
workflow_call:
inputs:
should_skip:
description: "Whether to skip the workflow"
required: false
type: string
default: "false"
webapp_changed:
description: "Whether webapp files changed"
required: false
type: string
default: "true"
application_server_changed:
description: "Whether application-server files changed"
required: false
type: string
default: "true"
e2e_changed:
description: "Whether browser E2E runtime files changed"
required: false
type: string
default: "true"
jobs:
tests:
permissions:
contents: read
checks: write
pull-requests: write
statuses: write
name: "${{ matrix.display-name }}"
runs-on: ubuntu-latest
if: inputs.should_skip != 'true'
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
include:
- test-type: application-server-verification
display-name: "App Server: Unit and Architecture"
- test-type: application-server-integration
display-name: "App Server: Integration"
- test-type: webapp-storybook
display-name: "Webapp: Stories"
- test-type: webapp-e2e
display-name: "Webapp: E2E"
steps:
- name: Determine if test should run
id: should_run
run: |
case "${{ matrix.test-type }}" in
"webapp-storybook")
echo "run=${{ inputs.webapp_changed }}" >> $GITHUB_OUTPUT
;;
"webapp-e2e")
echo "run=${{ inputs.e2e_changed }}" >> $GITHUB_OUTPUT
;;
application-server-*)
echo "run=${{ inputs.application_server_changed }}" >> $GITHUB_OUTPUT
;;
*)
echo "::error::Unknown test type '${{ matrix.test-type }}' in ci-tests.yml matrix."
echo "::error::Please add a case for this test type in the 'Determine if test should run' step."
echo "run=false" >> $GITHUB_OUTPUT
exit 1
;;
esac
- name: Skip notification
if: steps.should_run.outputs.run != 'true'
run: echo "⏭️ Skipping ${{ matrix.test-type }} - no relevant files changed"
- name: Checkout repository
if: steps.should_run.outputs.run == 'true'
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# Chromatic TurboSnap compares the stories job against its merge base.
fetch-depth: ${{ matrix.test-type == 'webapp-storybook' && '0' || '1' }}
persist-credentials: false
- name: Setup Bun
if: steps.should_run.outputs.run == 'true'
uses: ./.github/actions/setup-bun
- name: Setup caches
if: steps.should_run.outputs.run == 'true'
uses: ./.github/actions/setup-caches
with:
cache-type: ${{ matrix.test-type }}
os: ${{ runner.os }}
- name: Run server unit and architecture tests
if: steps.should_run.outputs.run == 'true' && matrix.test-type == 'application-server-verification'
run: |
rm -rf server/application/target/surefire-reports/*
bun run test:server:verification
- name: Run server integration tests
if: steps.should_run.outputs.run == 'true' && matrix.test-type == 'application-server-integration'
run: |
rm -rf server/application/target/surefire-reports/*
bun run test:server:integration
- name: Run tests
id: tests
continue-on-error: ${{ matrix.test-type == 'webapp-storybook' }}
if: steps.should_run.outputs.run == 'true' && startsWith(matrix.test-type, 'webapp-')
run: |
bun install --frozen-lockfile
cd webapp
case "${{ matrix.test-type }}" in
"webapp-storybook")
bun run playwright install chromium --with-deps
# Bound browser-runner deadlocks without coupling CI to the current suite duration.
timeout --kill-after=30s 15m bun run test:storybook
bun run export:readme-assets
if [[ -n "$(git status --porcelain --untracked-files=all -- ../docs/images/readme)" ]]; then
echo "::error::README or documentation images are stale. Run 'bun run --filter webapp export:readme-assets' and commit the result."
git status --short --untracked-files=all -- ../docs/images/readme
exit 1
fi
;;
"webapp-e2e")
docker compose -f ../server/compose.yaml up -d --wait postgres
cleanup() {
if [[ -n "${SERVER_PID:-}" ]]; then kill "${SERVER_PID}" 2>/dev/null || true; fi
docker compose -f ../server/compose.yaml down -v
}
trap cleanup EXIT
bun run playwright install chromium --with-deps
(
cd ../server
./mvnw install -pl generated-clients -am -DskipTests --batch-mode
SERVER_PORT=8080 MANAGEMENT_PORT=8080 POSTGRES_PORT=5432 \
SPRING_DOCKER_COMPOSE_ENABLED=false \
APPLICATION_HOST_URL=http://localhost:4200 \
./mvnw -pl application spring-boot:run \
-Dapp.profiles=e2e,playwright --batch-mode
) > ../e2e-server.log 2>&1 &
SERVER_PID=$!
timeout 5m bash -c 'until curl --fail --silent http://localhost:8080/actuator/health/liveness >/dev/null; do kill -0 '"${SERVER_PID}"' || exit 1; sleep 2; done'
curl --fail --silent --show-error -X POST http://localhost:8080/auth/dev-login \
-H 'content-type: application/json' -d '{"username":"e2e","admin":true}' >/dev/null
docker compose -f ../server/compose.yaml exec -T postgres \
psql -v ON_ERROR_STOP=1 -U root -d hephaestus < e2e/seed.sql
timeout --kill-after=30s 10m bun run test:e2e
;;
esac
- name: Summarize test results
if: steps.should_run.outputs.run == 'true' && always() && (startsWith(matrix.test-type, 'application-server-') || matrix.test-type == 'webapp-storybook')
continue-on-error: true
run: |
mkdir -p ci-metrics
if [[ "${{ matrix.test-type }}" == application-server-* ]]; then
bun run summarize:test-results "${{ matrix.display-name }}" server/application/target/surefire-reports "ci-metrics/${{ matrix.test-type }}.json"
else
bun run summarize:test-results "${{ matrix.display-name }}" webapp/test-results "ci-metrics/${{ matrix.test-type }}.json"
fi
- name: Upload test metrics
if: steps.should_run.outputs.run == 'true' && always() && (startsWith(matrix.test-type, 'application-server-') || matrix.test-type == 'webapp-storybook')
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: test-metrics-${{ matrix.test-type }}
path: ci-metrics/*.json
if-no-files-found: ignore
retention-days: 14
- name: Build Storybook for public preview
if: steps.should_run.outputs.run == 'true' && matrix.test-type == 'webapp-storybook'
run: bun run --filter webapp build-storybook
- name: "Chromatic Visual Testing"
if: >-
steps.should_run.outputs.run == 'true' && matrix.test-type == 'webapp-storybook' && always() &&
(github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
id: chromatic
continue-on-error: true
uses: chromaui/action@1cfa065cbdab28f6ca3afaeb3d761383076a35aa # v11
with:
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
workingDir: webapp
onlyChanged: true
zip: true
skip: "@(dependabot/**|renovate/**)"
autoAcceptChanges: ${{ github.ref == 'refs/heads/main' && 'main' || '' }}
exitZeroOnChanges: false
logLevel: info
junitReport: true
env:
CHROMATIC_BRANCH: ${{ github.head_ref || github.ref_name }}
CHROMATIC_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Deploy public Storybook preview
id: storybook_preview
if: >-
steps.should_run.outputs.run == 'true' && matrix.test-type == 'webapp-storybook' &&
github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository &&
startsWith(steps.chromatic.outputs.storybookUrl, 'http')
env:
PREVIEW_URL: ls1intum-hephaestus-storybook-pr-${{ github.event.number }}.surge.sh
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
run: bun --bun surge ./webapp/storybook-static "$PREVIEW_URL" --token "$SURGE_TOKEN"
- name: Add Storybook preview to the pull request
if: steps.storybook_preview.outcome == 'success'
uses: marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405 # v2.9.4
with:
header: storybook-preview
message: |
## 🧩 Storybook Preview
Review this pull request's components and interaction states:
🔗 **[View Storybook Preview](https://ls1intum-hephaestus-storybook-pr-${{ github.event.number }}.surge.sh)**
<sub>Preview for commit ${{ github.event.pull_request.head.sha }}. Updates automatically on new commits.</sub>
- name: "Create Storybook status check"
if: >-
steps.should_run.outputs.run == 'true' && matrix.test-type == 'webapp-storybook' && always() &&
startsWith(steps.chromatic.outputs.storybookUrl, 'http') &&
(github.event_name != 'pull_request' || steps.storybook_preview.outcome == 'success')
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const storybookUrl = context.payload.pull_request
? 'https://ls1intum-hephaestus-storybook-pr-${{ github.event.number }}.surge.sh'
: '${{ steps.chromatic.outputs.storybookUrl }}';
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.payload.pull_request?.head?.sha || context.sha,
state: 'success',
target_url: storybookUrl,
description: 'Click Details to view your Storybook',
context: 'Preview / Storybook'
});
- name: Upload application-server test results
if: steps.should_run.outputs.run == 'true' && always() && startsWith(matrix.test-type, 'application-server-')
uses: dorny/test-reporter@a43b3a5f7366b97d083190328d2c652e1a8b6aa2 # v3.0.0
with:
name: "Test Results - ${{ matrix.test-type }}"
path: "server/application/target/surefire-reports/TEST-*.xml"
reporter: java-junit
fail-on-error: false
- name: Upload webapp-storybook test results
if: steps.should_run.outputs.run == 'true' && always() && matrix.test-type == 'webapp-storybook'
uses: dorny/test-reporter@a43b3a5f7366b97d083190328d2c652e1a8b6aa2 # v3.0.0
with:
name: "Test Results - ${{ matrix.display-name }}"
path: "webapp/test-results/junit-storybook.xml"
reporter: java-junit
fail-on-error: false
- name: Upload webapp E2E diagnostics
if: steps.should_run.outputs.run == 'true' && failure() && matrix.test-type == 'webapp-e2e'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: webapp-e2e-results
path: |
webapp/test-results
e2e-server.log
if-no-files-found: warn
retention-days: 7
- name: Upload Chromatic test results
if: steps.should_run.outputs.run == 'true' && always() && matrix.test-type == 'webapp-storybook' && startsWith(steps.chromatic.outputs.storybookUrl, 'http')
uses: dorny/test-reporter@a43b3a5f7366b97d083190328d2c652e1a8b6aa2 # v3.0.0
with:
name: "Test Results - ${{ matrix.test-type }}"
path: "webapp/chromatic-build-*.xml"
reporter: java-junit
fail-on-error: false
- name: Evaluate stories checks
if: steps.should_run.outputs.run == 'true' && matrix.test-type == 'webapp-storybook' && always()
env:
STORYBOOK_TESTS: ${{ steps.tests.outcome }}
CHROMATIC: ${{ steps.chromatic.outcome }}
run: |
if [ "$STORYBOOK_TESTS" != "success" ] || { [ "$CHROMATIC" != "success" ] && [ "$CHROMATIC" != "skipped" ]; }; then
echo "::error::Storybook tests or Chromatic failed; review both independently reported steps."
exit 1
fi
- name: Generate test summary
if: steps.should_run.outputs.run == 'true' && always()
run: |
echo "### 🧪 ${{ matrix.test-type }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
case "${{ matrix.test-type }}" in
application-server-*)
if [ -d "server/application/target/surefire-reports" ]; then
TESTS=$(find server/application/target/surefire-reports -name "TEST-*.xml" -exec grep -h 'testsuite' {} \; 2>/dev/null | head -1 || echo "")
if [ -n "$TESTS" ]; then
echo "✅ Tests completed. See **Test Results** tab for details." >> $GITHUB_STEP_SUMMARY
fi
fi
;;
esac