-
Notifications
You must be signed in to change notification settings - Fork 361
309 lines (276 loc) · 10.9 KB
/
Copy pathplaywright.yml
File metadata and controls
309 lines (276 loc) · 10.9 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
name: Playwright
on:
push:
branches:
- develop
- main
# Ignore Storybook-only and unit-test-only changes when checking to run
# E2E tests. This is useful when adding/modifying/refactoring/removing
# test code ONLY in a commit, but saves running the expensive E2E test
# suite on GitHub Actions when all that's changing are tests and not code
# that would affect E2E behavior.
paths:
- ".github/workflows/playwright.yml"
- ".babelrc"
- "assets/**"
- "includes/**"
- "*.php"
- "jest-puppeteer.config.js"
- "composer.json"
- "composer.lock"
- "php-scoper/composer.lock"
- "package.json"
- "package-lock.json"
- "postcss.config.js"
- "webpack/*.config.js"
- "webpack.config.js"
- "tests/playwright/**"
- "!assets/**/__tests__/**/*.js"
- "!assets/**/test/*.js"
- "!assets/**/*.test.js"
- "!packages/**/__tests__/**/*.js"
- "!packages/**/test/*.js"
- "!packages/**/*.test.js"
pull_request:
branches:
- develop
- main
- "feature/**"
# Ignore Storybook-only and unit-test-only changes when checking to run
# E2E tests. This is useful when adding/modifying/refactoring/removing
# test code ONLY in a commit, but saves running the expensive E2E test
# suite on GitHub Actions when all that's changing are tests and not code
# that would affect E2E behavior.
paths:
- ".github/workflows/playwright.yml"
- ".babelrc"
- "assets/**"
- "includes/**"
- "*.php"
- "jest-puppeteer.config.js"
- "composer.json"
- "composer.lock"
- "php-scoper/composer.lock"
- "package.json"
- "package-lock.json"
- "postcss.config.js"
- "webpack/*.config.js"
- "webpack.config.js"
- "tests/playwright/**"
- "!assets/**/__tests__/**/*.js"
- "!assets/**/test/*.js"
- "!assets/**/*.test.js"
- "!packages/**/__tests__/**/*.js"
- "!packages/**/test/*.js"
- "!packages/**/*.test.js"
types:
- opened
- closed
- reopened
- synchronize
- ready_for_review
concurrency:
group: playwright-${{ github.ref }}
cancel-in-progress: true
env:
GCS_ROOT_PATH: playwright
FORBID_ONLY: true
RETRIES: 2
WORKERS: 4
CAN_UPLOAD_PLAYWRIGHT_REPORTS: ${{ github.event_name != 'pull_request' || ( ! contains( github.head_ref, 'dependabot/' ) && github.event.pull_request.head.repo.fork == false ) }}
jobs:
build:
name: Build
runs-on: ubuntu-latest
timeout-minutes: 15
if: github.event_name == 'push' || ( github.event_name == 'pull_request' && github.event.pull_request.draft == false && github.event.action != 'closed' )
permissions:
contents: read
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # ratchet:actions/checkout@v6
- uses: shivammathur/setup-php@7c071dfe9dc99bdf297fa79cb49ea005b9fcadbc # ratchet:shivammathur/setup-php@v2
with:
php-version: '8.4'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get Composer Cache Directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"
- uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # ratchet:actions/cache@v5
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Composer Install
run: composer install --no-interaction --no-progress --no-dev
- name: Setup Node.js (.nvmrc)
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # ratchet:actions/setup-node@v6
with:
node-version-file: .nvmrc
cache: npm
- name: Cache Playwright browsers
id: playwright-cache
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # ratchet:actions/cache@v5
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-browsers-${{ hashFiles('tests/playwright/package.json') }}
- name: Prepare plugin
run: |
npm ci --workspaces --include-workspace-root
npm run dev-zip
unzip -q google-site-kit.v*.zip -d plugin/
- name: Install Playwright browsers
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: npm run -w tests/playwright setup
- name: Upload plugin artifact
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # ratchet:actions/upload-artifact@v6
with:
name: plugin
path: plugin/google-site-kit
playwright-tests:
name: WordPress ${{ matrix.wp_version }}
needs: build
strategy:
fail-fast: false
matrix:
wp_version: ["latest", "nightly"]
include:
- wp_version: "5.2.21"
env:
WP_VERSION: ${{ matrix.wp_version }}
PLUGIN_PATH: ${{ github.workspace }}/plugin/google-site-kit
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
actions: read
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # ratchet:actions/checkout@v6
- name: Setup Node.js (.nvmrc)
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # ratchet:actions/setup-node@v6
with:
node-version-file: .nvmrc
cache: npm
- name: npm install
run: npm ci -w tests/playwright
env:
SKIP_PATCH_PACKAGE: '1'
- name: Download plugin artifact
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # ratchet:actions/download-artifact@v7
with:
name: plugin
path: plugin/google-site-kit
- name: Restore Playwright browsers cache
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # ratchet:actions/cache/restore@v5
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-browsers-${{ hashFiles('tests/playwright/package.json') }}
- name: Start environment
run: npm run playwright:env:start
- name: Run tests
id: run-tests
run: npm run test:playwright
env:
PLAYWRIGHT_HTML_TITLE: "WordPress ${{ matrix.wp_version }}"
- name: Upload artifacts
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # ratchet:actions/upload-artifact@v6
if: always()
with:
name: playwright-report-run[${{ github.run_attempt }}]-wp[${{ matrix.wp_version }}]
path: tests/playwright/artifacts/playwright-html
- name: Set report target directory
id: report-target
if: always() && env.CAN_UPLOAD_PLAYWRIGHT_REPORTS == 'true'
run: |
suffix="wp-${{ matrix.wp_version }}"
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "dir=pull/${{ github.event.number }}/${suffix}" >> "$GITHUB_OUTPUT"
else
echo "dir=${GITHUB_REF##*/}/${suffix}" >> "$GITHUB_OUTPUT"
fi
- uses: ./.github/actions/upload-to-gcs
id: upload-to-gcs
if: always() && env.CAN_UPLOAD_PLAYWRIGHT_REPORTS == 'true'
with:
credentials-json: ${{ secrets.GCP_CREDENTIALS }}
path: tests/playwright/artifacts
destination: ${{ env.GCS_ROOT_PATH }}/${{ steps.report-target.outputs.dir }}
- name: Save report URL
if: always() && env.CAN_UPLOAD_PLAYWRIGHT_REPORTS == 'true'
run: |
mkdir -p /tmp/artifact-url
if [ "${{ steps.run-tests.outcome }}" == "success" ]; then
echo "- ✅ [WordPress ${{ matrix.wp_version }}](${{ steps.upload-to-gcs.outputs.public-url }}/playwright-html/index.html)" > /tmp/artifact-url/url.md
else
echo "- ❌ [WordPress ${{ matrix.wp_version }}](${{ steps.upload-to-gcs.outputs.public-url }}/playwright-html/index.html)" > /tmp/artifact-url/url.md
fi
- name: Upload report URL
if: always() && env.CAN_UPLOAD_PLAYWRIGHT_REPORTS == 'true'
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # ratchet:actions/upload-artifact@v6
with:
name: artifact-url-wp-${{ matrix.wp_version }}
path: /tmp/artifact-url/url.md
add-comment-to-pr:
name: Add comment to PR
runs-on: ubuntu-latest
needs: playwright-tests
if: always() && github.event_name == 'pull_request' && ! contains( github.head_ref, 'dependabot/' ) && github.event.pull_request.head.repo.fork == false
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # ratchet:actions/checkout@v6
- name: Download artifact URLs
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # ratchet:actions/download-artifact@v7
with:
pattern: artifact-url-wp-*
merge-multiple: false
path: /tmp/artifact-urls/
- name: Build comment body
id: build-comment
run: |
{
echo 'body<<EOF'
echo '🎭 **Playwright reports for ${{ github.event.pull_request.head.sha }}:**'
find /tmp/artifact-urls -name 'url.md' | sort | xargs cat
echo EOF
} >> "$GITHUB_OUTPUT"
- uses: ./.github/actions/update-pr-comment
with:
issue-number: ${{ github.event.pull_request.number }}
section-id: playwright
section-content: ${{ steps.build-comment.outputs.body }}
remove-playwright-reports:
name: Remove Playwright reports
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' && github.event.action == 'closed'
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # ratchet:actions/checkout@v6
- uses: ./.github/actions/remove-gcs-path
with:
credentials-json: ${{ secrets.GCP_CREDENTIALS }}
path: ${{ env.GCS_ROOT_PATH }}/pull/${{ github.event.pull_request.number }}
- uses: ./.github/actions/update-pr-comment
with:
issue-number: ${{ github.event.pull_request.number }}
section-id: playwright
section-content: |
🎭 **Playwright reports for ${{ github.event.pull_request.head.sha }}:**
- Reports have been deleted.
cleanup-artifacts:
name: Cleanup temporary artifacts
runs-on: ubuntu-latest
needs: [playwright-tests, add-comment-to-pr]
if: always()
permissions:
actions: write
steps:
- name: Delete temporary artifacts
uses: geekyeggo/delete-artifact@176a747ab7e287e3ff4787bf8a148716375ca118 # ratchet:geekyeggo/delete-artifact@v6
with:
name: |
plugin
artifact-url-wp-*