-
Notifications
You must be signed in to change notification settings - Fork 4
466 lines (396 loc) · 16.5 KB
/
perform-lints.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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
name: Lint & Test
on:
push:
branches:
- develop
- main
pull_request:
branches:
- develop
- main
workflow_dispatch:
permissions:
contents: read
# Cancel previous workflow run groups that have not completed.
concurrency:
# Group workflow runs by workflow name, along with the head branch ref of the pull request
# or otherwise the branch or tag ref.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
pre-run:
name: 'Pre run'
runs-on: ubuntu-latest
outputs:
changed-php: ${{ steps.changed-files.outputs.php_any_changed }}
changed-js: ${{ steps.changed-files.outputs.js_any_changed }}
changed-workflow: ${{ steps.changed-files.outputs.gha-workflow_any_changed }}
steps:
- name: Checkout including last 2 commits
# Fetch last 2 commits if it's not a PR, so that we can determine the list of modified files.
if: ${{ github.base_ref == null }}
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Checkout
# Do usual checkout if it's a PR.
if: ${{ github.base_ref != null }}
uses: actions/checkout@v4
- name: Fetch base branch
# Only fetch base ref if it's a PR.
if: ${{ github.base_ref != null }}
run: git fetch --depth=1 --no-tags origin ${{ github.base_ref }}
- name: Determine modified files for PR
id: changed-files
uses: tj-actions/changed-files@v44
with:
# We are only interested in PHP, JS, and workflow files.
files_yaml: |
php:
- '**.php'
- 'composer.json'
- 'composer.lock'
gha-workflow:
- '**.yml'
- '**.yaml'
js:
- '**.js'
- '**.jsx'
- '**.ts'
- '**.tsx'
- 'package.json'
- 'package-lock.json'
- name: List all PHP changed files
if: steps.changed-files.outputs.php_any_changed == 'true'
env:
PHP_CHANGED_FILES: ${{ steps.changed-files.outputs.php_all_changed_files }}
run: |
for file in "$PHP_CHANGED_FILES"; do
echo "$file was changed"
done
- name: List all JS changed files
if: steps.changed-files.outputs.js_any_changed == 'true'
env:
JS_CHANGED_FILES: ${{ steps.changed-files.outputs.js_all_changed_files }}
run: |
for file in "$JS_CHANGED_FILES"; do
echo "$file was changed"
done
- name: List all Workflow changed files
if: steps.changed-files.outputs.gha-workflow_any_changed == 'true'
env:
GHA_CHANGED_FILES: ${{ steps.changed-files.outputs.gha-workflow_all_changed_files }}
run: |
for file in "$GHA_CHANGED_FILES"; do
echo "$file was changed"
done
phpcs:
needs: pre-run
if: needs.pre-run.outputs.changed-php == 'true' || needs.pre-run.outputs.changed-workflow == 'true'
name: PHP Coding Standards
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
coverage: none
tools: composer
# Install/cache composer dependencies
- name: Install dependencies
uses: ramsey/composer-install@v3
with:
composer-options: '--no-progress'
- name: Run PHP_CodeSniffer
run: composer run-script phpcs -- --report-full --report-checkstyle=./phpcs-report.xml
phpstan:
needs: pre-run
if: needs.pre-run.outputs.changed-php == 'true' || needs.pre-run.outputs.changed-workflow == 'true'
name: 'PHP Static Analysis'
runs-on: ubuntu-latest
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@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: mbstring, intl
coverage: none
tools: composer, wp-cli
# Install/cache composer dependencies
- name: Install dependencies
uses: ramsey/composer-install@v3
with:
composer-options: '--no-progress'
- name: Setup WordPress
run: |
cp .env.dist .env
npm run install-test-env
- name: Run PHPStan
working-directory: /tmp/wordpress/wp-content/plugins/snapwp-helper
run: composer run-script phpstan -- --error-format=github
lint-js:
name: 'Lint: JS'
needs: pre-run
if: needs.pre-run.outputs.changed-workflow == 'true' || needs.pre-run.outputs.changed-js == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Node.js dependencies
run: npm ci
env:
CI: true
- name: Run ESLint
run: npm run lint:js
codeception:
needs: pre-run
if: needs.pre-run.outputs.changed-php == 'true' || needs.pre-run.outputs.changed-workflow == 'true'
name: 'Tests - Codeception | PHP: ${{ matrix.php }} WP: ${{ matrix.wordpress }}'
runs-on: ubuntu-latest
strategy:
matrix:
php: ['8.2', '8.1']
wordpress: ['6.7'] # @todo support older versions
include:
- php: '8.2'
wordpress: '6.7'
coverage: 1
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: json, mbstring
tools: composer:v2
# Install/cache composer dependencies
- name: Install dependencies
uses: ramsey/composer-install@v3
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Node.js dependencies
run: npm ci
env:
CI: true
- name: Build JS assets
run: npm run build:js
- name: Copy .env file
run: cp .docker/.env.ci .env
- name: Start test environment
run: |
npm run docker:start
docker exec -e COVERAGE=${COVERAGE:-} $(docker compose ps -q wordpress) init-docker.sh
env:
WP_VERSION: ${{ matrix.wordpress }}
PHP_VERSION: ${{ matrix.php }}
COVERAGE: ${{ matrix.coverage }}
- name: Run acceptance tests
run: bash ./bin/run-codeception.sh
env:
WP_VERSION: ${{ matrix.wordpress }}
PHP_VERSION: ${{ matrix.php }}
DEBUG: ${{ secrets.ACTIONS_STEP_DEBUG || matrix.debug }}
SUITES: 'Acceptance'
- name: Run integration tests
working-directory: ${{ env.PROJECT_URI }}
run: bash ./bin/run-codeception.sh
env:
WP_VERSION: ${{ matrix.wordpress }}
PHP_VERSION: ${{ matrix.php }}
COVERAGE: ${{ matrix.coverage }}
DEBUG: ${{ secrets.ACTIONS_STEP_DEBUG || matrix.debug }}
SUITES: 'Integration'
- name: Push coverage to Coveralls.io
if: matrix.coverage == 1
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: tests/_output/Integration-coverage.xml
flag-name: Integration
format: clover
- name: Push coverage to CodeClimate
if: matrix.coverage == 1
uses: paambaati/codeclimate-action@v9
env:
CC_TEST_REPORTER_ID: ${{ secrets.CODECLIMATE_REPORTER_ID }}
with:
coverageLocations: |
${{github.workspace}}/tests/_output/Integration-coverage.xml:clover
prefix: '/var/www/html/wp-content/plugins/snapwp-helper'
playwright:
needs: pre-run
if: needs.pre-run.outputs.changed-workflow == 'true' || needs.pre-run.outputs.changed-js == 'true'
name: 'E2E - Playwright'
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
coverage: none
tools: composer
- name: Install Composer dependencies
uses: ramsey/composer-install@v3
with:
composer-options: '--no-progress'
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Node.js dependencies
run: npm ci
env:
CI: true
- name: Build assets
run: npm run build:dist
- name: Install Playwright dependencies
run: npx playwright install --with-deps
- name: Start wp-env
run: |
npm run wp-env -- start
sleep 10
netstat -nltp
curl -iL http://localhost:8889
- name: Run E2E tests
run: npm run test:e2e
- name: Upload tests artifacts
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: artifact
path: tests/_output/artifacts
retention-days: 7
if-no-files-found: error # 'warn' or 'ignore' are also available, defaults to `warn`
- name: Stop wp-env
if: ${{ always() }}
working-directory: ${{ env.PROJECT_URI }}
run: |
npm run wp-env -- stop || true
npm run wp-env -- destroy <<< 'y' || true # this doesn't have a flag to skip prompt
graphql-schema:
needs: pre-run
if: needs.pre-run.outputs.changed-php == 'true' || needs.pre-run.outputs.changed-workflow == 'true'
name: 'Lint WPGraphQL Schema'
runs-on: ubuntu-latest
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@v4
- name: Setup PHP w/ Composer & WP-CLI
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: mbstring, intl, bcmath, exif, gd, mysqli, opcache, zip, pdo_mysql
coverage: none
tools: composer:v2, wp-cli
- name: Install Composer dependencies
uses: ramsey/composer-install@v3
with:
composer-options: '--no-progress'
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Setup GraphQL Schema Linter
run: npm install -g graphql-schema-linter@^3.0 graphql@^16
- name: Install Node.js dependencies
run: npm ci
env:
CI: true
- name: Build JS assets
run: npm run build:js
- name: Setup WordPress
run: |
cp .env.dist .env
npm run install-test-env
- name: Generate the Static Schema
run: |
cd /tmp/wordpress/
# Output: /tmp/schema.graphql
wp graphql generate-static-schema --allow-root
- name: Lint the Schema
run: |
graphql-schema-linter --except=relay-connection-types-spec,relay-page-info-spec --ignore '{"defined-types-are-used":["MenuItemsWhereArgs","PostObjectUnion","TermObjectUnion","TimezoneEnum"]}' /tmp/schema.graphql
- name: Display ignored linting errors
run: |
graphql-schema-linter /tmp/schema.graphql || true
- name: Get Latest tag
uses: actions-ecosystem/action-get-latest-tag@v1
id: get-latest-tag
- name: Test Schema for breaking changes
run: |
echo "Previous tagged schema ${{ steps.get-latest-tag.outputs.tag }}"
- name: Get Previous Released Schema
run: |
FILE_NAME="schema.graphql"
GH_API="https://api.github.com"
GH_REPO="$GH_API/repos/$GITHUB_REPOSITORY"
GH_TAG="$GH_REPO/releases/tags/${{ steps.get-latest-tag.outputs.tag }}"
AUTH="Authorization: token $GITHUB_TOKEN"
response=$(curl -sH "$AUTH" $GH_TAG)
# Get ID of the asset based on given FILE_NAME.
id=$(echo "$response" | jq --arg name "$FILE_NAME" '.assets[] | select(.name == $name).id')
[ "$id" ] || { echo "Error: Failed to find ID for $FILE_NAME"; exit 1; }
GH_ASSET_URL="$GH_REPO/releases/assets/$id"
echo "Fetching schema from: $GH_ASSET_URL"
STATUS_CODE=$(
curl -H "$AUTH" \
-H 'Accept: application/octet-stream' \
-L -o /tmp/${{ steps.get-latest-tag.outputs.tag }}.graphql \
-w "%{http_code}" \
"$GH_ASSET_URL"
)
if [ "$STATUS_CODE" -ne 200 ]; then
echo "Failed to fetch schema. HTTP Status Code: $STATUS_CODE"
cat /tmp/${{ steps.get-latest-tag.outputs.tag }}.graphql
exit 1
fi
# Additional debug info
if [ ! -f /tmp/${{ steps.get-latest-tag.outputs.tag }}.graphql ]; then
echo "File not found!"
exit 1
else
echo "File exists."
fi
echo "Previous schema:"
cat /tmp/${{ steps.get-latest-tag.outputs.tag }}.graphql
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# https://github.com/marketplace/actions/graphql-inspector
- name: Install Schema Inspector
run: |
npm install @graphql-inspector/config @graphql-inspector/cli
- name: Run Schema Inspector
run: |
# This schema and previous release schema
node_modules/.bin/graphql-inspector diff /tmp/${{ steps.get-latest-tag.outputs.tag }}.graphql /tmp/schema.graphql