351 lines (308 loc) · 12.1 KB
/
tests.yml
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
name: Playwright API Checks
on:
pull_request:
schedule:
- cron: "0 6 * * *"
repository_dispatch:
workflow_dispatch:
inputs:
app_url:
description: "APP URL, to run tests against"
required: true
default: https://www.automationexercise.com
permissions:
contents: write
pages: write
jobs:
install:
permissions:
contents: read
pages: write
id-token: write
timeout-minutes: 60
runs-on: ubuntu-latest
outputs:
playwright_version: ${{ steps.set-env.outputs.PLAYWRIGHT_VERSION }}
started_at: ${{ steps.set-env.outputs.STARTED_AT}}
app_url: ${{ steps.set-env.outputs.APP_URL}}
pull_request_url: ${{ steps.set-env.outputs.PULL_REQUEST_URL }}
env:
SLACK_BOT_USER_OAUTH_TOKEN: ${{ secrets.SLACK_BOT_USER_OAUTH_TOKEN }}
APP_URL: ${{ github.event.inputs.app_url }}
PULL_REQUEST_URL: ${{ github.event.client_payload.pull_request_url }}${{ github.event.pull_request._links.html.href }}${{ github.event.client_payload.github.event.issue.html_url }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Set current date as env variable
run: echo "STARTED_AT=$(date +%s)" >> $GITHUB_ENV
# - name: Dump GitHub context for debugging
# id: github_context_step
# run: echo '${{ toJSON(github) }}'
- name: Cache node_modules
uses: actions/cache@v3
id: node-modules-cache
with:
path: |
node_modules
key: modules-${{ hashFiles('package-lock.json') }}
- run: npm ci --ignore-scripts
if: steps.node-modules-cache.outputs.cache-hit != 'true'
- name: Get installed Playwright version
id: playwright-version
run: echo "PLAYWRIGHT_VERSION=$(node -e "console.log(require('./package-lock.json').dependencies['@playwright/test'].version)")" >> $GITHUB_ENV
- name: Cache playwright binaries
uses: actions/cache@v3
id: playwright-cache
with:
path: |
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}
- run: npx playwright install --with-deps
if: steps.playwright-cache.outputs.cache-hit != 'true'
- run: npx playwright install-deps
if: steps.playwright-cache.outputs.cache-hit != 'true'
- name: Create Output for ENV Variables
id: set-env
run: |
echo "PLAYWRIGHT_VERSION=${{env.PLAYWRIGHT_VERSION}}" >> $GITHUB_OUTPUT
echo "STARTED_AT=${{env.STARTED_AT}}" >> $GITHUB_OUTPUT
echo "APP_URL=${{env.APP_URL}}" >> $GITHUB_OUTPUT
echo "PULL_REQUEST_URL=${{env.PULL_REQUEST_URL}}" >> $GITHUB_OUTPUT
tests:
name: Run Playwright Tests (${{ matrix.shardIndex }}/${{ strategy.job-total }})
needs: install
timeout-minutes: 60
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
shardIndex: [1, 2, 3, 4]
shardTotal: [4]
outputs:
playwright_version: ${{ steps.set-env.outputs.PLAYWRIGHT_VERSION }}
started_at: ${{ steps.set-env.outputs.STARTED_AT}}
app_url: ${{ steps.set-env.outputs.APP_URL}}
pull_request_url: ${{ steps.set-env.outputs.PULL_REQUEST_URL }}
env:
PLAYWRIGHT_VERSION: ${{ needs.install.outputs.playwright_version }}
STARTED_AT: ${{ needs.install.outputs.started_at }}
APP_URL: ${{ needs.install.outputs.app_url }}
PULL_REQUEST_URL: ${{ needs.install.outputs.pull_request_url }}
CURRENTS_PROJECT_ID: ${{ secrets.CURRENTS_PROJECT_ID }}
CURRENTS_RECORD_KEY: ${{ secrets.CURRENTS_RECORD_KEY }}
CURRENTS_CI_BUILD_ID: reporter-${{ github.repository }}-${{ github.run_id }}-${{ github.run_attempt }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- name: Cache node_modules
uses: actions/cache@v3
with:
path: |
node_modules
key: modules-${{ hashFiles('package-lock.json') }}
- name: Cache Playwright
uses: actions/cache@v3
with:
path: |
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}
- name: Install OS Dependencies (needed for Webkit)
run: npx playwright install --with-deps
- name: Set APP_URL if not passed in
if: env.APP_URL == null
run: |
echo "APP_URL=https://www.automationexercise.com" >> $GITHUB_ENV
- name: Run Playwright tests
run: APP_URL=${{ env.APP_URL}} npx playwright test --grep-invert @axe --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }} --workers=1
- name: Copy Summary to playwright-report/ folder
if: always()
run: cp summary.json playwright-report/summary.json
- uses: actions/upload-artifact@v3
if: always()
with:
name: report-${{ matrix.shardIndex }}
path: playwright-report/
retention-days: 3
- name: Upload blob report to GitHub Actions Artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: all-blob-reports
path: blob-report/
retention-days: 1
- name: Create Output for ENV Variables
if: always()
id: set-env
run: |
echo "PLAYWRIGHT_VERSION=${{env.PLAYWRIGHT_VERSION}}" >> $GITHUB_OUTPUT
echo "STARTED_AT=${{env.STARTED_AT}}" >> $GITHUB_OUTPUT
echo "APP_URL=${{env.APP_URL}}" >> $GITHUB_OUTPUT
echo "PULL_REQUEST_URL=${{env.PULL_REQUEST_URL}}" >> $GITHUB_OUTPUT
merge:
name: Merge Reports
if: ${{ always() }}
needs: [install, tests]
timeout-minutes: 60
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: true
env:
PLAYWRIGHT_VERSION: ${{ needs.tests.outputs.playwright_version }}
STARTED_AT: ${{ needs.tests.outputs.started_at }}
APP_URL: ${{ needs.tests.outputs.app_url }}
PULL_REQUEST_URL: ${{ needs.tests.outputs.pull_request_url }}
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- name: Cache node_modules
uses: actions/cache@v3
with:
path: |
node_modules
key: modules-${{ hashFiles('package-lock.json') }}
- name: Cache Playwright
uses: actions/cache@v3
with:
path: |
~/.cache/ms-playwright
key: playwright-${{ hashFiles('package-lock.json') }}
- uses: actions/download-artifact@v3
with:
path: playwright-report/
- name: Display structure of downloaded files
run: ls -R
- name: Remove Previous html-report directory if exists
run: rm -rf playwright-report/html-report
- name: Run Report Merge
run: npm run merge
- name: Display structure of Merged
run: ls -R
- name: Read Summary Report to Get Test Results
if: always()
run: |
STATUS=$(cat ./summary.json | jq -r '.status')
STATUS="$(echo $STATUS | sed 's/failed/failure/;s/passed/success/')"
echo "STATUS=$STATUS" >> $GITHUB_ENV
PASSED=$(cat ./summary.json | jq -r '.passed[]' | tr '\n' ' ')
echo "PASSED=$PASSED" >> $GITHUB_ENV
TIMEOUT=$(cat ./summary.json | jq -r '.timedOut[]' | tr '\n' ' ' | sed 's/ /--->TIMEOUT /g')
FAILURES=$(cat ./summary.json | jq -r '.failed[]' | tr '\n' ' ')
FAILURES+=$TIMEOUT
echo "FAILURES=$FAILURES" >> $GITHUB_ENV
- name: Download blob reports from GitHub Actions Artifacts
uses: actions/download-artifact@v3
with:
name: all-blob-reports
path: all-blob-reports
- name: Merge into HTML Report
run: npx playwright merge-reports --config=merge.config.ts ./all-blob-reports
- name: Copy Summary to html-report/ folder
if: always()
run: cp summary.json playwright-report/summary.json
- name: Upload HTML report
uses: actions/upload-artifact@v3
with:
name: html-report-attempt-${{ github.run_attempt }}
path: playwright-report
retention-days: 14
- name: Setup Pages
if: always()
uses: actions/configure-pages@v2
- name: Upload artifact
if: always()
uses: actions/upload-pages-artifact@v1
with:
path: playwright-report/
- name: Deploy to GitHub Pages
if: always()
id: deployment
uses: actions/deploy-pages@v1
- name: Output time taken
if: always()
run: |
echo "Duration: $(($(($(date +%s) - ${{ env.STARTED_AT }}))/60)) minute(s)"
echo "DURATION=$(($(($(date +%s) - ${{ env.STARTED_AT }}))/60))" >> $GITHUB_ENV
- name: Notify MS Teams on Success
if: success()
uses: jdcargile/ms-teams-notification@v1.3
with:
github-token: ${{ github.token }} # this will use the runner's token.
ms-teams-webhook-uri: ${{ secrets.MSTEAMS_WEBHOOK }}
notification-summary: Results ✅ ${{ env.PASSED }} | ❌ ${{ env.FAILURES }}
notification-color: 28a745
timezone: America/Chicago
- name: Notify MS Teams on Failure
if: failure()
uses: jdcargile/ms-teams-notification@v1.3
with:
github-token: ${{ github.token }}
ms-teams-webhook-uri: ${{ secrets.MSTEAMS_WEBHOOK }}
notification-summary: Results ✅ ${{ env.PASSED }} | ❌ ${{ env.FAILURES }}
notification-color: dc3545
timezone: America/Chicago
- name: Send Slack Notification
if: always()
uses: 8398a7/action-slack@v3
with:
status: custom
fields: repo,eventName,workflow,job,took
custom_payload: |
{
attachments: [{
color: '${{ env.STATUS }}' === 'success' ? 'good' : 'danger',
title: `Playwright Demo Automation Results :test_tube:`,
fields: [{
title: 'Site Under Test',
value: '${{ env.APP_URL }}',
short: true
},
{
title: 'Triggered By',
value: [{'origin': 'pull_request', 'new': 'Pull Request'}, {'origin': 'schedule', 'new': 'Schedule'}, {'origin': 'repository_dispatch', 'new': 'Deploy'}, {'origin': 'workflow_dispatch', 'new': 'GitHub Actions'}].find(item => item.origin === `${process.env.AS_EVENT_NAME}`).new || `${process.env.AS_EVENT_NAME}`,
short: true
},
{
title: 'Repo',
value: `${process.env.AS_REPO}`,
short: true
},
{
title: 'Execution Time',
value: `Took ${{ env.DURATION }} minute(s)`,
short: true
},
{
title: 'Workflow',
value: `${process.env.AS_WORKFLOW}`,
short: true
},
{
title: 'Total Tests',
value: (`${{ env.FAILURES }}`.match(/.spec.ts/g) || []).length + (`${{ env.PASSED }}`.match(/.spec.ts/g) || []).length,
short: true
},
{
title: 'Pull Request',
value: `${{ env.PULL_REQUEST_URL }}`,
short: false
},
{
title: 'Failures',
value: `${{ env.FAILURES }}` === '' ? 'No failures' : `${{ env.FAILURES }}`.match(/.spec.ts/g).length > 10 ? `Too many failures to print. Please go to GitHub to see full list of failures` : '```${{ env.FAILURES }}```'.replace(/ /g, '\n'),
short: false
}]
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
MATRIX_CONTEXT: ${{ toJson(matrix) }}