Repository navigation
213 lines (202 loc) · 8.29 KB
/
Copy pathe2e.yml
File metadata and controls
213 lines (202 loc) · 8.29 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
name: E2E
on:
pull_request:
push:
branches:
- main
workflow_dispatch:
inputs:
profile:
description: Execution profile from e2e/ci.yml.
required: true
default: regression
type: string
projects:
description: Optional project override, one per line.
required: false
default: ""
type: string
labels:
description: Optional tag override, one per line.
required: false
default: ""
type: string
label-match:
description: Optional tag matching override.
required: false
default: profile
type: choice
options:
- profile
- all
- any
permissions:
contents: read
pull-requests: write
concurrency:
group: e2e-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
e2e:
name: E2E Gate
runs-on: ubuntu-latest
timeout-minutes: 45
env:
COMPOSE_PROJECT_NAME: e2e-${{ github.run_id }}-${{ github.run_attempt }}
steps:
- name: Check out repository
uses: actions/checkout@v7
- id: sut
name: Start example SUT and wait for readiness
continue-on-error: true
shell: bash
run: |
mkdir -p sut-logs
docker compose -f compose.e2e.yml up --detach --build --wait 2>&1 | tee sut-logs/startup.log
- id: e2e
name: Run E2E
if: steps.sut.outcome == 'success'
continue-on-error: true
uses: $/
env:
DEMO_RUNTIME_TOKEN: synthetic-token-not-a-secret
DEMO_RUNTIME_MESSAGE: |-
hello from the workflow
spaces, "quotes", $dollar and = survive
DEMO_UNLISTED_TOKEN: must-stay-outside-the-runner
with:
runtime-env: |
DEMO_RUNTIME_TOKEN
DEMO_RUNTIME_MESSAGE
profile: >-
${{ github.event_name == 'pull_request' && 'pull-request' ||
github.event_name == 'push' && 'main' || inputs.profile }}
projects: ${{ github.event_name == 'workflow_dispatch' && inputs.projects || '' }}
labels: ${{ github.event_name == 'workflow_dispatch' && inputs.labels || '' }}
label-match: >-
${{ github.event_name == 'workflow_dispatch' && inputs.label-match != 'profile' &&
inputs.label-match || '' }}
- id: sut-logs
name: Capture example SUT logs
if: always() && steps.sut.outcome != 'skipped'
continue-on-error: true
shell: bash
run: |
mkdir -p sut-logs
docker compose -f compose.e2e.yml logs --no-color --timestamps > sut-logs/services.log 2>&1
- id: sut-cleanup
name: Stop example SUT
if: always() && steps.sut.outcome != 'skipped'
continue-on-error: true
shell: bash
run: |
mkdir -p sut-logs
docker compose -f compose.e2e.yml down --volumes --remove-orphans > sut-logs/teardown.log 2>&1
- id: sut-artifact
name: Upload example SUT logs
if: always() && steps.sut.outcome != 'skipped'
continue-on-error: true
uses: actions/upload-artifact@v7
with:
name: sut-logs
path: sut-logs/
if-no-files-found: error
retention-days: 10
- name: Update pull request
if: always() && github.event_name == 'pull_request'
uses: actions/github-script@v9
env:
E2E_RESULT: ${{ steps.e2e.outputs.result }}
E2E_SUT_SETUP: ${{ steps.sut.outcome }}
E2E_SUT_CLEANUP: ${{ steps.sut-cleanup.outcome }}
E2E_SUT_LOGS: ${{ steps.sut-logs.outcome }}
E2E_SUT_ARTIFACT: ${{ steps.sut-artifact.outcome }}
E2E_PRIMARY_FAILURE: ${{ steps.e2e.outputs.primary-failure }}
E2E_TOTAL: ${{ steps.e2e.outputs.total }}
E2E_PASSED: ${{ steps.e2e.outputs.passed }}
E2E_FAILED: ${{ steps.e2e.outputs.failed }}
E2E_SKIPPED: ${{ steps.e2e.outputs.skipped }}
E2E_PROFILE: ${{ steps.e2e.outputs.profile }}
E2E_PROJECTS: ${{ steps.e2e.outputs.projects }}
E2E_LABELS: ${{ steps.e2e.outputs.labels }}
E2E_LABEL_MATCH: ${{ steps.e2e.outputs.label-match }}
E2E_RUNNER_CACHE_HIT: ${{ steps.e2e.outputs.runner-cache-hit }}
E2E_RUNNER_IMAGE: ${{ steps.e2e.outputs.runner-image-name }}
E2E_RESULTS_ARTIFACT: ${{ steps.e2e.outputs.results-artifact }}
E2E_REPORT_IMAGE: ${{ steps.e2e.outputs.report-image-name }}
E2E_REPORT_ARTIFACT: ${{ steps.e2e.outputs.report-image-artifact }}
with:
script: |
const marker = '<!-- playwright-e2e-report -->';
const value = (name, fallback = 'n/a') => process.env[name] || fallback;
const list = (name) => value(name).split('\n').filter(Boolean).join(', ');
const actionResult = value('E2E_RESULT', 'infrastructure-error');
const lifecycleFailures = ['E2E_SUT_SETUP', 'E2E_SUT_CLEANUP', 'E2E_SUT_LOGS', 'E2E_SUT_ARTIFACT']
.filter((name) => value(name) !== 'success');
const result = actionResult === 'failed'
? 'failed'
: lifecycleFailures.length ? 'infrastructure-error' : actionResult;
const icon = result === 'passed' ? '✅' : result === 'failed' ? '❌' : '⚠️';
const cache = value('E2E_RUNNER_CACHE_HIT', 'false') === 'true' ? 'reused' : 'built';
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const rows = [
['Gate', `${icon} ${result}`],
['Caller SUT', `setup: ${value('E2E_SUT_SETUP')} · cleanup: ${value('E2E_SUT_CLEANUP')} · artifact: sut-logs`],
['Tests', `${value('E2E_PASSED', '0')} passed · ${value('E2E_FAILED', '0')} failed · ${value('E2E_SKIPPED', '0')} skipped · ${value('E2E_TOTAL', '0')} total`],
['Profile', value('E2E_PROFILE')],
['Projects', list('E2E_PROJECTS')],
['Tags', `${list('E2E_LABELS')} (${value('E2E_LABEL_MATCH')})`],
['Runner', `${value('E2E_RUNNER_IMAGE')} (${cache})`],
['Results', value('E2E_RESULTS_ARTIFACT')],
['Report image', `${value('E2E_REPORT_IMAGE')} · ${value('E2E_REPORT_ARTIFACT')}`],
['Run', `[Open workflow run](${runUrl})`],
];
const failureMessage = process.env.E2E_PRIMARY_FAILURE ||
(lifecycleFailures.length ? `Caller lifecycle did not succeed: ${lifecycleFailures.join(', ')}` : '');
const failure = failureMessage
? `\n> ${failureMessage}\n`
: '';
const body = [
marker,
'## E2E test report',
'',
'| | |',
'|---|---|',
...rows.map(([name, detail]) => `| ${name} | ${detail} |`),
failure,
].join('\n');
const comments = await github.paginate(github.rest.issues.listComments, {
...context.repo,
issue_number: context.issue.number,
per_page: 100,
});
const previous = comments.find((comment) =>
comment.user?.type === 'Bot' && comment.body?.includes(marker));
if (previous) {
await github.rest.issues.updateComment({
...context.repo,
comment_id: previous.id,
body,
});
} else {
await github.rest.issues.createComment({
...context.repo,
issue_number: context.issue.number,
body,
});
}
- name: Preserve E2E result
if: always()
shell: bash
env:
E2E_STEP_OUTCOME: ${{ steps.e2e.outcome }}
SUT_SETUP_OUTCOME: ${{ steps.sut.outcome }}
SUT_LOGS_OUTCOME: ${{ steps.sut-logs.outcome }}
SUT_CLEANUP_OUTCOME: ${{ steps.sut-cleanup.outcome }}
SUT_ARTIFACT_OUTCOME: ${{ steps.sut-artifact.outcome }}
run: |
for outcome in "$E2E_STEP_OUTCOME" "$SUT_SETUP_OUTCOME" "$SUT_LOGS_OUTCOME" "$SUT_CLEANUP_OUTCOME" "$SUT_ARTIFACT_OUTCOME"; do
if [[ "$outcome" != "success" ]]; then
exit 1
fi
done