Repository navigation
2739 lines (2529 loc) · 142 KB
/
Copy pathwp-compatibility-test.yml
File metadata and controls
2739 lines (2529 loc) · 142 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
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This workflow performs comprehensive WordPress plugin compatibility and quality checks.
# It runs multiple validation processes including:
# - WordPress Plugin Check for WordPress.org compatibility
# - PHPUnit tests across supported PHP versions (8.2, 8.3, 8.4, 8.5)
# - PHP compatibility testing across multiple PHP versions (8.2, 8.3, 8.4, 8.5)
# - WordPress compatibility testing across multiple WP versions (6.8, latest, nightly)
# - PHPStan static analysis for WordPress-specific code quality
# - WordPress security vulnerability scanning using pattern analysis
# - PHPCS code standards validation for WordPress coding standards
# - Psalm static analysis and taint analysis
# - YAML, workflow, Python and Markdown linting
# (yamllint, actionlint, zizmor, Ruff, mypy, markdownlint)
# - Unit test line coverage, with a minimum
# - Code quality analysis and automated issue creation for failures
# Acceptance requires passing results and artifacts for the exact tested source.
name: WordPress Compatibility & Plugin Check
on:
# Run on pushes to main branch and on all pull requests
push:
branches: [ main ]
pull_request:
# Allow manually triggering the workflow
workflow_dispatch:
# Cancels all previous workflow runs for the same branch that have not yet completed
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
plugin-check:
name: WP Plugin Check (PHP 8.3)
runs-on: ubuntu-latest
# The job files an issue when it fails on main.
permissions:
contents: read
issues: write
timeout-minutes: 45
steps:
- name: Checkout code
id: checkout_code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# Always fetch the latest commit, disable any caching
fetch-depth: 0
clean: true
- name: Setup PHP 8.3
id: setup_php_8_3
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: '8.3'
extensions: mysqli, curl, zip, intl, gd, mbstring, fileinfo, xml
coverage: none
tools: composer:v2
- name: Clear any existing composer cache
id: clear_any_existing_composer_cache
run: |
composer clear-cache || true
rm -rf vendor/ composer.lock || true
- name: Install Composer dependencies (no cache)
id: install_composer_dependencies_no_cache
run: |
composer install --prefer-dist --no-progress --no-cache
- name: Clean up potential artifact directories
id: clean_up_potential_artifact_directories
run: |
echo "🧹 Removing any artifact directories to prevent conflicts..."
rm -rf .reports 2>/dev/null || true
rm -rf build 2>/dev/null || true
echo "✅ Cleanup complete"
- name: Prepare Plugin Check build directory
id: prepare_plugin_check_build_directory
run: |
# Stdlib-only automation fixtures run on this runner, not the workstation.
python3 .github/scripts/test-automation.py
rm -rf plugin-check-build 2>/dev/null || true
PLUGIN_SLUG="enginescript-site-optimizer"
BUILD_DIR="plugin-check-build/${PLUGIN_SLUG}"
mkdir -p "$BUILD_DIR"
cp enginescript-site-optimizer.php "$BUILD_DIR/"
cp uninstall.php "$BUILD_DIR/"
cp readme.txt "$BUILD_DIR/"
cp LICENSE "$BUILD_DIR/"
cp -r includes "$BUILD_DIR/"
cp -r languages "$BUILD_DIR/"
# Inspect a release-shaped ZIP without publishing or changing the PCP input.
PACKAGE_ZIP="$RUNNER_TEMP/${PLUGIN_SLUG}-candidate.zip"
rm -f "$PACKAGE_ZIP"
(cd plugin-check-build && zip -qr "$PACKAGE_ZIP" "$PLUGIN_SLUG")
mkdir -p "$RUNNER_TEMP/es-optimizer-diagnostics"
python3 .github/scripts/check-plugin-package.py "$BUILD_DIR" --zip "$PACKAGE_ZIP" | tee "$RUNNER_TEMP/es-optimizer-diagnostics/package-manifest.txt"
if [ "$(stat --format=%s "$PACKAGE_ZIP")" -gt 2097152 ]; then
rm -f "$PACKAGE_ZIP"
echo '::error::Candidate package exceeds the diagnostic artifact limit.'
exit 1
fi
- name: WordPress Plugin Check
id: wordpress_plugin_check
uses: WordPress/plugin-check-action@10857da14b6c2246d15402b3e69f777edcf8c12e # v1.1.9
with:
# Comment only on trusted, same-repository human PRs. An empty token
# skips the action's optional comment, not checks or annotations.
repo-token: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]' && github.event.pull_request.user.login != 'dependabot[bot]' && github.token || '' }}
# Production-style plugin directory. Excludes repo-only files such as
# .github, GEMINI.md, and other development artifacts.
build-dir: './plugin-check-build/enginescript-site-optimizer'
# Configure which categories to check
categories: |
accessibility
general
performance
plugin_repo
security
# Run the experimental checks as well
include-experimental: true
# Don't ignore warnings or errors, including the low-severity ones
ignore-warnings: false
ignore-errors: false
include-low-severity-errors: true
include-low-severity-warnings: true
# A warning fails the job, as an error does
strict: true
# WordPress version to use
wp-version: 'latest'
- name: Handle plugin check completion
id: handle_plugin_check_completion
if: ${{ always() }}
env:
JOB_STATUS: ${{ job.status }}
run: |
echo "Plugin Check job status: $JOB_STATUS"
- name: Preserve diagnostic summary
id: preserve_diagnostics
if: ${{ always() }}
continue-on-error: true
env:
STEP_RESULTS: |
checkout_code=${{ steps.checkout_code.outcome }}
setup_php_8_3=${{ steps.setup_php_8_3.outcome }}
clear_any_existing_composer_cache=${{ steps.clear_any_existing_composer_cache.outcome }}
install_composer_dependencies_no_cache=${{ steps.install_composer_dependencies_no_cache.outcome }}
clean_up_potential_artifact_directories=${{ steps.clean_up_potential_artifact_directories.outcome }}
prepare_plugin_check_build_directory=${{ steps.prepare_plugin_check_build_directory.outcome }}
wordpress_plugin_check=${{ steps.wordpress_plugin_check.outcome }}
handle_plugin_check_completion=${{ steps.handle_plugin_check_completion.outcome }}
run: |
mkdir -p "$RUNNER_TEMP/es-optimizer-diagnostics"
printf '%s\n' "$STEP_RESULTS" > "$RUNNER_TEMP/es-optimizer-diagnostics/steps.txt"
printf 'commit=%s\njob=%s\n' "$GITHUB_SHA" "$GITHUB_JOB" > "$RUNNER_TEMP/es-optimizer-diagnostics/run.txt"
if command -v php >/dev/null; then
php -r 'echo PHP_VERSION, PHP_EOL;' > "$RUNNER_TEMP/es-optimizer-diagnostics/php.txt"
fi
if command -v composer >/dev/null && [ -f vendor/composer/installed.json ]; then
php -r '$data = json_decode(file_get_contents("vendor/composer/installed.json"), true, 512, JSON_THROW_ON_ERROR); foreach ($data["packages"] ?? $data as $package) { echo $package["name"], " ", $package["version"], PHP_EOL; }' > "$RUNNER_TEMP/es-optimizer-diagnostics/dependencies.txt"
fi
# Never upload config, authentication data, SQL, exports, or arbitrary logs.
# Refuse oversized or linked diagnostics instead of uploading them.
find "$RUNNER_TEMP/es-optimizer-diagnostics" -type l -delete
find "$RUNNER_TEMP/es-optimizer-diagnostics" -type f -size +2M -delete
- name: Upload diagnostic summary
id: upload_diagnostics
if: ${{ always() }}
continue-on-error: true
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: wp-compat-plugin-check
path: |
${{ runner.temp }}/es-optimizer-diagnostics/run.txt
${{ runner.temp }}/es-optimizer-diagnostics/steps.txt
${{ runner.temp }}/es-optimizer-diagnostics/php.txt
${{ runner.temp }}/es-optimizer-diagnostics/dependencies.txt
${{ runner.temp }}/es-optimizer-diagnostics/wordpress.txt
${{ runner.temp }}/es-optimizer-diagnostics/junit.xml
${{ runner.temp }}/es-optimizer-diagnostics/package-manifest.txt
${{ runner.temp }}/enginescript-site-optimizer-candidate.zip
retention-days: 7
if-no-files-found: warn
- name: Create issue on plugin check failure
id: create_issue_on_plugin_check_failure
if: ${{ failure() && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.actor != 'dependabot[bot]' }}
uses: JasonEtco/create-an-issue@1b14a70e4d8dc185e5cc76d3bec9eab20257b2c5 # v2.9.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FAILURE_STAGE: ${{ steps.checkout_code.outcome == 'failure' && 'checkout_code' || steps.setup_php_8_3.outcome == 'failure' && 'setup_php_8_3' || steps.clear_any_existing_composer_cache.outcome == 'failure' && 'clear_any_existing_composer_cache' || steps.install_composer_dependencies_no_cache.outcome == 'failure' && 'install_composer_dependencies_no_cache' || steps.clean_up_potential_artifact_directories.outcome == 'failure' && 'clean_up_potential_artifact_directories' || steps.prepare_plugin_check_build_directory.outcome == 'failure' && 'prepare_plugin_check_build_directory' || steps.wordpress_plugin_check.outcome == 'failure' && 'wordpress_plugin_check' || steps.handle_plugin_check_completion.outcome == 'failure' && 'handle_plugin_check_completion' || 'unknown_or_canceled' }}
PHP_VERSION: '8.3'
RUN_ID: ${{ github.run_id }}
WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
with:
filename: .github/ISSUE_TEMPLATE/plugin-check-failure.md
update_existing: false
- name: Mark job as failed after issue creation
id: mark_job_as_failed_after_issue_creation
if: ${{ failure() }}
run: |
echo "::error::Plugin Check job failed; see the failed step and reporting outcome."
exit 1
phpcs:
name: PHPCS (PHP 8.3)
runs-on: ubuntu-latest
# The job files an issue when it fails on main.
permissions:
contents: read
issues: write
timeout-minutes: 45
steps:
- name: Checkout code
id: checkout_code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Setup PHP 8.3
id: setup_php_8_3
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: '8.3'
extensions: mysqli, curl, zip, intl, gd, mbstring, fileinfo, xml
coverage: none
tools: composer:v2
- name: Install Composer dependencies
id: install_composer_dependencies
uses: ramsey/composer-install@26d8a556604053a9612623447203a691f406fbe6 # v4
with:
dependency-versions: highest
composer-options: "--prefer-dist --no-progress"
- name: Verify PHPCS standards
id: verify_phpcs_standards
run: |
# Verify the project-local PHPCS installation and registered standards.
vendor/bin/phpcs -i
- name: Run PHPCS
id: run_phpcs
run: |
vendor/bin/phpcs --standard=phpcs.xml
# Static scanner controls; never execute these incompatible PHP fixtures.
CONTROL_DIR="$RUNNER_TEMP/optimizer-compat-controls"
mkdir -p "$CONTROL_DIR" "$RUNNER_TEMP/es-optimizer-diagnostics"
printf '<?php strlen("control");\n' > "$CONTROL_DIR/compatible.php"
printf '<?php each(array());\n' > "$CONTROL_DIR/legacy-incompatible.php"
printf '<?php json_validate("{}");\n' > "$CONTROL_DIR/modern-incompatible.php"
vendor/bin/phpcs --standard=PHPCompatibilityWP --runtime-set testVersion 8.2 "$CONTROL_DIR/compatible.php"
if vendor/bin/phpcs --standard=PHPCompatibilityWP --runtime-set testVersion 8.2 --report=json "$CONTROL_DIR/legacy-incompatible.php" > "$CONTROL_DIR/legacy.json"; then
echo '::error::The known legacy-incompatible fixture was missed.'
exit 1
else
status=$?
[[ $status == 1 || $status == 2 ]]
fi
php -r '$report = json_decode(file_get_contents($argv[1]), true, 512, JSON_THROW_ON_ERROR); foreach ($report["files"] ?? [] as $file) { foreach ($file["messages"] as $message) { if (str_starts_with($message["source"], "PHPCompatibility.") && str_contains($message["message"], "each")) { exit(0); } } } exit(1);' "$CONTROL_DIR/legacy.json"
if vendor/bin/phpcs --standard=PHPCompatibilityWP --runtime-set testVersion 8.2 --report=json "$CONTROL_DIR/modern-incompatible.php" > "$CONTROL_DIR/modern.json"; then
echo '::warning::CR-TOOL-001: current stable rules miss PHP 8.3 json_validate at the PHP 8.2 floor. Modern-rule acceptance remains pending.'
echo 'modern_rule_coverage=known_gap' > "$RUNNER_TEMP/es-optimizer-diagnostics/compatibility-controls.txt"
else
status=$?
[[ $status == 1 || $status == 2 ]]
php -r '$report = json_decode(file_get_contents($argv[1]), true, 512, JSON_THROW_ON_ERROR); foreach ($report["files"] ?? [] as $file) { foreach ($file["messages"] as $message) { if (str_starts_with($message["source"], "PHPCompatibility.") && str_contains($message["message"], "json_validate")) { exit(0); } } } exit(1);' "$CONTROL_DIR/modern.json"
echo 'modern_rule_coverage=fixture_detected' > "$RUNNER_TEMP/es-optimizer-diagnostics/compatibility-controls.txt"
fi
echo 'compatible=passed;legacy_incompatible=rejected' >> "$RUNNER_TEMP/es-optimizer-diagnostics/compatibility-controls.txt"
- name: Preserve diagnostic summary
id: preserve_diagnostics
if: ${{ always() }}
continue-on-error: true
env:
STEP_RESULTS: |
checkout_code=${{ steps.checkout_code.outcome }}
setup_php_8_3=${{ steps.setup_php_8_3.outcome }}
install_composer_dependencies=${{ steps.install_composer_dependencies.outcome }}
verify_phpcs_standards=${{ steps.verify_phpcs_standards.outcome }}
run_phpcs=${{ steps.run_phpcs.outcome }}
run: |
mkdir -p "$RUNNER_TEMP/es-optimizer-diagnostics"
printf '%s\n' "$STEP_RESULTS" > "$RUNNER_TEMP/es-optimizer-diagnostics/steps.txt"
printf 'commit=%s\njob=%s\n' "$GITHUB_SHA" "$GITHUB_JOB" > "$RUNNER_TEMP/es-optimizer-diagnostics/run.txt"
if command -v php >/dev/null; then
php -r 'echo PHP_VERSION, PHP_EOL;' > "$RUNNER_TEMP/es-optimizer-diagnostics/php.txt"
fi
if command -v composer >/dev/null && [ -f vendor/composer/installed.json ]; then
php -r '$data = json_decode(file_get_contents("vendor/composer/installed.json"), true, 512, JSON_THROW_ON_ERROR); foreach ($data["packages"] ?? $data as $package) { echo $package["name"], " ", $package["version"], PHP_EOL; }' > "$RUNNER_TEMP/es-optimizer-diagnostics/dependencies.txt"
fi
# Never upload config, authentication data, SQL, exports, or arbitrary logs.
# Refuse oversized or linked diagnostics instead of uploading them.
find "$RUNNER_TEMP/es-optimizer-diagnostics" -type l -delete
find "$RUNNER_TEMP/es-optimizer-diagnostics" -type f -size +2M -delete
- name: Upload diagnostic summary
id: upload_diagnostics
if: ${{ always() }}
continue-on-error: true
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: wp-compat-phpcs
path: |
${{ runner.temp }}/es-optimizer-diagnostics/run.txt
${{ runner.temp }}/es-optimizer-diagnostics/steps.txt
${{ runner.temp }}/es-optimizer-diagnostics/php.txt
${{ runner.temp }}/es-optimizer-diagnostics/dependencies.txt
${{ runner.temp }}/es-optimizer-diagnostics/wordpress.txt
${{ runner.temp }}/es-optimizer-diagnostics/junit.xml
${{ runner.temp }}/es-optimizer-diagnostics/compatibility-controls.txt
retention-days: 7
if-no-files-found: warn
- name: Create issue on PHPCS failure
id: create_issue_on_phpcs_failure
if: ${{ failure() && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.actor != 'dependabot[bot]' }}
uses: JasonEtco/create-an-issue@1b14a70e4d8dc185e5cc76d3bec9eab20257b2c5 # v2.9.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FAILURE_STAGE: ${{ steps.checkout_code.outcome == 'failure' && 'checkout_code' || steps.setup_php_8_3.outcome == 'failure' && 'setup_php_8_3' || steps.install_composer_dependencies.outcome == 'failure' && 'install_composer_dependencies' || steps.verify_phpcs_standards.outcome == 'failure' && 'verify_phpcs_standards' || steps.run_phpcs.outcome == 'failure' && 'run_phpcs' || 'unknown_or_canceled' }}
PHP_VERSION: '8.3'
RUN_ID: ${{ github.run_id }}
WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
with:
filename: .github/ISSUE_TEMPLATE/phpcs-failure.md
update_existing: false
vip-phpcs:
name: WP VIP CS (PHP 8.3)
runs-on: ubuntu-latest
# The job files an issue when it fails on main.
permissions:
contents: read
issues: write
timeout-minutes: 45
steps:
- name: Checkout code
id: checkout_code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Setup PHP 8.3
id: setup_php_8_3
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: '8.3'
extensions: mysqli, curl, zip, intl, gd, mbstring, fileinfo, xml
coverage: none
tools: composer:v2
- name: Install Composer dependencies
id: install_composer_dependencies
uses: ramsey/composer-install@26d8a556604053a9612623447203a691f406fbe6 # v4
with:
dependency-versions: highest
composer-options: "--prefer-dist --no-progress"
- name: Install WordPress VIP Coding Standards
id: install_wordpress_vip_coding_standards
run: |
# Install PHPCS and WordPress VIP Coding Standards
composer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer global require --dev squizlabs/php_codesniffer:"^3.13.6"
composer global require --dev wp-coding-standards/wpcs:"^3.4.1"
composer global require --dev automattic/vipwpcs:"^3.0.1"
composer global require --dev dealerdirect/phpcodesniffer-composer-installer:"^1.2"
# Add composer bin to PATH
VIP_BIN_DIR="$(composer global config bin-dir --absolute)"
echo "$VIP_BIN_DIR" >> "$GITHUB_PATH"
echo "VIP_PHPCS=$VIP_BIN_DIR/phpcs" >> "$GITHUB_ENV"
export PATH="$VIP_BIN_DIR:$PATH"
# Verify installation and show available standards
"$VIP_BIN_DIR/phpcs" -i
# Verify VIP standards are available
"$VIP_BIN_DIR/phpcs" -i | grep -F WordPress-VIP-Go
- name: Create VIP-specific PHPCS configuration
id: create_vip_specific_phpcs_configuration
run: |
cat > phpcs-vip.xml << 'EOF'
<?xml version="1.0"?>
<ruleset name="WordPress VIP Go Coding Standards">
<description>WordPress VIP Go coding standards for enterprise-level WordPress development</description>
<!-- Files to check -->
<file>enginescript-site-optimizer.php</file>
<file>includes</file>
<file>uninstall.php</file>
<!-- Exclude patterns -->
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>*/tests/*</exclude-pattern>
<exclude-pattern>*/assets/*</exclude-pattern>
<exclude-pattern>*/languages/*</exclude-pattern>
<exclude-pattern>*/.git/*</exclude-pattern>
<exclude-pattern>*/.github/*</exclude-pattern>
<exclude-pattern>*.js</exclude-pattern>
<exclude-pattern>*.css</exclude-pattern>
<!-- Use WordPress VIP Go coding standards -->
<rule ref="WordPress-VIP-Go">
<!-- Allow short array syntax [] instead of array() -->
<exclude name="Generic.Arrays.DisallowShortArraySyntax"/>
<!-- Allow longer lines for readability in some cases -->
<exclude name="Generic.Files.LineLength.TooLong"/>
<!-- Exclude JS-related sniffs to avoid deprecation warnings -->
<exclude name="WordPressVIPMinimum.JS"/>
</rule>
<!-- Add specific WordPressVIPMinimum rules (non-JS) -->
<rule ref="WordPressVIPMinimum.Security"/>
<rule ref="WordPressVIPMinimum.Performance"/>
<rule ref="WordPressVIPMinimum.UserExperience"/>
<rule ref="WordPressVIPMinimum.Functions"/>
<rule ref="WordPressVIPMinimum.Variables"/>
<rule ref="WordPressVIPMinimum.Files"/>
<rule ref="WordPressVIPMinimum.Hooks"/>
<!-- WordPress internationalization with plugin text domain -->
<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
<element value="enginescript-site-optimizer"/>
</property>
</properties>
</rule>
<!-- Only scan PHP files -->
<arg name="extensions" value="php"/>
<!-- Show progress -->
<arg value="p"/>
<!-- Show sniff codes in all reports -->
<arg value="s"/>
<!-- Use colors in output -->
<arg name="colors"/>
<!-- Set report width for better readability -->
<arg name="report-width" value="120"/>
<!-- Report every message, including those rated below the default severity of 5 -->
<arg name="severity" value="1"/>
</ruleset>
EOF
- name: Run WordPress VIP PHPCS
id: run_wordpress_vip_phpcs
run: |
echo "🚀 Running WordPress VIP Go Coding Standards scan..."
echo "📋 This scan focuses on VIP-specific requirements including:"
echo " • File system operation restrictions"
echo " • Performance and caching best practices"
echo " • Security vulnerabilities specific to VIP platform"
echo " • User experience guidelines for enterprise WordPress"
echo " • Uncached function usage patterns"
echo ""
echo "📦 Using standards: WordPress-VIP-Go, WordPressVIPMinimum"
echo "🎯 Scanning PHP files only (excluding JS/CSS to avoid deprecation warnings)"
echo ""
# Run VIP-specific PHPCS scan using our custom configuration
# Only scan PHP files to avoid JS/CSS deprecation warnings
"$VIP_PHPCS" --standard=phpcs-vip.xml --extensions=php || {
echo ""
echo "⚠️ WordPress VIP coding standards issues found."
echo "💡 Note: These are VIP-specific recommendations for enterprise WordPress platforms."
echo "🔧 Many of these may not apply to standard WordPress installations."
echo "📖 For more info: https://docs.wpvip.com/technical-references/code-quality-and-best-practices/"
echo ""
exit 1
}
echo "✅ WordPress VIP coding standards check completed successfully!"
- name: Preserve diagnostic summary
id: preserve_diagnostics
if: ${{ always() }}
continue-on-error: true
env:
STEP_RESULTS: |
checkout_code=${{ steps.checkout_code.outcome }}
setup_php_8_3=${{ steps.setup_php_8_3.outcome }}
install_composer_dependencies=${{ steps.install_composer_dependencies.outcome }}
install_wordpress_vip_coding_standards=${{ steps.install_wordpress_vip_coding_standards.outcome }}
create_vip_specific_phpcs_configuration=${{ steps.create_vip_specific_phpcs_configuration.outcome }}
run_wordpress_vip_phpcs=${{ steps.run_wordpress_vip_phpcs.outcome }}
run: |
mkdir -p "$RUNNER_TEMP/es-optimizer-diagnostics"
printf '%s\n' "$STEP_RESULTS" > "$RUNNER_TEMP/es-optimizer-diagnostics/steps.txt"
printf 'commit=%s\njob=%s\n' "$GITHUB_SHA" "$GITHUB_JOB" > "$RUNNER_TEMP/es-optimizer-diagnostics/run.txt"
if command -v php >/dev/null; then
php -r 'echo PHP_VERSION, PHP_EOL;' > "$RUNNER_TEMP/es-optimizer-diagnostics/php.txt"
fi
if command -v composer >/dev/null && [ -f vendor/composer/installed.json ]; then
php -r '$data = json_decode(file_get_contents("vendor/composer/installed.json"), true, 512, JSON_THROW_ON_ERROR); foreach ($data["packages"] ?? $data as $package) { echo $package["name"], " ", $package["version"], PHP_EOL; }' > "$RUNNER_TEMP/es-optimizer-diagnostics/dependencies.txt"
fi
# Never upload config, authentication data, SQL, exports, or arbitrary logs.
# Refuse oversized or linked diagnostics instead of uploading them.
find "$RUNNER_TEMP/es-optimizer-diagnostics" -type l -delete
find "$RUNNER_TEMP/es-optimizer-diagnostics" -type f -size +2M -delete
- name: Upload diagnostic summary
id: upload_diagnostics
if: ${{ always() }}
continue-on-error: true
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: wp-compat-vip-phpcs
path: |
${{ runner.temp }}/es-optimizer-diagnostics/run.txt
${{ runner.temp }}/es-optimizer-diagnostics/steps.txt
${{ runner.temp }}/es-optimizer-diagnostics/php.txt
${{ runner.temp }}/es-optimizer-diagnostics/dependencies.txt
${{ runner.temp }}/es-optimizer-diagnostics/wordpress.txt
${{ runner.temp }}/es-optimizer-diagnostics/junit.xml
retention-days: 7
if-no-files-found: warn
- name: Create issue on VIP PHPCS failure
id: create_issue_on_vip_phpcs_failure
if: ${{ failure() && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.actor != 'dependabot[bot]' }}
uses: JasonEtco/create-an-issue@1b14a70e4d8dc185e5cc76d3bec9eab20257b2c5 # v2.9.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FAILURE_STAGE: ${{ steps.checkout_code.outcome == 'failure' && 'checkout_code' || steps.setup_php_8_3.outcome == 'failure' && 'setup_php_8_3' || steps.install_composer_dependencies.outcome == 'failure' && 'install_composer_dependencies' || steps.install_wordpress_vip_coding_standards.outcome == 'failure' && 'install_wordpress_vip_coding_standards' || steps.create_vip_specific_phpcs_configuration.outcome == 'failure' && 'create_vip_specific_phpcs_configuration' || steps.run_wordpress_vip_phpcs.outcome == 'failure' && 'run_wordpress_vip_phpcs' || 'unknown_or_canceled' }}
PHP_VERSION: '8.3'
RUN_ID: ${{ github.run_id }}
WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
with:
filename: .github/ISSUE_TEMPLATE/vip-phpcs-failure.md
update_existing: false
phpmd:
name: PHPMD (PHP 8.3)
runs-on: ubuntu-latest
# The job files an issue when it fails on main.
permissions:
contents: read
issues: write
timeout-minutes: 45
steps:
- name: Checkout code
id: checkout_code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# Always fetch the latest commit, disable any caching
fetch-depth: 0
clean: true
- name: Verify latest commit
id: verify_latest_commit
run: |
echo "=== Git Information ==="
echo "Current commit: $(git rev-parse HEAD)"
echo "Current branch: $(git rev-parse --abbrev-ref HEAD)"
echo "Latest commit message: $(git log -1 --pretty=%B)"
echo "=== End Git Information ==="
- name: Setup PHP 8.3
id: setup_php_8_3
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: '8.3'
extensions: mysqli, curl, zip, intl, gd, mbstring, fileinfo, xml
coverage: none
tools: composer:v2
- name: Clear any existing composer cache
id: clear_any_existing_composer_cache
run: |
composer clear-cache || true
rm -rf vendor/ composer.lock || true
- name: Install Composer dependencies (no cache)
id: install_composer_dependencies_no_cache
run: |
composer install --prefer-dist --no-progress --no-cache
- name: Verify phpmd.xml content
id: verify_phpmd_xml_content
run: |
echo "=== Current phpmd.xml content ==="
cat phpmd.xml
echo "=== End phpmd.xml content ==="
- name: Run PHPMD
id: run_phpmd
run: |
# Use WordPress-specific PHPMD configuration (WordPress snake_case compatible)
echo "Using WordPress-specific PHPMD configuration (WordPress snake_case compatible)..."
vendor/bin/phpmd analyze . --no-progress --format text --ruleset phpmd.xml --exclude vendor --exclude tests --exclude stubs --exclude .private --exclude node_modules
- name: Preserve diagnostic summary
id: preserve_diagnostics
if: ${{ always() }}
continue-on-error: true
env:
STEP_RESULTS: |
checkout_code=${{ steps.checkout_code.outcome }}
verify_latest_commit=${{ steps.verify_latest_commit.outcome }}
setup_php_8_3=${{ steps.setup_php_8_3.outcome }}
clear_any_existing_composer_cache=${{ steps.clear_any_existing_composer_cache.outcome }}
install_composer_dependencies_no_cache=${{ steps.install_composer_dependencies_no_cache.outcome }}
verify_phpmd_xml_content=${{ steps.verify_phpmd_xml_content.outcome }}
run_phpmd=${{ steps.run_phpmd.outcome }}
run: |
mkdir -p "$RUNNER_TEMP/es-optimizer-diagnostics"
printf '%s\n' "$STEP_RESULTS" > "$RUNNER_TEMP/es-optimizer-diagnostics/steps.txt"
printf 'commit=%s\njob=%s\n' "$GITHUB_SHA" "$GITHUB_JOB" > "$RUNNER_TEMP/es-optimizer-diagnostics/run.txt"
if command -v php >/dev/null; then
php -r 'echo PHP_VERSION, PHP_EOL;' > "$RUNNER_TEMP/es-optimizer-diagnostics/php.txt"
fi
if command -v composer >/dev/null && [ -f vendor/composer/installed.json ]; then
php -r '$data = json_decode(file_get_contents("vendor/composer/installed.json"), true, 512, JSON_THROW_ON_ERROR); foreach ($data["packages"] ?? $data as $package) { echo $package["name"], " ", $package["version"], PHP_EOL; }' > "$RUNNER_TEMP/es-optimizer-diagnostics/dependencies.txt"
fi
# Never upload config, authentication data, SQL, exports, or arbitrary logs.
# Refuse oversized or linked diagnostics instead of uploading them.
find "$RUNNER_TEMP/es-optimizer-diagnostics" -type l -delete
find "$RUNNER_TEMP/es-optimizer-diagnostics" -type f -size +2M -delete
- name: Upload diagnostic summary
id: upload_diagnostics
if: ${{ always() }}
continue-on-error: true
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: wp-compat-phpmd
path: |
${{ runner.temp }}/es-optimizer-diagnostics/run.txt
${{ runner.temp }}/es-optimizer-diagnostics/steps.txt
${{ runner.temp }}/es-optimizer-diagnostics/php.txt
${{ runner.temp }}/es-optimizer-diagnostics/dependencies.txt
${{ runner.temp }}/es-optimizer-diagnostics/wordpress.txt
${{ runner.temp }}/es-optimizer-diagnostics/junit.xml
retention-days: 7
if-no-files-found: warn
- name: Create issue on PHPMD failure
id: create_issue_on_phpmd_failure
if: ${{ failure() && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.actor != 'dependabot[bot]' }}
uses: JasonEtco/create-an-issue@1b14a70e4d8dc185e5cc76d3bec9eab20257b2c5 # v2.9.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FAILURE_STAGE: ${{ steps.checkout_code.outcome == 'failure' && 'checkout_code' || steps.verify_latest_commit.outcome == 'failure' && 'verify_latest_commit' || steps.setup_php_8_3.outcome == 'failure' && 'setup_php_8_3' || steps.clear_any_existing_composer_cache.outcome == 'failure' && 'clear_any_existing_composer_cache' || steps.install_composer_dependencies_no_cache.outcome == 'failure' && 'install_composer_dependencies_no_cache' || steps.verify_phpmd_xml_content.outcome == 'failure' && 'verify_phpmd_xml_content' || steps.run_phpmd.outcome == 'failure' && 'run_phpmd' || 'unknown_or_canceled' }}
PHP_VERSION: '8.3'
RUN_ID: ${{ github.run_id }}
WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
with:
filename: .github/ISSUE_TEMPLATE/phpmd-failure.md
update_existing: false
psalm-analysis:
name: Psalm Static Analysis (PHP 8.3)
runs-on: ubuntu-latest
# The job files an issue when it fails on main.
permissions:
contents: read
issues: write
timeout-minutes: 45
steps:
- name: Checkout code
id: checkout_code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Setup PHP 8.3
id: setup_php_8_3
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: '8.3'
extensions: mysqli, curl, zip, intl, gd, mbstring, fileinfo, xml
coverage: none
tools: composer:v2
- name: Install Composer dependencies
id: install_composer_dependencies
uses: ramsey/composer-install@26d8a556604053a9612623447203a691f406fbe6 # v4
with:
dependency-versions: highest
composer-options: "--prefer-dist --no-progress"
- name: Verify Psalm installation
id: verify_psalm_installation
run: vendor/bin/psalm --version
- name: Run Psalm
id: run_psalm
run: |
vendor/bin/psalm --config=psalm.xml --show-info=true
- name: Run Psalm taint analysis
id: run_psalm_taint_analysis
run: |
vendor/bin/psalm --config=psalm.xml --taint-analysis
- name: Preserve diagnostic summary
id: preserve_diagnostics
if: ${{ always() }}
continue-on-error: true
env:
STEP_RESULTS: |
checkout_code=${{ steps.checkout_code.outcome }}
setup_php_8_3=${{ steps.setup_php_8_3.outcome }}
install_composer_dependencies=${{ steps.install_composer_dependencies.outcome }}
verify_psalm_installation=${{ steps.verify_psalm_installation.outcome }}
run_psalm=${{ steps.run_psalm.outcome }}
run_psalm_taint_analysis=${{ steps.run_psalm_taint_analysis.outcome }}
run: |
mkdir -p "$RUNNER_TEMP/es-optimizer-diagnostics"
printf '%s\n' "$STEP_RESULTS" > "$RUNNER_TEMP/es-optimizer-diagnostics/steps.txt"
printf 'commit=%s\njob=%s\n' "$GITHUB_SHA" "$GITHUB_JOB" > "$RUNNER_TEMP/es-optimizer-diagnostics/run.txt"
if command -v php >/dev/null; then
php -r 'echo PHP_VERSION, PHP_EOL;' > "$RUNNER_TEMP/es-optimizer-diagnostics/php.txt"
fi
if command -v composer >/dev/null && [ -f vendor/composer/installed.json ]; then
php -r '$data = json_decode(file_get_contents("vendor/composer/installed.json"), true, 512, JSON_THROW_ON_ERROR); foreach ($data["packages"] ?? $data as $package) { echo $package["name"], " ", $package["version"], PHP_EOL; }' > "$RUNNER_TEMP/es-optimizer-diagnostics/dependencies.txt"
fi
# Never upload config, authentication data, SQL, exports, or arbitrary logs.
# Refuse oversized or linked diagnostics instead of uploading them.
find "$RUNNER_TEMP/es-optimizer-diagnostics" -type l -delete
find "$RUNNER_TEMP/es-optimizer-diagnostics" -type f -size +2M -delete
- name: Upload diagnostic summary
id: upload_diagnostics
if: ${{ always() }}
continue-on-error: true
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: wp-compat-psalm-analysis
path: |
${{ runner.temp }}/es-optimizer-diagnostics/run.txt
${{ runner.temp }}/es-optimizer-diagnostics/steps.txt
${{ runner.temp }}/es-optimizer-diagnostics/php.txt
${{ runner.temp }}/es-optimizer-diagnostics/dependencies.txt
${{ runner.temp }}/es-optimizer-diagnostics/wordpress.txt
${{ runner.temp }}/es-optimizer-diagnostics/junit.xml
retention-days: 7
if-no-files-found: warn
- name: Create issue on Psalm failure
id: create_issue_on_psalm_failure
if: ${{ failure() && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.actor != 'dependabot[bot]' }}
uses: JasonEtco/create-an-issue@1b14a70e4d8dc185e5cc76d3bec9eab20257b2c5 # v2.9.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FAILURE_STAGE: ${{ steps.checkout_code.outcome == 'failure' && 'checkout_code' || steps.setup_php_8_3.outcome == 'failure' && 'setup_php_8_3' || steps.install_composer_dependencies.outcome == 'failure' && 'install_composer_dependencies' || steps.verify_psalm_installation.outcome == 'failure' && 'verify_psalm_installation' || steps.run_psalm.outcome == 'failure' && 'run_psalm' || steps.run_psalm_taint_analysis.outcome == 'failure' && 'run_psalm_taint_analysis' || 'unknown_or_canceled' }}
PHP_VERSION: '8.3'
RUN_ID: ${{ github.run_id }}
WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
with:
filename: .github/ISSUE_TEMPLATE/psalm-failure.md
update_existing: false
security-check:
name: Security Scan (PHP 8.3)
runs-on: ubuntu-latest
# The job files an issue when it fails on main.
permissions:
contents: read
issues: write
timeout-minutes: 45
steps:
- name: Checkout code
id: checkout_code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Setup PHP 8.3
id: setup_php_8_3
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: '8.3'
extensions: mysqli, curl, zip, intl, gd, mbstring, fileinfo, xml
coverage: none
tools: composer:v2
- name: Install Composer dependencies
id: install_composer_dependencies
uses: ramsey/composer-install@26d8a556604053a9612623447203a691f406fbe6 # v4
with:
dependency-versions: highest
composer-options: "--prefer-dist --no-progress"
- name: Security Check for known vulnerabilities in dependencies
id: security_check_for_known_vulnerabilities_in_dependencies
uses: symfonycorp/security-checker-action@258311ef7ac571f1310780ef3d79fc5abef642b5 # v5
- name: WordPress Security Scan
id: wordpress_security_scan
run: |
echo "Performing WordPress plugin security analysis..."
# Basic security pattern checks for common WordPress vulnerabilities
echo "Checking for common security issues..."
security_findings=0
test -f enginescript-site-optimizer.php
test -f uninstall.php
for source in includes/admin.php includes/bootstrap.php includes/frontend.php includes/options.php; do
test -f "$source"
done
grep_php() {
if grep -n "$1" enginescript-site-optimizer.php includes/*.php uninstall.php; then
return 0
else
local scan_status=$?
if [ "$scan_status" -gt 1 ]; then
echo '::error::Security scan could not read its production inputs.' >&2
exit "$scan_status"
fi
return 1
fi
}
# Check for potential SQL injection patterns
if grep_php "mysql_query\|mysqli_query"; then
echo "::error::Direct database queries found. Ensure proper sanitization."
security_findings=1
fi
# Check for potential XSS vulnerabilities (missing escaping)
if grep_php "echo \$_\|print \$_"; then
echo "::error::Potential XSS vulnerability found. Ensure output is escaped."
security_findings=1
fi
# Check for file inclusion vulnerabilities
if grep_php "include.*\$_\|require.*\$_"; then
echo "::error::Potential file inclusion vulnerability found."
security_findings=1
fi
# Check for eval() usage (security risk)
if grep_php "eval("; then
echo "::error::eval() function usage detected. This is a security risk."
security_findings=1
fi
# Check for proper nonce usage
if grep_php "wp_nonce_field\|wp_verify_nonce\|settings_fields" >/dev/null 2>&1; then
echo "WordPress nonce usage detected."
else
echo "Info: Consider adding WordPress nonces for form security."
fi
# Check for proper sanitization functions
if grep_php "sanitize_\|esc_" >/dev/null 2>&1; then
echo "WordPress sanitization functions detected."
else
echo "::error::Limited use of WordPress sanitization functions."
security_findings=1
fi
# Check for capability checks
if grep_php "current_user_can\|user_can" >/dev/null 2>&1; then
echo "WordPress capability checks detected."
else
echo "Info: Consider adding user capability checks where appropriate."
fi
if [ "$security_findings" -ne 0 ]; then
echo "::error::WordPress security scan found blocking findings."
exit 1
fi
echo "WordPress security scan completed."
- name: Preserve diagnostic summary
id: preserve_diagnostics
if: ${{ always() }}
continue-on-error: true
env:
STEP_RESULTS: |
checkout_code=${{ steps.checkout_code.outcome }}
setup_php_8_3=${{ steps.setup_php_8_3.outcome }}
install_composer_dependencies=${{ steps.install_composer_dependencies.outcome }}
security_check_for_known_vulnerabilities_in_dependencies=${{ steps.security_check_for_known_vulnerabilities_in_dependencies.outcome }}
wordpress_security_scan=${{ steps.wordpress_security_scan.outcome }}
run: |
mkdir -p "$RUNNER_TEMP/es-optimizer-diagnostics"
printf '%s\n' "$STEP_RESULTS" > "$RUNNER_TEMP/es-optimizer-diagnostics/steps.txt"
printf 'commit=%s\njob=%s\n' "$GITHUB_SHA" "$GITHUB_JOB" > "$RUNNER_TEMP/es-optimizer-diagnostics/run.txt"
if command -v php >/dev/null; then
php -r 'echo PHP_VERSION, PHP_EOL;' > "$RUNNER_TEMP/es-optimizer-diagnostics/php.txt"
fi
if command -v composer >/dev/null && [ -f vendor/composer/installed.json ]; then
php -r '$data = json_decode(file_get_contents("vendor/composer/installed.json"), true, 512, JSON_THROW_ON_ERROR); foreach ($data["packages"] ?? $data as $package) { echo $package["name"], " ", $package["version"], PHP_EOL; }' > "$RUNNER_TEMP/es-optimizer-diagnostics/dependencies.txt"
fi
# Never upload config, authentication data, SQL, exports, or arbitrary logs.
# Refuse oversized or linked diagnostics instead of uploading them.
find "$RUNNER_TEMP/es-optimizer-diagnostics" -type l -delete
find "$RUNNER_TEMP/es-optimizer-diagnostics" -type f -size +2M -delete
- name: Upload diagnostic summary
id: upload_diagnostics
if: ${{ always() }}
continue-on-error: true
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: wp-compat-security-check
path: |
${{ runner.temp }}/es-optimizer-diagnostics/run.txt
${{ runner.temp }}/es-optimizer-diagnostics/steps.txt
${{ runner.temp }}/es-optimizer-diagnostics/php.txt
${{ runner.temp }}/es-optimizer-diagnostics/dependencies.txt
${{ runner.temp }}/es-optimizer-diagnostics/wordpress.txt
${{ runner.temp }}/es-optimizer-diagnostics/junit.xml
retention-days: 7
if-no-files-found: warn
- name: Create issue on security vulnerability
id: create_issue_on_security_vulnerability
if: ${{ failure() && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.actor != 'dependabot[bot]' }}
uses: JasonEtco/create-an-issue@1b14a70e4d8dc185e5cc76d3bec9eab20257b2c5 # v2.9.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FAILURE_STAGE: ${{ steps.checkout_code.outcome == 'failure' && 'checkout_code' || steps.setup_php_8_3.outcome == 'failure' && 'setup_php_8_3' || steps.install_composer_dependencies.outcome == 'failure' && 'install_composer_dependencies' || steps.security_check_for_known_vulnerabilities_in_dependencies.outcome == 'failure' && 'security_check_for_known_vulnerabilities_in_dependencies' || steps.wordpress_security_scan.outcome == 'failure' && 'wordpress_security_scan' || 'unknown_or_canceled' }}
PHP_VERSION: '8.3'
RUN_ID: ${{ github.run_id }}
WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
with:
filename: .github/ISSUE_TEMPLATE/security-failure.md
update_existing: false
phpstan-wordpress:
name: PHPStan for WP (PHP 8.3)
runs-on: ubuntu-latest
# The job files an issue when it fails on main.
permissions:
contents: read
issues: write
timeout-minutes: 45
steps:
- name: Checkout code
id: checkout_code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# Always fetch the latest commit, disable any caching
fetch-depth: 0
clean: true
- name: Setup PHP 8.3
id: setup_php_8_3
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: '8.3'
extensions: mysqli, curl, zip, intl, gd, mbstring, fileinfo, xml
coverage: none
tools: composer:v2
- name: Clear any existing composer cache
id: clear_any_existing_composer_cache
run: |
composer clear-cache || true
rm -rf vendor/ composer.lock || true
- name: Install Composer dependencies (no cache)
id: install_composer_dependencies_no_cache
run: |
composer install --prefer-dist --no-progress --no-cache
- name: Verify phpstan.neon content
id: verify_phpstan_neon_content
run: |