-
Notifications
You must be signed in to change notification settings - Fork 800
485 lines (415 loc) · 18.4 KB
/
linting.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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
# This workflow holds jobs for linting, currently PHP and JavaScript.
#
# The jobs are all set up to only run if appropriate files have changed; the
# `changed_files` job is used to determine whether files have changed in
# various categories so the rest of the jobs can know whether to run or not.
name: Linting
on: pull_request
concurrency:
group: linting-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true
env:
COMPOSER_ROOT_VERSION: "dev-trunk"
jobs:
### Job to categorize changed files. Other jobs depend on this to know when they should run.
changed_files:
name: detect changed files
runs-on: ubuntu-latest
timeout-minutes: 1 # 2021-01-18: Successful runs seem to take a few seconds
outputs:
# Whether any PHP files have changed.
php: ${{ steps.filter.outputs.php }}
# Whether any JavaScript files have changed.
js: ${{ steps.filter.outputs.js }}
# Whether any lock files have changed.
lockfiles: ${{ steps.filter.outputs.lockfiles }}
# Whether any GitHub Actions yaml files have changed.
ghactionsfiles: ${{ steps.filter.outputs.ghactionsfiles }}
# Whether any miscellaneous files related to linting have changed.
misc: ${{ steps.filter.outputs.misc }}
# Whether any miscellaneous files related to PHP linting have changed.
misc_php: ${{ steps.filter.outputs.misc == 'true' || steps.filter.outputs.misc_php == 'true' }}
# Whether any miscellaneous files related to JS linting have changed.
misc_js: ${{ steps.filter.outputs.misc == 'true' || steps.filter.outputs.misc_js == 'true' }}
# JSON string holding an array of files in phpcs-excludelist.json that have changed.
php_excluded_files: ${{ steps.filterPHP.outputs.php_excluded_files }}
# JSON string holding an array of files in eslint-excludelist.json that have changed.
js_excluded_files: ${{ steps.filterJS.outputs.js_excluded_files }}
# Whether any excluded files were modified or deleted.
excludelist: ${{ steps.filterExcludeList.outputs.excluded_files != '[]' || steps.filter.outputs.misc == 'true' || steps.filter.outputs.misc_php == 'true' || steps.filter.outputs.misc_js == 'true' || steps.filter.outputs.misc_excludelist == 'true' }}
steps:
- uses: actions/checkout@v3
- uses: dorny/paths-filter@v2
id: filter
with:
list-files: json
filters: |
php:
# If any PHP file changed, they need checking.
- added|modified:
- '**.php'
js:
# If any JS file changed, they need checking.
- added|modified:
- '**.cjs'
- '**.js'
- '**.jsx'
- '**.mjs'
- '**.ts'
- '**.tsx'
- '**.svelte'
excludelist:
# If any PHP or JS file changed or was deleted, we need to check the excludelist.
- modified|deleted:
- '**.php'
- '**.js'
- '**.jsx'
- '**.ts'
lockfiles:
- 'composer.json'
- 'composer.lock'
- 'package.json'
- 'pnpm-lock.yaml'
- '**/composer.json'
- '**/composer.lock'
- '**/package.json'
ghactionsfiles:
- '.github/workflows/*.{yml,yaml}'
- '.github/actions/*/action.{yml,yaml}'
- 'projects/github-actions/*/action.{yml,yaml}'
misc_php:
# If composer, phpcs config, or the codesniffer package itself changed, there may be a new standard.
- 'composer.json'
- 'composer.lock'
- '.phpcs.config.xml'
- '.phpcs.xml.dist'
- '.phpcsignore'
- '**/.phpcs.dir.xml'
- '**/.phpcsignore'
- 'projects/packages/codesniffer/**'
# If the excludelist changed, run to ensure newly non-excluded files pass.
- 'tools/phpcs-excludelist.json'
# If other files used by this workflow changed, run it to test those changes.
- 'tools/parallel-lint.sh'
- '.github/files/php-linting-phpcs.xml'
- '.github/matchers/phpcs-problem-matcher.json'
- '.github/matchers/php-lint-problem-matcher.json'
misc_js:
# If package or eslint config changed, there may be new checks.
- 'package.json'
- 'tools/js-tools/package.json'
- 'pnpm-lock.yaml'
- '.eslintignore'
- '.eslintignore.root'
- '.eslintrc.*'
- '**/.eslintignore'
- '**/.eslintrc.*'
# If the excludelist changed, run to ensure newly non-excluded files pass.
- 'tools/eslint-excludelist.json'
misc_excludelist:
- 'tools/cleanup-excludelists.sh'
- 'tools/js-tools/check-excludelist-diff.js'
misc:
# If the workflow itself changed, everything should re-run.
- '.github/workflows/linting.yml'
- id: filterPHP
shell: bash
env:
PHP_FILES: ${{ steps.filter.outputs.php_files }}
run: |
EXCLUDED_FILES=$(jq --argjson files "$PHP_FILES" --slurpfile excludes tools/phpcs-excludelist.json -nc '$files - ($files - $excludes[0])')
echo "php_excluded_files=$EXCLUDED_FILES" >> "$GITHUB_OUTPUT"
echo "Excluded files:"
jq --argjson files "$EXCLUDED_FILES" -nr '" - " + $files[]'
- id: filterJS
shell: bash
env:
JS_FILES: ${{ steps.filter.outputs.js_files }}
run: |
EXCLUDED_FILES=$(jq --argjson files "$JS_FILES" --slurpfile excludes tools/eslint-excludelist.json -nc '$files - ($files - $excludes[0])')
echo "js_excluded_files=$EXCLUDED_FILES" >> "$GITHUB_OUTPUT"
echo "Excluded files:"
jq --argjson files "$EXCLUDED_FILES" -nr '" - " + $files[]'
- id: filterExcludeList
shell: bash
env:
FILES: ${{ steps.filter.outputs.excludelist_files }}
run: |
EXCLUDED_FILES=$(jq --argjson files "$FILES" --slurpfile phpexcludes tools/phpcs-excludelist.json --slurpfile jsexcludes tools/eslint-excludelist.json -nc '$files - ($files - $phpexcludes[0] - $jsexcludes[0])')
echo "excluded_files=$EXCLUDED_FILES" >> "$GITHUB_OUTPUT"
echo "Excluded files:"
jq --argjson files "$EXCLUDED_FILES" -nr '" - " + $files[]'
### Runs `php -l` over all PHP files, in all relevant PHP versions
# Local equivalent: `composer php:lint`
php_lint:
name: PHP lint (${{ matrix.php-versions }})
runs-on: ubuntu-latest
needs: changed_files
continue-on-error: ${{ matrix.experimental }}
timeout-minutes: 3 # 2021-01-18: Successful runs seem to take ~1 minute
strategy:
fail-fast: false
matrix:
php-versions: [ '7.0', '7.2', '7.4', '8.0', '8.1', '8.2' ]
experimental: [ false ]
steps:
- uses: actions/checkout@v3
- name: Setup tools
uses: ./.github/actions/tool-setup
with:
php: ${{ matrix.php-versions }}
node: false
- name: Install dependencies
run: |
# Install stuff ignoring platform reqs.
composer install --ignore-platform-reqs
# Remove stuff we don't need here that fails some platform reqs.
# This will complain if we missed any.
composer remove --dev sirbrillig/phpcs-changed automattic/jetpack-codesniffer
- name: Run linter
run: |
echo "::add-matcher::.github/matchers/php-lint-problem-matcher.json"
composer php:lint -- --checkstyle
echo "::remove-matcher owner=php-lint"
### Runs phpcs on all PHP files not listed in phpcs-excludelist.json.
# Local equivalent: `composer phpcs:lint:required`
phpcs:
name: PHP Code Sniffer (non-excluded files only)
runs-on: ubuntu-latest
needs: changed_files
if: needs.changed_files.outputs.php == 'true' || needs.changed_files.outputs.misc_php == 'true'
timeout-minutes: 5 # 2021-01-18: Successful runs seem to take ~1 minute. Leaving some extra for future expansion.
steps:
- uses: actions/checkout@v3
- name: Setup tools
uses: ./.github/actions/tool-setup
with:
node: false
- name: Install dependencies
run: composer install
- name: Run phpcs
run: |
echo "::add-matcher::.github/matchers/phpcs-problem-matcher.json"
composer phpcs:lint:required -- --report=emacs --standard=.github/files/php-linting-phpcs.xml
echo "::remove-matcher owner=phpcs"
### Runs PHPCompatibility over all PHP files.
# Local equivalent: `composer phpcs:compatibility`
phpcompatibility:
name: PHP Compatibility
runs-on: ubuntu-latest
needs: changed_files
if: needs.changed_files.outputs.php == 'true' || needs.changed_files.outputs.misc_php == 'true'
timeout-minutes: 5 # 2021-01-18: Successful runs seem to take ~1 minute. Leaving some extra for future expansion.
steps:
- uses: actions/checkout@v3
- name: Setup tools
uses: ./.github/actions/tool-setup
with:
node: false
- name: Install dependencies
run: composer install
- name: Run phpcs for PHPCompatibility
run: |
echo "::add-matcher::.github/matchers/phpcs-problem-matcher.json"
composer phpcs:compatibility -- --report=emacs .
echo "::remove-matcher owner=phpcs"
### Runs phpcs-changed on PHP files listed in phpcs-excludelist.json.
# Local equivalent: `composer phpcs:changed -- --git-base=<base> <files...>`
# `<base>` is the branch this PR is to be merged into, probably `origin/trunk`.
#
# Pre-commit, you might also `git add` the relevant files and run `composer phpcs:changed`
phpcs_changed:
name: PHP Code Sniffer (changes to excluded files only)
runs-on: ubuntu-latest
needs: changed_files
if: needs.changed_files.outputs.php_excluded_files != '[]'
continue-on-error: true
timeout-minutes: 5 # 2021-01-18: Successful runs seem to take ~1 minute. Leaving some extra for future expansion.
steps:
# We don't need full git history, but phpcs-changed does need everything up to the merge-base.
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 10
- uses: ./.github/actions/deepen-to-merge-base
- name: Setup tools
uses: ./.github/actions/tool-setup
with:
node: false
- name: Install dependencies
run: composer install
- name: Run phpcs-changed
shell: bash
env:
SHA: ${{ github.event.pull_request.base.sha }}
FILES: ${{ needs.changed_files.outputs.php_excluded_files }}
run: |
echo "::add-matcher::.github/matchers/phpcs-problem-matcher.json"
composer phpcs:changed -- --report=json --standard=.github/files/php-linting-phpcs.xml --git-base=$SHA $(jq -rn --argjson files "$FILES" '$files[]') |
jq -r '.files | to_entries | .[] | .key as $key | .value.messages[] | [ $key, ":", .line, ":", .column, ": ", .type, " - ", .message, " (", .source, ")" ] | map(tostring) | join("")'
echo "::remove-matcher owner=phpcs"
### Runs eslint on JS files not listed in eslint-excludelist.json
# Local equivalent: `pnpm run lint-required`
eslint:
name: ESLint (non-excluded files only)
runs-on: ubuntu-latest
needs: changed_files
if: needs.changed_files.outputs.js == 'true' || needs.changed_files.outputs.misc_js == 'true'
timeout-minutes: 10 # 2021-03-05: Runs now take ~5 minutes due to now installing all php/js deps to ensure valid linting.
steps:
- uses: actions/checkout@v3
- name: Setup tools
uses: ./.github/actions/tool-setup
- name: Monorepo pnpm install
run: pnpm install
- run: pnpm run lint-required
### Runs eslint-changed on JS files listed in eslint-excludelist.json.
# Local equivalent: `pnpm run lint-changed --git-base=<base>`
# `<base>` is the branch this PR is to be merged into, probably `origin/trunk`.
#
# Pre-commit, you might also `git add` the relevant files and run `pnpm run lint-changed`
eslint_changed:
name: ESLint (changes to excluded files only)
runs-on: ubuntu-latest
needs: changed_files
if: needs.changed_files.outputs.js_excluded_files != '[]'
continue-on-error: true
timeout-minutes: 10 # 2021-03-05: Taking ~4:30 now due to now installing all php/js deps to ensure valid linting.
steps:
# We don't need full git history, but eslint-changed does need everything up to the merge-base.
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 10
- uses: ./.github/actions/deepen-to-merge-base
- name: Setup tools
uses: ./.github/actions/tool-setup
- name: Monorepo pnpm install
run: pnpm install
- name: Run eslint-changed
env:
SHA: ${{ github.event.pull_request.base.sha }}
FILES: ${{ needs.changed_files.outputs.js_excluded_files }}
run: pnpm run lint-changed --git-base=$SHA $(jq -rn --argjson files "$FILES" '$files[]')
### Lints GitHub Actions yaml files.
# Local equivalent: `./tools/js-tools/lint-gh-actions.js <files>`
lint_gh_actions:
name: Lint GitHub Actions yaml files
runs-on: ubuntu-latest
needs: changed_files
if: needs.changed_files.outputs.ghactionsfiles == 'true' || needs.changed_files.outputs.misc == 'true'
timeout-minutes: 5 # 2021-03-24: Pnpm stuff takes about a minute.
steps:
- uses: actions/checkout@v3
- name: Setup tools
uses: ./.github/actions/tool-setup
with:
php: false
- run: pnpm install
- name: Run lint
run: ./tools/js-tools/lint-gh-actions.js -v '.github/workflows/*.{yml,yaml}' '.github/actions/*/action.{yml,yaml}' 'projects/github-actions/*/action.{yml,yaml}'
### Checks that copied files (e.g. readme, license) are in sync
# Local equivalent: `./tools/check-copied-files.sh`
copied_files:
name: Copied files are in sync
runs-on: ubuntu-latest
timeout-minutes: 1 # 2021-01-18: Successful runs seem to take a few seconds.
steps:
- uses: actions/checkout@v3
- run: ./tools/check-copied-files.sh
### Runs tools/cleanup-excludelists.sh and checks for any changes
# Local equivalent: `tools/cleanup-excludelists.sh`
check_excludelists:
name: Check linter exclude lists
runs-on: ubuntu-latest
needs: changed_files
if: needs.changed_files.outputs.excludelist == 'true'
timeout-minutes: 10 # 2022-05-11: The check itself takes 4 minutes.
steps:
- uses: actions/checkout@v3
- name: Setup tools
uses: ./.github/actions/tool-setup
- run: composer install
- name: Monorepo pnpm install
run: pnpm install
- name: Cleanup excludelists
run: tools/cleanup-excludelists.sh
- name: Check for changes to exclude lists
run: tools/js-tools/check-excludelist-diff.js
### Checks that changelogger change files are being created.
# Local equivalent: Probably `tools/check-changelogger-use.php origin/trunk HEAD`
changelogger_used:
name: Changelogger use
runs-on: ubuntu-latest
timeout-minutes: 5 # 2021-03-24: Takes about a minute.
steps:
# We don't need full git history, but tools/check-changelogger-use.php does need everything up to the merge-base.
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 10
- uses: ./.github/actions/deepen-to-merge-base
- name: Setup tools
uses: ./.github/actions/tool-setup
with:
node: false
- name: Check change files are touched for touched projects
env:
BASE: ${{ github.event.pull_request.base.sha }}
HEAD: ${{ github.event.pull_request.head.sha }}
run: tools/check-changelogger-use.php --debug "$BASE" "$HEAD"
### Checks that changelogger change files are valid.
# Local equivalent: `./tools/changelogger-validate-all.sh`
changelogger_valid:
name: Changelogger validity
runs-on: ubuntu-latest
timeout-minutes: 5 # 2021-03-24: Takes about a minute
steps:
- uses: actions/checkout@v3
- name: Setup tools
uses: ./.github/actions/tool-setup
with:
node: false
- name: Check change file validity
run: tools/changelogger-validate-all.sh -vv
### Checks that lock files are up to date.
# Local equivalent: .github/files/check-lock-files.sh
# Note that may modify lock files in your working tree!
lock_files:
name: "Lock files are up to date"
runs-on: ubuntu-latest
needs: changed_files
if: needs.changed_files.outputs.lockfiles == 'true' || needs.changed_files.outputs.misc == 'true'
timeout-minutes: 7 # 2021-03-17: Successful runs seem to take 3+ minutes, thanks to pnpm building stuff.
steps:
- uses: actions/checkout@v3
- name: Setup tools
uses: ./.github/actions/tool-setup
- run: .github/files/check-lock-files.sh
### Check that monorepo packages are correctly referenced.
# Local equivalent: tools/check-intra-monorepo-deps.sh -v && .github/files/check-monorepo-package-repos.sh
monorepo_package_refs:
name: Monorepo package version refs
runs-on: ubuntu-latest
needs: changed_files
if: needs.changed_files.outputs.lockfiles == 'true' || needs.changed_files.outputs.misc == 'true'
timeout-minutes: 5 # 2022-03-25: The pnpm install will probably take a minute or so.
steps:
- uses: actions/checkout@v3
- name: Setup tools
uses: ./.github/actions/tool-setup
- run: pnpm install
- run: tools/check-intra-monorepo-deps.sh -v
- run: .github/files/check-monorepo-package-repos.sh
### Checks against project structure, e.g. that composer.json exists.
# Local equivalent: `./.github/files/lint-project-structure.sh`
project_structure:
name: Project structure
runs-on: ubuntu-latest
timeout-minutes: 5 # 2021-03-24: Pnpm stuff takes about a minute.
steps:
- uses: actions/checkout@v3
- name: Setup tools
uses: ./.github/actions/tool-setup
- run: pnpm install
- run: .github/files/lint-project-structure.sh