-
Notifications
You must be signed in to change notification settings - Fork 0
483 lines (430 loc) · 18.2 KB
/
e2e-pullpreview.yml
File metadata and controls
483 lines (430 loc) · 18.2 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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
name: E2E PullPreview Orchestration
on:
workflow_dispatch:
inputs:
suite:
description: "Test suite selector (all runs full suite)"
required: true
default: all
type: choice
options:
- all
- smoke
- regression
- integration
- custom
custom_grep:
description: "Custom Playwright --grep expression (used when suite=custom)"
required: false
setupMethod:
description: "Setup method"
required: true
default: sso-external
type: choice
options:
- sso-external
- sso-nextcloud
- oauth2
keep_environment_on_failure:
description: "Keep PullPreview environment when tests fail"
required: true
default: false
type: boolean
integration_ref:
description: "Branch/ref in integration repo to execute workflow from"
required: true
default: main
type: string
integration_repo:
description: "Repository that owns PullPreview deployment"
required: true
default: opf/integration-qa-helmfile
type: string
integration_workflow:
description: "Dispatchable workflow filename in integration repo"
required: true
default: pullpreview-dispatch.yml
type: string
openproject_version:
description: "OpenProject image tag"
required: false
type: string
nextcloud_version:
description: "Nextcloud image tag"
required: false
type: string
keycloak_version:
description: "Keycloak image tag"
required: false
type: string
integration_app_version:
description: "integration_openproject app version (alias if integration_openproject_version is empty)"
required: false
type: string
integration_openproject_version:
description: "integration_openproject app version (overrides integration_app_version when set)"
required: false
type: string
integration_openproject_git_branch:
description: "integration_openproject git branch (version ignored when set)"
required: false
type: string
openproject_branch:
description: "Optional OpenProject git branch override"
required: false
type: string
nextcloud_branch:
description: "Optional Nextcloud git branch override"
required: false
type: string
jobs:
pullpreview-e2e:
runs-on: ubuntu-latest
timeout-minutes: 120
permissions:
contents: read
env:
CI: true
HEADLESS: true
SKIP_SETUP_JOB_CHECK: true
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Log refs and inputs
shell: bash
run: |
set -euo pipefail
echo "E2E repo ref: ${GITHUB_REF_NAME:-} sha: ${GITHUB_SHA:-}"
echo "Integration repo: ${{ github.event.inputs.integration_repo }}"
echo "Integration workflow: ${{ github.event.inputs.integration_workflow }}"
echo "Integration ref: ${{ github.event.inputs.integration_ref }}"
echo "Setup method: ${{ github.event.inputs.setupMethod }}"
echo "Requested versions: OP='${{ github.event.inputs.openproject_version }}' NC='${{ github.event.inputs.nextcloud_version }}' KC='${{ github.event.inputs.keycloak_version }}'"
echo "Requested integration app: legacy='${{ github.event.inputs.integration_app_version }}' io_ver='${{ github.event.inputs.integration_openproject_version }}' io_git='${{ github.event.inputs.integration_openproject_git_branch }}'"
echo "Requested branches: OP='${{ github.event.inputs.openproject_branch }}' NC='${{ github.event.inputs.nextcloud_branch }}'"
test -f ".github/workflows/e2e-pullpreview.yml"
echo "Workflow file present: .github/workflows/e2e-pullpreview.yml"
- name: Resolve grep and preview name
id: resolve
shell: bash
run: |
set -euo pipefail
suite="${{ github.event.inputs.suite }}"
grep=""
case "$suite" in
all) grep='' ;;
smoke) grep='@smoke' ;;
regression) grep='@regression' ;;
integration) grep='@integration' ;;
custom) grep='${{ github.event.inputs.custom_grep }}' ;;
*)
echo "::error::Unknown suite: $suite"
exit 1
;;
esac
if [ "$suite" = "custom" ] && [ -z "${grep}" ]; then
echo "::error::Resolved grep is empty. For suite=custom, set custom_grep."
exit 1
fi
preview_name='${{ github.event.inputs.preview_name }}'
if [ -z "${preview_name}" ]; then
preview_name="e2e-${{ github.run_id }}-${{ github.run_attempt }}"
fi
{
echo "grep=${grep}"
echo "preview_name=${preview_name}"
echo "deploy_started_at=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
} >> "$GITHUB_OUTPUT"
echo "Suite: ${suite}"
echo "Grep: ${grep}"
echo "Preview name: ${preview_name}"
- name: Dispatch PullPreview deploy workflow
shell: bash
env:
GH_TOKEN: ${{ secrets.INTEGRATION_REPO_PAT }}
run: |
set -euo pipefail
if [ -z "${GH_TOKEN:-}" ]; then
echo "::error::Missing secret INTEGRATION_REPO_PAT"
exit 1
fi
owner_repo="${{ github.event.inputs.integration_repo }}"
workflow_file="${{ github.event.inputs.integration_workflow }}"
target_ref="${{ github.event.inputs.integration_ref }}"
if [ -z "${owner_repo}" ] || [ -z "${workflow_file}" ]; then
echo "::error::integration_repo and integration_workflow must be set."
exit 1
fi
payload="$(jq -n \
--arg ref "$target_ref" \
--arg action "up" \
--arg preview_name "${{ steps.resolve.outputs.preview_name }}" \
--arg setup_method "${{ github.event.inputs.setupMethod }}" \
--arg openproject_version "${{ github.event.inputs.openproject_version }}" \
--arg nextcloud_version "${{ github.event.inputs.nextcloud_version }}" \
--arg keycloak_version "${{ github.event.inputs.keycloak_version }}" \
--arg integration_app_version "${{ github.event.inputs.integration_app_version }}" \
--arg integration_openproject_version "${{ github.event.inputs.integration_openproject_version }}" \
--arg integration_openproject_git_branch "${{ github.event.inputs.integration_openproject_git_branch }}" \
--arg openproject_branch "${{ github.event.inputs.openproject_branch }}" \
--arg nextcloud_branch "${{ github.event.inputs.nextcloud_branch }}" \
'{
ref: $ref,
inputs: {
action: $action,
preview_name: $preview_name,
integrationSetupMethod: $setup_method,
openproject_version: $openproject_version,
nextcloud_version: $nextcloud_version,
keycloak_version: $keycloak_version,
integration_app_version: $integration_app_version,
integration_openproject_version: $integration_openproject_version,
integration_openproject_git_branch: $integration_openproject_git_branch,
openproject_branch: $openproject_branch,
nextcloud_branch: $nextcloud_branch
}
}'
)"
curl -fsSL -X POST \
-H "Authorization: Bearer ${GH_TOKEN}" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${owner_repo}/actions/workflows/${workflow_file}/dispatches" \
-d "${payload}"
echo "Dispatched ${workflow_file} in ${owner_repo} on ref ${target_ref}"
- name: Wait for deploy run and fetch preview info
id: preview
shell: bash
env:
GH_TOKEN: ${{ secrets.INTEGRATION_REPO_PAT }}
OWNER_REPO: ${{ github.event.inputs.integration_repo }}
WORKFLOW_FILE: ${{ github.event.inputs.integration_workflow }}
TARGET_REF: ${{ github.event.inputs.integration_ref }}
PREVIEW_NAME: ${{ steps.resolve.outputs.preview_name }}
STARTED_AT: ${{ steps.resolve.outputs.deploy_started_at }}
run: |
set -euo pipefail
if [ -z "${GH_TOKEN:-}" ]; then
echo "::error::Missing secret INTEGRATION_REPO_PAT"
exit 1
fi
max_wait_seconds=3600
interval_seconds=15
elapsed=0
run_id=""
status=""
conclusion=""
workflow_name_prefix="PullPreview Dispatch"
while [ "$elapsed" -lt "$max_wait_seconds" ]; do
runs_json="$(curl -fsSL \
-H "Authorization: Bearer ${GH_TOKEN}" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${OWNER_REPO}/actions/workflows/${WORKFLOW_FILE}/runs?event=workflow_dispatch&branch=${TARGET_REF}&per_page=50")"
run_match="$(echo "${runs_json}" | jq -r \
--arg preview "${PREVIEW_NAME}" \
--arg started "${STARTED_AT}" \
--arg wfPrefix "${workflow_name_prefix}" \
'.workflow_runs
| map(select((.name // "") | startswith($wfPrefix)))
| map(select((.display_title // "") | contains($preview)))
| map(select(.created_at >= $started))
| sort_by(.created_at)
| last // empty
| @base64')"
if [ -n "${run_match}" ]; then
run_json="$(echo "${run_match}" | base64 --decode)"
run_id="$(echo "${run_json}" | jq -r '.id')"
head_sha="$(echo "${run_json}" | jq -r '.head_sha // empty')"
status="$(echo "${run_json}" | jq -r '.status')"
conclusion="$(echo "${run_json}" | jq -r '.conclusion // ""')"
if [ -n "${head_sha}" ]; then
echo "Deploy run ${run_id}: sha=${head_sha} status=${status}, conclusion=${conclusion}"
else
echo "Deploy run ${run_id}: status=${status}, conclusion=${conclusion}"
fi
if [ "${status}" = "completed" ]; then
break
fi
else
echo "No matching deploy run found yet for preview ${PREVIEW_NAME}"
fi
sleep "${interval_seconds}"
elapsed=$((elapsed + interval_seconds))
done
if [ -z "${run_id}" ]; then
echo "::error::Timed out waiting for integration workflow run to appear"
exit 1
fi
if [ "${status}" != "completed" ]; then
echo "::error::Timed out waiting for deploy run completion"
exit 1
fi
if [ "${conclusion}" != "success" ]; then
echo "::error::Deploy run failed with conclusion=${conclusion}"
echo "deploy_run_id=${run_id}" >> "$GITHUB_OUTPUT"
exit 1
fi
artifact_url=""
artifact_attempts=20
artifact_sleep_seconds=5
for attempt in $(seq 1 "${artifact_attempts}"); do
artifacts_json="$(curl -fsSL \
-H "Authorization: Bearer ${GH_TOKEN}" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${OWNER_REPO}/actions/runs/${run_id}/artifacts")"
artifact_url="$(echo "${artifacts_json}" | jq -r \
'.artifacts
| map(select(.name == "pullpreview-info"))
| first
| .archive_download_url // empty')"
if [ -n "${artifact_url}" ]; then
echo "Found pullpreview-info artifact (attempt ${attempt}/${artifact_attempts})"
break
fi
echo "Waiting for pullpreview-info artifact (attempt ${attempt}/${artifact_attempts})"
sleep "${artifact_sleep_seconds}"
done
if [ -z "${artifact_url}" ]; then
echo "::error::Artifact pullpreview-info not found for run ${run_id} after ${artifact_attempts} attempts"
exit 1
fi
curl -fsSL \
-H "Authorization: Bearer ${GH_TOKEN}" \
-H "Accept: application/vnd.github+json" \
"${artifact_url}" \
-o pullpreview-info.zip
rm -rf pullpreview-info
mkdir -p pullpreview-info
unzip -o pullpreview-info.zip -d pullpreview-info >/dev/null
info_file="pullpreview-info/preview-info.json"
if [ ! -f "${info_file}" ]; then
echo "::error::preview-info.json missing in artifact"
exit 1
fi
preview_host="$(jq -r '.preview_host // empty' "${info_file}")"
preview_url="$(jq -r '.preview_url // empty' "${info_file}")"
nextcloud_url="$(jq -r '.nextcloud_url // empty' "${info_file}")"
keycloak_url="$(jq -r '.keycloak_url // empty' "${info_file}")"
live="$(jq -r '.live // false' "${info_file}")"
if [ -z "${preview_host}" ] || [ "${live}" != "true" ]; then
echo "::error::Preview not live or host missing (live=${live}, host=${preview_host})"
exit 1
fi
# Normalize https default port to avoid https://host:443 form.
if [[ "${preview_url}" == *:443 ]]; then
preview_url="${preview_url%:443}"
fi
{
echo "OPENPROJECT_HOST=${preview_host}"
echo "NEXTCLOUD_HOST=nextcloud.${preview_host}"
echo "KEYCLOAK_HOST=keycloak.${preview_host}"
echo "OPENPROJECT_URL=${preview_url}"
echo "NEXTCLOUD_URL=${nextcloud_url}"
echo "E2E_ENV=pullpreview"
} >> "$GITHUB_ENV"
{
echo "preview_host=${preview_host}"
echo "preview_url=${preview_url}"
echo "nextcloud_url=${nextcloud_url}"
echo "keycloak_url=${keycloak_url}"
echo "deploy_run_id=${run_id}"
} >> "$GITHUB_OUTPUT"
- name: Preview endpoints
if: always() && steps.preview.outcome == 'success'
shell: bash
run: |
{
echo "### PullPreview endpoints"
echo ""
echo "- Preview name: \`${{ steps.resolve.outputs.preview_name }}\`"
echo "- OpenProject: ${{ steps.preview.outputs.preview_url }}"
echo "- Nextcloud: ${{ steps.preview.outputs.nextcloud_url }}"
echo "- Keycloak: ${{ steps.preview.outputs.keycloak_url }}"
} >> "$GITHUB_STEP_SUMMARY"
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: npm
- name: Install dependencies
run: npm ci
- name: Install Playwright browsers
run: npx playwright install --with-deps chromium
- name: Run Playwright tests
id: tests
continue-on-error: true
env:
SETUP_METHOD: ${{ github.event.inputs.setupMethod }}
TAG_GREP: ${{ steps.resolve.outputs.grep }}
shell: bash
run: |
set -euo pipefail
CMD="npx playwright test"
if [ -n "${TAG_GREP:-}" ]; then
CMD="${CMD} --grep \"${TAG_GREP}\""
fi
echo "Running: ${CMD}"
echo "Hosts: OP=${OPENPROJECT_HOST} NC=${NEXTCLOUD_HOST} KC=${KEYCLOAK_HOST}"
eval "${CMD}"
- name: Trigger PullPreview teardown
if: always() && (steps.tests.outcome == 'success' || github.event.inputs.keep_environment_on_failure != 'true' || steps.preview.outcome != 'success')
shell: bash
env:
GH_TOKEN: ${{ secrets.INTEGRATION_REPO_PAT }}
run: |
set -euo pipefail
if [ -z "${GH_TOKEN:-}" ]; then
echo "::warning::Missing INTEGRATION_REPO_PAT, skipping teardown dispatch."
exit 0
fi
owner_repo="${{ github.event.inputs.integration_repo }}"
workflow_file="${{ github.event.inputs.integration_workflow }}"
target_ref="${{ github.event.inputs.integration_ref }}"
if [ -z "${owner_repo}" ] || [ -z "${workflow_file}" ]; then
echo "::warning::integration_repo or integration_workflow empty; skipping teardown dispatch."
exit 0
fi
payload="$(jq -n \
--arg ref "$target_ref" \
--arg action "down" \
--arg preview_name "${{ steps.resolve.outputs.preview_name }}" \
'{
ref: $ref,
inputs: {
action: $action,
preview_name: $preview_name
}
}'
)"
curl -fsSL -X POST \
-H "Authorization: Bearer ${GH_TOKEN}" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${owner_repo}/actions/workflows/${workflow_file}/dispatches" \
-d "${payload}"
echo "Teardown dispatched for preview ${{ steps.resolve.outputs.preview_name }}"
- name: Keep environment notice
if: always() && steps.tests.outcome != 'success' && github.event.inputs.keep_environment_on_failure == 'true'
shell: bash
run: |
{
echo "### PullPreview environment kept for debugging"
echo ""
echo "- Preview name: \`${{ steps.resolve.outputs.preview_name }}\`"
echo "- OpenProject: ${{ steps.preview.outputs.preview_url }}"
echo "- Nextcloud: ${{ steps.preview.outputs.nextcloud_url }}"
echo "- Keycloak: ${{ steps.preview.outputs.keycloak_url }}"
} >> "$GITHUB_STEP_SUMMARY"
- name: Upload Playwright report
if: always()
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: playwright-report
- name: Final status
if: always()
shell: bash
run: |
if [ "${{ steps.tests.outcome }}" != "success" ]; then
echo "::error::Playwright tests failed."
exit 1
fi