-
Notifications
You must be signed in to change notification settings - Fork 15
265 lines (220 loc) · 8.52 KB
/
playwright-shard.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
name: Playwright Test
on:
workflow_dispatch:
push:
branches: [main]
pull_request:
branches: [main]
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
checks: write # for dorny/test-reporter
pull-requests: write # for leaving a comment on PR
env:
NODEJS_VERSION: 20
TESULTS_API_TOKEN: ${{ secrets.TESULTS_API_TOKEN }}
LH_TESULTS_API_TOKEN: ${{ secrets.LH_TESULTS_API_TOKEN }}
jobs:
create_tesults_target:
name: Create Tesults Target
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup NodeJS SDK ${{ env.NODEJS_VERSION }}
uses: actions/setup-node@v3
with:
cache: yarn
cache-dependency-path: yarn.lock
node-version: ${{ env.NODEJS_VERSION }}
# used to create/delete branch target
- name: Set Branch Name Environment Variable
run: |
# Short name for current branch. For PRs, use target branch (base ref)
BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
- name: Yarn Install
run: yarn install --mode=skip-build
- name: Set Tesults Token Output
run: node ./.scripts/create-delete-branch-target.js create
- name: Upload Tesults Token
uses: actions/upload-artifact@v3
with:
name: tesultsToken
path: tesultsToken.txt
playwright_test:
name: Playwright Test
needs: create_tesults_target
strategy:
fail-fast: false
matrix:
shard: [1/4, 2/4, 3/4, 4/4]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup NodeJS SDK ${{ env.NODEJS_VERSION }}
uses: actions/setup-node@v3
with:
cache: yarn
cache-dependency-path: yarn.lock
node-version: ${{ env.NODEJS_VERSION }}
- name: Yarn Install
run: yarn install
# caching playwright browsers, see https://github.com/microsoft/playwright/issues/7249
- name: Store Playwright Version
run: |
PLAYWRIGHT_VERSION=$(npm ls @playwright/test | grep @playwright | sed 's/.*@//')
echo "Playwright Version: $PLAYWRIGHT_VERSION"
echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV
- name: Cache Browsers for Playwright Version
id: cache-playwright-browsers
uses: actions/cache@v3
with:
path: ~/.cache/ms-playwright
key: playwright-browsers-${{ env.PLAYWRIGHT_VERSION }}
- name: Install Playwright Browsers
if: steps.cache-playwright-browsers.outputs.cache-hit != 'true'
run: yarn playwright install --with-deps
- name: Install Playwright Dependencies
if: steps.cache-playwright-browsers.outputs.cache-hit == 'true'
run: yarn playwright install-deps
- name: Download Tesults Token Artifact
uses: actions/download-artifact@v3
with:
name: tesultsToken
- name: Set Tesults Target
run: |
echo "PW_TESULTS_TOKEN=$(cat tesultsToken.txt)" >> $GITHUB_ENV
- name: Run Tests
run: yarn test:ci --shard ${{ matrix.shard }}
- 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: 10
# screenshot/video/trace is stored in test-results if a test fails, otherwise empty if all tests pass
- name: Upload test-results to GitHub Actions Artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: test-results
path: test-results/
retention-days: 10
if-no-files-found: warn
reporting:
if: ${{ always() }}
needs: playwright_test
name: Reporting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup NodeJS SDK ${{ env.NODEJS_VERSION }}
uses: actions/setup-node@v3
with:
cache: yarn
cache-dependency-path: yarn.lock
node-version: ${{ env.NODEJS_VERSION }}
- name: Yarn Install
run: yarn install
- name: Download blob reports from GitHub Actions Artifacts
uses: actions/download-artifact@v3
with:
name: all-blob-reports
path: all-blob-reports
# test-results directory is only created when a test fails, if all pass there is no dir to download
- name: Check for test-results Artifact
uses: xSAVIKx/artifact-exists-action@v0
id: check-artifact
with:
name: test-results
# TODO - watch for upcoming ignore feature on this so that the above step can be removed
- name: Download test-results from GitHub Actions Artifacts
uses: actions/download-artifact@v3
if: ${{ steps.check-artifact.outputs.exists == 'true' }}
with:
name: test-results
path: test-results
# xml report use by dorny-test-reporter
- name: Merge into XML Report
run: PLAYWRIGHT_JUNIT_OUTPUT_NAME=junit.xml npx playwright merge-reports --reporter=junit ./all-blob-reports
- name: Test Report
uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: Playwright Test Report
path: "**/junit.xml"
reporter: java-junit
fail-on-error: 'false'
- name: Merge into HTML Report
run: npx playwright merge-reports --reporter html ./all-blob-reports
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Upload HTML report for Pages
uses: actions/upload-pages-artifact@v2
with:
name: github-pages
path: playwright-report
retention-days: 14
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
- name: Message PR of Artifact Published
if: ${{ always() && github.event_name == 'pull_request' }}
uses: thollander/actions-comment-pull-request@main
with:
message: |
[Click here for Github Pages Playwright Report](${{ steps.deployment.outputs.page_url }})
[Click here to see Tesults Dashboard](https://www.tesults.com/results/rsp/view/status/project/48242328-a7eb-4ab4-8065-3a3686634e5c/group/playwright-boilerplate)
comment_tag: playwright_message
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
lighthouse_test:
if: ${{ always() }}
name: Lighthouse
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup NodeJS SDK ${{ env.NODEJS_VERSION }}
uses: actions/setup-node@v3
with:
cache: yarn
cache-dependency-path: yarn.lock
node-version: ${{ env.NODEJS_VERSION }}
- name: Yarn Install
run: yarn install
# caching playwright browsers, see https://github.com/microsoft/playwright/issues/7249
- name: Store Playwright Version
run: |
PLAYWRIGHT_VERSION=$(npm ls @playwright/test | grep @playwright | sed 's/.*@//')
echo "Playwright Version: $PLAYWRIGHT_VERSION"
echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV
- name: Cache Browsers for Playwright Version
id: cache-playwright-browsers
uses: actions/cache@v3
with:
path: ~/.cache/ms-playwright
key: playwright-browsers-${{ env.PLAYWRIGHT_VERSION }}
- name: Install Playwright Browsers
if: steps.cache-playwright-browsers.outputs.cache-hit != 'true'
run: yarn playwright install --with-deps chromium
- name: Install Playwright Dependencies
if: steps.cache-playwright-browsers.outputs.cache-hit == 'true'
run: yarn playwright install-deps
- name: Run Lighthouse
run: yarn test:lighthouse
- name: Upload Lighthouse Report
uses: actions/upload-artifact@v3
with:
name: lighthouse-report
path: tests/lighthouse/reports
retention-days: 10
- name: Message PR of Artifact Published
if: ${{ always() && github.event_name == 'pull_request' }}
uses: thollander/actions-comment-pull-request@main
with:
message: |
[Click here to see Tesults Lighthouse Report](https://www.tesults.com/results/rsp/view/results/target/48242328-a7eb-4ab4-8065-3a3686634e5c-1701748288944)
comment_tag: lighthouse_message
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}