-
Notifications
You must be signed in to change notification settings - Fork 5
447 lines (386 loc) · 15.7 KB
/
playwright.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
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
name: WordPress Composer Playwright Tests
on:
pull_request:
paths-ignore:
- '.github/workflows/ci.yml'
- '.github/workflows/composer-diff.yml'
- '.github/workflows/phpcbf.yml'
- '.github/workflows/sage-test.yml'
- '.github/workflows/sync-default.yml'
- '.github/tests/*.bats'
- 'private/scripts/**'
- 'docs/**'
- '*.md'
- 'phpcs.yml'
- 'wp-cli.yml'
- '.lando.upstream.yml'
- 'CODEOWNERS'
- '.editorconfig'
types:
- opened
- reopened
- synchronize
- ready_for_review
permissions:
contents: write
actions: read
jobs:
playwright-single:
name: Single site
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Wait for status artifacts
env:
GH_TOKEN: ${{ github.token }}
run: |
max_attempts=10
delay_seconds=30
attempt=0
success=0
status=0
echo "Checking for status artifacts..."
while [ $attempt -lt $max_attempts ]; do
# Attempt to download the artifacts.
gh run download -n status-8.1-${{ github.sha }} || true
gh run download -n status-8.2-${{ github.sha }} || true
gh run download -n status-8.3-${{ github.sha }} || true
if [ -f status-8.1-${{ github.sha }}.txt ] && [ -f status-8.2-${{ github.sha }}.txt ] && [ -f status-8.3-${{ github.sha }}.txt ]; then
success=1
break
else
echo "Status files not found. Sleeping for $delay_seconds seconds..."
sleep $delay_seconds
fi
attempt=$(( attempt + 1 ))
done
if [ $success -eq 0 ]; then
echo "Timed out waiting for status artifacts."
exit 1
fi
for file in status-*.txt; do
status=$(cat $file)
if [ $status -eq 1 ]; then
echo "status=$status" >> $GITHUB_ENV
exit 1
fi
done
echo "Linting tests passed. Proceeding with Playwright tests. ✅"
echo "status=$status" >> $GITHUB_ENV
- name: Linting failed
if: env.status == '1'
run: |
echo "One or more jobs in a previous workflow failed. Exiting."
exit 1
- name: Get last commit message
env:
GH_TOKEN: ${{ github.token }}
run: |
cd ${{ github.workspace }}/
PR_NUMBER=$(echo ${{ github.event.pull_request.number }})
COMMIT_MSG=$(gh pr view $PR_NUMBER --json commits --jq '.commits[-1] | "\(.messageHeadline) \(.messageBody)"')
# Remove newlines and carriage returns
CLEAN_COMMIT_MSG=$(echo "$COMMIT_MSG" | tr -d '\n' | tr -d '\r')
# Replace newlines and carriage returns with spaces
CLEAN_COMMIT_MSG=$(echo "$COMMIT_MSG" | tr '\n\r' ' ')
# Remove single quotes
CLEAN_COMMIT_MSG=$(echo "$CLEAN_COMMIT_MSG" | sed "s/'//g")
echo "Cleaned commit message: ${CLEAN_COMMIT_MSG}"
echo "COMMIT_MSG=${CLEAN_COMMIT_MSG}" >> $GITHUB_ENV
- name: Set up env variables
run: |
SITE_NAME="WordPress (Composer Managed) Single Site Test"
SITE_URL="https://dev-wpcm-playwright-tests.pantheonsite.io"
echo "Site name: $SITE_NAME"
echo "Site url: $SITE_URL"
echo "SITE_NAME=$SITE_NAME" >> $GITHUB_ENV
echo "SITE_URL=$SITE_URL" >> $GITHUB_ENV
- name: Install SSH keys
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Validate Pantheon Host Key
shell: bash
run: |
echo "Host *.drush.in HostKeyAlgorithms +ssh-rsa" >> ~/.ssh/config
echo "Host *.drush.in PubkeyAcceptedKeyTypes +ssh-rsa" >> ~/.ssh/config
echo "StrictHostKeyChecking no" >> ~/.ssh/config
- name: Get latest Terminus release
uses: pantheon-systems/terminus-github-actions@v1
with:
pantheon-machine-token: ${{ secrets.TERMINUS_TOKEN }}
- name: Install dependencies
run: |
echo "Install Composer dependencies"
composer update --no-progress --prefer-dist --optimize-autoloader
echo "Install NPM dependencies"
npm install
echo "Install Playwright Browsers"
npx playwright install --with-deps
- name: Setup Single Site Tests
env:
SITE_ID: wpcm-playwright-tests
SITE_NAME: ${{ env.SITE_NAME }}
SITE_URL: ${{ env.SITE_URL }}
TYPE: single
TERMINUS_TOKEN: ${{ secrets.TERMINUS_TOKEN }}
COMMIT_MSG: ${{ env.COMMIT_MSG }}
WORKSPACE: ${{ github.workspace }}
run: bash ${{ github.workspace }}/devops/scripts/setup-playwright-tests.sh
- name: Run Playwright tests
env:
SITE_NAME: ${{ env.SITE_NAME }}
SITE_URL: ${{ env.SITE_URL }}
run: npm run test .github/tests/wpcm.spec.ts
- name: Delete Site
if: success()
shell: bash
run: terminus site:delete wpcm-playwright-tests -y
playwright-subdir:
name: Subdirectory multisite
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Wait for status artifacts
env:
GH_TOKEN: ${{ github.token }}
run: |
max_attempts=10
delay_seconds=30
attempt=0
success=0
status=0
echo "Checking for status artifacts..."
while [ $attempt -lt $max_attempts ]; do
# Attempt to download the artifacts.
gh run download -n status-8.1-${{ github.sha }} || true
gh run download -n status-8.2-${{ github.sha }} || true
gh run download -n status-8.3-${{ github.sha }} || true
if [ -f status-8.1-${{ github.sha }}.txt ] && [ -f status-8.2-${{ github.sha }}.txt ] && [ -f status-8.3-${{ github.sha }}.txt ]; then
success=1
break
else
echo "Status files not found. Sleeping for $delay_seconds seconds..."
sleep $delay_seconds
fi
attempt=$(( attempt + 1 ))
done
if [ $success -eq 0 ]; then
echo "Timed out waiting for status artifacts."
exit 1
fi
for file in status-*.txt; do
status=$(cat $file)
if [ $status -eq 1 ]; then
echo "status=$status" >> $GITHUB_ENV
exit 1
fi
done
echo "status=$status" >> $GITHUB_ENV
- name: Linting failed
if: env.status == '1'
run: |
echo "One or more jobs in a previous workflow failed. Exiting."
exit 1
- name: Get last commit message
env:
GH_TOKEN: ${{ github.token }}
run: |
cd ${{ github.workspace }}/
PR_NUMBER=$(echo ${{ github.event.pull_request.number }})
COMMIT_MSG=$(gh pr view $PR_NUMBER --json commits --jq '.commits[-1] | "\(.messageHeadline) \(.messageBody)"')
# Remove newlines and carriage returns
CLEAN_COMMIT_MSG=$(echo "$COMMIT_MSG" | tr -d '\n' | tr -d '\r')
# Replace newlines and carriage returns with spaces
CLEAN_COMMIT_MSG=$(echo "$COMMIT_MSG" | tr '\n\r' ' ')
# Remove single quotes
CLEAN_COMMIT_MSG=$(echo "$CLEAN_COMMIT_MSG" | sed "s/'//g")
echo "Cleaned commit message: ${CLEAN_COMMIT_MSG}"
echo "COMMIT_MSG=${CLEAN_COMMIT_MSG}" >> $GITHUB_ENV
- name: Set up env variables
run: |
SITE_NAME="WordPress (Composer Managed) Subdirectory Multisite Test"
SITE_URL="https://dev-wpcm-subdir-playwright-tests.pantheonsite.io"
echo "Site name: $SITE_NAME"
echo "Site url: $SITE_URL"
echo "SITE_NAME=$SITE_NAME" >> $GITHUB_ENV
echo "SITE_URL=$SITE_URL" >> $GITHUB_ENV
- name: Install SSH keys
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Validate Pantheon Host Key
shell: bash
run: |
echo "Host *.drush.in HostKeyAlgorithms +ssh-rsa" >> ~/.ssh/config
echo "Host *.drush.in PubkeyAcceptedKeyTypes +ssh-rsa" >> ~/.ssh/config
echo "StrictHostKeyChecking no" >> ~/.ssh/config
- name: Get latest Terminus release
uses: pantheon-systems/terminus-github-actions@v1
with:
pantheon-machine-token: ${{ secrets.TERMINUS_TOKEN }}
- name: Install dependencies
run: |
echo "Install Composer dependencies"
composer update --no-progress --prefer-dist --optimize-autoloader
echo "Install NPM dependencies"
npm install
echo "Install Playwright Browsers"
npx playwright install --with-deps
- name: Setup Subdirectory Multisite Tests
env:
SITE_ID: wpcm-subdir-playwright-tests
SITE_NAME: ${{ env.SITE_NAME }}
SITE_URL: ${{ env.SITE_URL }}
TYPE: subdir
TERMINUS_TOKEN: ${{ secrets.TERMINUS_TOKEN }}
COMMIT_MSG: ${{ env.COMMIT_MSG }}
WORKSPACE: ${{ github.workspace }}
run: bash ${{ github.workspace }}/devops/scripts/setup-playwright-tests.sh
- name: Run Playwright tests
env:
SITE_NAME: ${{ env.SITE_NAME }}
SITE_URL: ${{ env.SITE_URL }}
run: |
npm run test .github/tests/wpcm.spec.ts
SITE_NAME=Foo
SITE_URL=${{ env.SITE_URL }}/foo
echo "Running Playwright tests on WordPress subdirectory subsite"
npm run test .github/tests/wpcm.spec.ts
- name: Delete Site
if: success()
shell: bash
run: terminus site:delete wpcm-subdir-playwright-tests -y
playwright-subdom:
name: Subdomain multisite
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Wait for status artifacts
env:
GH_TOKEN: ${{ github.token }}
run: |
max_attempts=10
delay_seconds=30
attempt=0
success=0
status=0
echo "Checking for status artifacts..."
while [ $attempt -lt $max_attempts ]; do
# Attempt to download the artifacts.
gh run download -n status-8.1-${{ github.sha }} || true
gh run download -n status-8.2-${{ github.sha }} || true
gh run download -n status-8.3-${{ github.sha }} || true
if [ -f status-8.1-${{ github.sha }}.txt ] && [ -f status-8.2-${{ github.sha }}.txt ] && [ -f status-8.3-${{ github.sha }}.txt ]; then
success=1
break
else
echo "Status files not found. Sleeping for $delay_seconds seconds..."
sleep $delay_seconds
fi
attempt=$(( attempt + 1 ))
done
if [ $success -eq 0 ]; then
echo "Timed out waiting for status artifacts."
exit 1
fi
for file in status-*.txt; do
status=$(cat $file)
if [ $status -eq 1 ]; then
echo "status=$status" >> $GITHUB_ENV
exit 1
fi
done
echo "status=$status" >> $GITHUB_ENV
- name: Linting failed
if: env.status == '1'
run: |
echo "One or more jobs in a previous workflow failed. Exiting."
exit 1
- name: Get last commit message
env:
GH_TOKEN: ${{ github.token }}
run: |
cd ${{ github.workspace }}/
PR_NUMBER=$(echo ${{ github.event.pull_request.number }})
COMMIT_MSG=$(gh pr view $PR_NUMBER --json commits --jq '.commits[-1] | "\(.messageHeadline) \(.messageBody)"')
# Remove newlines and carriage returns
CLEAN_COMMIT_MSG=$(echo "$COMMIT_MSG" | tr -d '\n' | tr -d '\r')
# Replace newlines and carriage returns with spaces
CLEAN_COMMIT_MSG=$(echo "$COMMIT_MSG" | tr '\n\r' ' ')
# Remove single quotes
CLEAN_COMMIT_MSG=$(echo "$CLEAN_COMMIT_MSG" | sed "s/'//g")
echo "Cleaned commit message: ${CLEAN_COMMIT_MSG}"
echo "COMMIT_MSG=${CLEAN_COMMIT_MSG}" >> $GITHUB_ENV
- name: Set up env variables
run: |
SITE_NAME="WordPress (Composer Managed) Subdomain Multisite Test"
SITE_URL="https://dev-wpcm-subdom-playwright-tests.pantheonsite.io"
SUBDOMAIN_URL="https://foo.dev-wpcm-subdom-playwright-tests.pantheonsite.io"
echo "Site name: $SITE_NAME"
echo "Site url: $SITE_URL"
echo "Subdomain url: $SUBDOMAIN_URL"
echo "SITE_NAME=$SITE_NAME" >> $GITHUB_ENV
echo "SITE_URL=$SITE_URL" >> $GITHUB_ENV
echo "SUBDOMAIN_URL=$SUBDOMAIN_URL" >> $GITHUB_ENV
echo "SITE_ID=wpcm-subdom-playwright-tests" >> $GITHUB_ENV
- name: Install SSH keys
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Validate Pantheon Host Key
shell: bash
run: |
echo "Host *.drush.in HostKeyAlgorithms +ssh-rsa" >> ~/.ssh/config
echo "Host *.drush.in PubkeyAcceptedKeyTypes +ssh-rsa" >> ~/.ssh/config
echo "StrictHostKeyChecking no" >> ~/.ssh/config
- name: Get latest Terminus release
uses: pantheon-systems/terminus-github-actions@v1
with:
pantheon-machine-token: ${{ secrets.TERMINUS_TOKEN }}
- name: Install dependencies
run: |
echo "Install Composer dependencies"
composer update --no-progress --prefer-dist --optimize-autoloader
echo "Install NPM dependencies"
npm install
echo "Install Playwright Browsers"
npx playwright install --with-deps
- name: Copy changes from PR
run: |
echo "Commit Message: ${{ env.COMMIT_MSG }}"
echo "Setting up some git config..."
git config --global user.email "[email protected]"
git config --global user.name "Pantheon WPCM Bot"
echo "Switching to git mode..."
terminus connection:set "${{ env.SITE_ID }}".dev git
echo "Clone the site locally and copy PR updates"
terminus local:clone ${{ env.SITE_ID }}
cd ~/pantheon-local-copies/"${{ env.SITE_ID }}"
echo "Copying latest changes and committing to the site."
rsync -a --exclude='.git' --exclude='status-*.txt' --exclude="node_modules" "${{ github.workspace }}/" .
git add -A
git commit -m "Update to latest commit: ${{ env.COMMIT_MSG }}" || true
git push origin master || true
# Wait for the git push to finish.
terminus workflow:wait "${{ env.SITE_ID }}".dev
echo "Checking WordPress install status"
terminus wp "${{ env.SITE_ID }}".dev -- cli info
# Run curl checks against the site URLs to ensure the main site and the subdomain site exist.
echo "Checking site URLs"
SITE_URL_TEST=$(curl -s -o /dev/null -w "%{http_code}" ${{ env.SITE_URL }})
SUBDOMAIN_URL_TEST=$(curl -s -o /dev/null -w "%{http_code}" ${{ env.SUBDOMAIN_URL }})
if [ $SITE_URL_TEST -ne 200 ] || [ $SUBDOMAIN_URL_TEST -ne 200 ]; then
echo "One or more site URLs are not returning a 200 status code. Exiting."
exit 1
fi
- name: Run Playwright tests
env:
SITE_NAME: ${{ env.SITE_NAME }}
SITE_URL: ${{ env.SITE_URL }}
run: |
npm run test .github/tests/wpcm.spec.ts
SITE_NAME=Foo
SITE_URL=${{ env.SUBDOMAIN_URL }}
echo "Running Playwright tests on WordPress Subdomain subsite"
npm run test .github/tests/wpcm.spec.ts