-
Notifications
You must be signed in to change notification settings - Fork 12
556 lines (467 loc) · 20.7 KB
/
pull_request_examples.yml
File metadata and controls
556 lines (467 loc) · 20.7 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
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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
name: CI - Examples
on:
pull_request:
branches:
- main
- develop
paths:
- .github/workflows/pull_request_examples.yml
- examples/**
- packages/**
push:
branches:
- main
- develop
paths:
- .github/workflows/pull_request_examples.yml
- examples/**
- packages/**
# TODO: Remove and replace with real matrix.
workflow_dispatch:
inputs:
NODE_VERSIONS:
description: 'Node versions to test against. Need a JSON array of versions.'
required: true
default: '[22]'
type: string
permissions:
contents: read
pull-requests: read
env:
NODE_VERSIONS: '[22]'
PATHS: |
nextjs/starter:
- .github/workflows/pull_request_examples.yml
- examples/nextjs/starter/**
- packages/**
GRAPHQL_SCHEMA_FILE: '${{ github.workspace }}/schema.graphql'
SNAPWP_HELPER_REF: 'develop' # TODO: Get from PR description.
jobs:
path-filter:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Filter paths
id: filter
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36
with:
filters: ${{ env.PATHS }}
outputs:
# TODO: the example shouldn't be hardcoded
changes: ${{ github.event_name == 'workflow_dispatch' && '["nextjs/starter"]' || steps.filter.outputs.changes }}
generate_schema:
name: Generate WPGraphQL schema
uses: './.github/workflows/generate-schema.yml'
with:
# TODO: Get from PR description.
ref: 'develop'
secrets: inherit
eslint:
name: ESLint
runs-on: ubuntu-latest
needs:
- path-filter
- generate_schema
if: ${{ needs.path-filter.outputs.changes != '' && toJSON(fromJSON(needs.path-filter.outputs.changes)) != '[]' }}
strategy:
matrix:
example: ${{ fromJSON(needs.path-filter.outputs.changes) }}
fail-fast: true
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version-file: '.nvmrc'
- name: Get generated schema
uses: actions/download-artifact@v8
with:
name: schema
path: /tmp/schema
- name: Move schema to workspace
run: |
cp /tmp/schema/schema.graphql ${{ github.workspace }}/schema.graphql
- name: Build local packages
run: |
cd '${{ github.workspace }}'
npm ci --workspaces --include-workspace-root
npm run --if-present local-registry:start
npm run --if-present build
# Ensure Verdaccio has the right permissions for CI
touch .verdaccio/conf/htpasswd
sudo chmod 666 .verdaccio/conf/htpasswd # Required so verdaccio container can add our user
mkdir -p .verdaccio/storage/
sudo chmod 777 .verdaccio/storage/
sudo chmod 777 .verdaccio/
npm run --if-present publish:local
# Create test app directory outside of workspace
mkdir -p ${{ runner.temp }}/snapwp-test-app
- name: Scaffold ${{ matrix.example }} App
working-directory: ${{ runner.temp }}/snapwp-test-app
run: |
cp '${{ github.workspace }}/examples/${{ matrix.example }}/.env.example' .env
sed -i 's|NEXT_PUBLIC_WP_HOME_URL=.*|NEXT_PUBLIC_WP_HOME_URL=http://localhost|' .env
# We use a local install because npm link is flaky in CI.
# @see https://github.com/rtCamp/snapwp/pull/
npm i '${{ github.workspace }}/packages/cli' --no-save
npx snapwp --proxy <<< '.'
npm i
- name: Run ESLint
working-directory: ${{ runner.temp }}/snapwp-test-app
run: npm run --if-present lint
- name: Clean up
if: always()
continue-on-error: true
run: |
cd '${{ github.workspace }}'
npm run --if-present local-registry:stop
rm -rf ${{ runner.temp }}/snapwp-test-app
typecheck:
name: TS Typecheck
runs-on: ubuntu-latest
needs:
- path-filter
- generate_schema
if: ${{ needs.path-filter.outputs.changes != '' && toJSON(fromJSON(needs.path-filter.outputs.changes)) != '[]' }}
strategy:
matrix:
example: ${{ fromJSON(needs.path-filter.outputs.changes) }}
fail-fast: true
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version-file: '.nvmrc'
- name: Get generated schema
uses: actions/download-artifact@v8
with:
name: schema
path: /tmp/schema
- name: Move schema to workspace
run: |
cp /tmp/schema/schema.graphql ${{ github.workspace }}/schema.graphql
- name: Build local packages
run: |
cd '${{ github.workspace }}'
npm ci --workspaces --include-workspace-root
npm run --if-present local-registry:start
npm run --if-present build
# Ensure Verdaccio has the right permissions for CI
touch .verdaccio/conf/htpasswd
sudo chmod 666 .verdaccio/conf/htpasswd # Required so verdaccio container can add our user
mkdir -p .verdaccio/storage/
sudo chmod 777 .verdaccio/storage/
sudo chmod 777 .verdaccio/
npm run --if-present publish:local
# Create test app directory outside of workspace
mkdir -p ${{ runner.temp }}/snapwp-test-app
- name: Scaffold ${{ matrix.example }} App
working-directory: ${{ runner.temp }}/snapwp-test-app
run: |
cp '${{ github.workspace }}/examples/${{ matrix.example }}/.env.example' .env
sed -i 's|NEXT_PUBLIC_WP_HOME_URL=.*|NEXT_PUBLIC_WP_HOME_URL=http://localhost|' .env
# We use a local install because npm link is flaky in CI.
# @see https://github.com/rtCamp/snapwp/pull/
npm i '${{ github.workspace }}/packages/cli' --no-save
npx snapwp --proxy <<< '.'
npm i
- name: Run Codegen
working-directory: ${{ runner.temp }}/snapwp-test-app
run: npm run codegen
- name: Run TypeScript type check
# TODO: Why are we catching the error?
working-directory: ${{ runner.temp }}/snapwp-test-app
run: npm run --if-present typecheck
- name: Clean up
if: always()
continue-on-error: true
run: |
cd '${{ github.workspace }}'
npm run --if-present local-registry:stop
rm -rf ${{ runner.temp }}/snapwp-test-app
test-build:
name: Test Build (Node v${{ matrix.node-version }} | ${{ matrix.example }})
runs-on: ubuntu-latest
needs:
- path-filter
- generate_schema
if: ${{ needs.path-filter.outputs.changes != '' && toJSON(fromJSON(needs.path-filter.outputs.changes)) != '[]' }}
strategy:
matrix:
node-version: ${{ fromJSON('[22]') }}
example: ${{ fromJSON(needs.path-filter.outputs.changes) }}
fail-fast: true
services:
mariadb:
image: mariadb:10
ports:
- 3306:3306
env:
MYSQL_ROOT_PASSWORD: password
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Checkout SnapWP Helper
uses: actions/checkout@v6
with:
token: '${{ secrets.GITHUB_TOKEN }}'
repository: 'rtcamp/snapwp-helper'
path: snapwp-helper
ref: ${{ env.SNAPWP_HELPER_REF }}
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
- name: Setup PHP
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # 2.36.0
with:
php-version: '8.2'
extensions: mbstring, intl
coverage: none
tools: composer, wp-cli
- name: Get generated schema
uses: actions/download-artifact@v8
with:
name: schema
path: /tmp/schema
- name: Move schema to workspace
run: |
cp /tmp/schema/schema.graphql ${{ github.workspace }}/schema.graphql
- name: Install Composer deps for SnapWP Helper
uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # 3.1.1
with:
working-directory: '${{ github.workspace }}/snapwp-helper'
composer-options: '--no-progress'
- name: Setup WordPress Test Environment
run: |
cd '${{ github.workspace }}/snapwp-helper'
cp .env.dist .env; set -a; source .env; set +a
npm run install-test-env
cd $WORDPRESS_ROOT_DIR
sudo php -S localhost:80 -t "${WORDPRESS_ROOT_DIR}" &
sleep 3
curl -IL http://localhost # Verify that the server is running; will fail and exit workflow if not
- name: Build local packages
run: |
cd '${{ github.workspace }}'
npm ci --workspaces --include-workspace-root
npm run --if-present local-registry:start
npm run --if-present build
# Ensure Verdaccio has the right permissions for CI
touch .verdaccio/conf/htpasswd
sudo chmod 666 .verdaccio/conf/htpasswd # Required so verdaccio container can add our user
mkdir -p .verdaccio/storage/
sudo chmod 777 .verdaccio/storage/
sudo chmod 777 .verdaccio/
npm run --if-present publish:local
# Create test app directory outside of workspace
mkdir -p ${{ runner.temp }}/snapwp-test-app
- name: Scaffold ${{ matrix.example }} App
working-directory: ${{ runner.temp }}/snapwp-test-app
run: |
cp '${{ github.workspace }}/examples/${{ matrix.example }}/.env.example' .env
sed -i 's|NEXT_PUBLIC_WP_HOME_URL=.*|NEXT_PUBLIC_WP_HOME_URL=http://localhost|' .env
# We use a local install because npm link is flaky in CI.
# @see https://github.com/rtCamp/snapwp/pull/
npm i '${{ github.workspace }}/packages/cli' --no-save
npx snapwp --proxy <<< '.'
npm i
- name: Build assets
working-directory: ${{ runner.temp }}/snapwp-test-app
run: npm run --if-present build
- name: Clean up
if: always()
continue-on-error: true
run: |
cd '${{ github.workspace }}'
npm run --if-present local-registry:stop
rm -rf ${{ runner.temp }}/snapwp-test-app
unit:
name: Unit Tests (Node v${{ matrix.node-version }} | ${{ matrix.example }})
runs-on: ubuntu-latest
needs:
- path-filter
- generate_schema
if: ${{ needs.path-filter.outputs.changes != '' && toJSON(fromJSON(needs.path-filter.outputs.changes)) != '[]' }}
strategy:
matrix:
node-version: ${{ fromJSON('[22]') }}
example: ${{ fromJSON(needs.path-filter.outputs.changes) }}
fail-fast: true
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
- name: Get generated schema
uses: actions/download-artifact@v8
with:
name: schema
path: /tmp/schema
- name: Move schema to workspace
run: |
cp /tmp/schema/schema.graphql ${{ github.workspace }}/schema.graphql
- name: Build local packages
run: |
cd '${{ github.workspace }}'
npm ci --workspaces --include-workspace-root
npm run --if-present local-registry:start
npm run --if-present build
# Ensure Verdaccio has the right permissions for CI
touch .verdaccio/conf/htpasswd
sudo chmod 666 .verdaccio/conf/htpasswd # Required so verdaccio container can add our user
mkdir -p .verdaccio/storage/
sudo chmod 777 .verdaccio/storage/
sudo chmod 777 .verdaccio/
npm run --if-present publish:local
# Create test app directory outside of workspace
mkdir -p ${{ runner.temp }}/snapwp-test-app
- name: Scaffold ${{ matrix.example }} App
working-directory: ${{ runner.temp }}/snapwp-test-app
run: |
cp '${{ github.workspace }}/examples/${{ matrix.example }}/.env.example' .env
sed -i 's|NEXT_PUBLIC_WP_HOME_URL=.*|NEXT_PUBLIC_WP_HOME_URL=http://localhost|' .env
# We use a local install because npm link is flaky in CI.
# @see https://github.com/rtCamp/snapwp/pull/
npm i '${{ github.workspace }}/packages/cli' --no-save
npx snapwp --proxy <<< '.'
npm i
- name: Run unit tests
working-directory: ${{ runner.temp }}/snapwp-test-app
run: npm run --if-present test
- name: Clean up
if: always()
continue-on-error: true
run: |
cd '${{ github.workspace }}'
npm run --if-present local-registry:stop
rm -rf ${{ runner.temp }}/snapwp-test-app
security:
name: Dependencies Audit
runs-on: ubuntu-latest
needs:
- path-filter
- generate_schema
if: ${{ needs.path-filter.outputs.changes != '' && toJSON(fromJSON(needs.path-filter.outputs.changes)) != '[]' }}
strategy:
matrix:
example: ${{ fromJSON(needs.path-filter.outputs.changes) }}
fail-fast: true
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version-file: '.nvmrc'
- name: Get generated schema
uses: actions/download-artifact@v8
with:
name: schema
path: /tmp/schema
- name: Move schema to workspace
run: |
cp /tmp/schema/schema.graphql ${{ github.workspace }}/schema.graphql
- name: Build local packages
run: |
cd '${{ github.workspace }}'
npm ci --workspaces --include-workspace-root
npm run --if-present local-registry:start
npm run --if-present build
# Ensure Verdaccio has the right permissions for CI
touch .verdaccio/conf/htpasswd
sudo chmod 666 .verdaccio/conf/htpasswd # Required so verdaccio container can add our user
mkdir -p .verdaccio/storage/
sudo chmod 777 .verdaccio/storage/
sudo chmod 777 .verdaccio/
npm run --if-present publish:local
# Create test app directory outside of workspace
mkdir -p ${{ runner.temp }}/snapwp-test-app
- name: Scaffold ${{ matrix.example }} App
working-directory: ${{ runner.temp }}/snapwp-test-app
run: |
cp '${{ github.workspace }}/examples/${{ matrix.example }}/.env.example' .env
sed -i 's|NEXT_PUBLIC_WP_HOME_URL=.*|NEXT_PUBLIC_WP_HOME_URL=http://localhost|' .env
# We use a local install because npm link is flaky in CI.
# @see https://github.com/rtCamp/snapwp/pull/
npm i '${{ github.workspace }}/packages/cli' --no-save
npx snapwp --proxy <<< '.'
npm i
- name: Run npm audit
working-directory: ${{ runner.temp }}/snapwp-test-app
run: npm audit --audit-level=high
- name: Clean up
if: always()
continue-on-error: true
run: |
cd '${{ github.workspace }}'
npm run --if-present local-registry:stop
rm -rf ${{ runner.temp }}/snapwp-test-app
prettier:
name: Check Formatting
runs-on: ubuntu-latest
needs:
- path-filter
- generate_schema
if: ${{ needs.path-filter.outputs.changes != '' && toJSON(fromJSON(needs.path-filter.outputs.changes)) != '[]' }}
strategy:
matrix:
example: ${{ fromJSON(needs.path-filter.outputs.changes) }}
fail-fast: true
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version-file: '.nvmrc'
- name: Get generated schema
uses: actions/download-artifact@v8
with:
name: schema
path: /tmp/schema
- name: Move schema to workspace
run: |
cp /tmp/schema/schema.graphql ${{ github.workspace }}/schema.graphql
- name: Build local packages
run: |
cd '${{ github.workspace }}'
npm ci --workspaces --include-workspace-root
npm run --if-present local-registry:start
npm run --if-present build
# Ensure Verdaccio has the right permissions for CI
touch .verdaccio/conf/htpasswd
sudo chmod 666 .verdaccio/conf/htpasswd # Required so verdaccio container can add our user
mkdir -p .verdaccio/storage/
sudo chmod 777 .verdaccio/storage/
sudo chmod 777 .verdaccio/
npm run --if-present publish:local
# Create test app directory outside of workspace
mkdir -p ${{ runner.temp }}/snapwp-test-app
- name: Scaffold ${{ matrix.example }} App
working-directory: ${{ runner.temp }}/snapwp-test-app
run: |
cp '${{ github.workspace }}/examples/${{ matrix.example }}/.env.example' .env
sed -i 's|NEXT_PUBLIC_WP_HOME_URL=.*|NEXT_PUBLIC_WP_HOME_URL=http://localhost|' .env
# We use a local install because npm link is flaky in CI.
# @see https://github.com/rtCamp/snapwp/pull/
npm i '${{ github.workspace }}/packages/cli' --no-save
npx snapwp --proxy <<< '.'
npm i
- name: Run Prettier
working-directory: ${{ runner.temp }}/snapwp-test-app
run: npm run --if-present format-check
- name: Clean up
if: always()
continue-on-error: true
run: |
cd '${{ github.workspace }}'
npm run --if-present local-registry:stop
rm -rf ${{ runner.temp }}/snapwp-test-app