@@ -2,100 +2,136 @@ name: CI for Plugin Boilerplate
22
33on : [push]
44
5+ # Cancel any in-progress runs for the same branch when a new push lands.
6+ concurrency :
7+ group : ${{ github.workflow }}-${{ github.ref }}
8+ cancel-in-progress : true
9+
10+ # Disable all permissions by default; grant minimal permissions per job.
11+ permissions : {}
12+
13+ # wp-env mounts the working tree at wp-content/plugins/<basename>, so check out into
14+ # a directory named to match the slug used in composer.json's "integration" script.
15+ defaults :
16+ run :
17+ working-directory : plugin-slug
18+
519jobs :
620 lint :
721 name : Lint and code standards
822
923 runs-on : ubuntu-latest
1024
25+ permissions :
26+ contents : read
27+
1128 steps :
1229 - name : Checkout
13- uses : actions/checkout@master
14-
15- - name : Validate composer.json and composer.lock
16- run : composer validate
30+ uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
31+ with :
32+ path : plugin-slug
33+ persist-credentials : false
1734
18- - name : Setup PHP 8.2
19- uses : shivammathur/setup-php@v2
35+ - name : Setup PHP 8.4
36+ uses : shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0
2037 with :
21- php-version : ' 8.2 '
38+ php-version : ' 8.4 '
2239 coverage : none
40+ tools : composer:v2
2341 extensions : mbstring # Just enough to keep phpunit happy when installing Composer dependencies.
2442
25- - name : Install dependencies
26- run : composer install --prefer-dist --no-progress --no-suggest
43+ - name : Validate composer.json
44+ run : composer validate --no-check-lock
45+
46+ - name : Install Composer dependencies
47+ uses : ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
48+ with :
49+ working-directory : plugin-slug
50+ composer-options : --prefer-dist --no-progress --no-suggest
2751
2852 # Needed as runs-on: system doesn't have xml-lint by default.
2953 - name : Lint .phpcs.xml.dist
30- uses : ChristophWurst/xmllint-action@v1
54+ uses : ChristophWurst/xmllint-action@7c54ff113fc0f6d4588a15cb4dfe31b6ecca5212 # v1.2.1
3155 with :
32- xml-file : ./.phpcs.xml.dist
33- xml-schema-file : ./vendor/squizlabs/php_codesniffer/phpcs.xsd
56+ xml-file : ./plugin-slug/ .phpcs.xml.dist
57+ xml-schema-file : ./plugin-slug/ vendor/squizlabs/php_codesniffer/phpcs.xsd
3458
3559 # Needed as runs-on: system doesn't have xml-lint by default.
3660 - name : Lint phpunit.xml.dist
37- uses : ChristophWurst/xmllint-action@v1
61+ uses : ChristophWurst/xmllint-action@7c54ff113fc0f6d4588a15cb4dfe31b6ecca5212 # v1.2.1
3862 with :
39- xml-file : ./phpunit.xml.dist
40- xml-schema-file : ./vendor/phpunit/phpunit/phpunit.xsd
63+ xml-file : ./plugin-slug/ phpunit.xml.dist
64+ xml-schema-file : ./plugin-slug/ vendor/phpunit/phpunit/phpunit.xsd
4165
4266 - name : Lint PHP files
4367 run : bin/php-lint
4468
4569 - name : Run PHPCS
4670 run : composer cs
4771
48- supported-php-versions :
49- name : Determine Supported PHP Versions
50- runs-on : ubuntu-latest
51- outputs :
52- extensions : ${{ steps.supported-versions-matrix.outputs.extensions }}
53- version : ${{ steps.supported-versions-matrix.outputs.version }}
54- steps :
55- - uses : actions/checkout@v4
56- - id : supported-versions-matrix
57- uses : WyriHaximus/github-action-composer-php-versions-in-range@v1
58-
5972 test :
60- name : Unit and Integration tests
61- needs :
62- - supported-php-versions
73+ name : WP ${{ matrix.wordpress }} on PHP ${{ matrix.php }}
6374
6475 runs-on : ubuntu-latest
6576
77+ permissions :
78+ contents : read
79+
6680 strategy :
6781 fail-fast : false
6882 matrix :
69- php : ${{ fromJson(needs.supported-php-versions.outputs.version) }}
70- wordpress : [ 'latest' ]
7183 include :
72- - php : ' 8.3'
73- wordpress : ' trunk'
74- experimental : true
84+ # Lowest supported PHP with lowest supported WordPress.
85+ - php : ' 8.4'
86+ wordpress : ' 6.9'
87+ # Latest supported PHP with the latest WordPress.
88+ - php : ' 8.5'
89+ wordpress : ' master'
7590
7691 steps :
7792 - name : Checkout
78- uses : actions/checkout@v4
93+ uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
94+ with :
95+ path : plugin-slug
96+ persist-credentials : false
97+
98+ - name : Setup Node.js (for wp-env)
99+ uses : actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
100+ with :
101+ node-version : ' lts/*'
102+
103+ - name : Cache npm registry for wp-env
104+ uses : actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
105+ with :
106+ path : ~/.npm
107+ key : ${{ runner.os }}-npm-wp-env-${{ hashFiles('plugin-slug/.wp-env.json') }}
108+ restore-keys : |
109+ ${{ runner.os }}-npm-wp-env-
110+
111+ - name : Install wp-env
112+ run : npm install -g @wordpress/env
79113
80114 - name : Setup PHP
81- uses : shivammathur/setup-php@v2
115+ uses : shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0
82116 env :
83117 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
84118 with :
85119 php-version : ${{ matrix.php }}
86120 coverage : pcov
121+ tools : composer:v2
87122 # https://make.wordpress.org/hosting/handbook/handbook/server-environment/#php-extensions
88123 extensions : curl, dom, exif, fileinfo, hash, json, mbstring, mysqli, libsodium, openssl, pcre, imagick, xml, zip
89124
90- - name : Install dependencies
91- run : |
92- composer install --prefer-dist --no-progress --no-suggest
93- # composer require pcov/clobber --dev
94- # vendor/bin/pcov clobber
95- # See see https://dev.to/swashata/setup-php-pcov-for-5-times-faster-phpunit-code-coverage-3d9c
125+ - name : Install Composer dependencies
126+ uses : ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
127+ with :
128+ working-directory : plugin-slug
129+ composer-options : --prefer-dist --no-progress --no-suggest
96130
97131 - name : Setup Problem Matchers for PHPUnit
98- run : echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
132+ env :
133+ RUNNER_TOOL_CACHE : ${{ runner.tool_cache }}
134+ run : echo "::add-matcher::${RUNNER_TOOL_CACHE}/phpunit.json"
99135
100136 - name : Run unit tests
101137 run : composer unit
@@ -104,11 +140,11 @@ jobs:
104140 run : composer infection
105141 continue-on-error : true
106142
107- - name : Start MySQL Service
108- run : sudo systemctl start mysql.service
109-
110- - name : Prepare environment
111- run : composer prepare
143+ - name : Start wp-env
144+ run : wp-env start
145+ env :
146+ WP_ENV_CORE : WordPress/WordPress#${{ matrix.wordpress }}
147+ WP_ENV_PHP_VERSION : ${{ matrix.php }}
112148
113149 - name : Run integration tests
114150 run : composer integration
0 commit comments