Skip to content

Commit 1a6bf06

Browse files
authored
Merge pull request #30 from GaryJones/GaryJones/fix-ci-failures
Move CI integration tests to wp-env, harden and cache the workflows
2 parents e76e346 + 4baf9d5 commit 1a6bf06

9 files changed

Lines changed: 151 additions & 218 deletions

File tree

.github/workflows/ci.yml

Lines changed: 84 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,100 +2,136 @@ name: CI for Plugin Boilerplate
22

33
on: [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+
519
jobs:
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

.github/workflows/plugin-assets-readme-update.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,28 @@ on:
1010
push:
1111
branches:
1212
- master
13+
14+
# Serialise WordPress.org SVN updates to avoid overlapping commits to the same
15+
# repository. Do not cancel an in-progress run, since it may already be pushing.
16+
concurrency:
17+
group: ${{ github.workflow }}
18+
cancel-in-progress: false
19+
20+
permissions: {}
21+
1322
jobs:
1423
master:
1524
name: Update plugin and assets
1625
runs-on: ubuntu-latest
26+
permissions:
27+
contents: read
1728
steps:
18-
- uses: actions/checkout@master
29+
- name: Checkout
30+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
31+
with:
32+
persist-credentials: false
1933
- name: WordPress.org plugin asset/readme update
20-
uses: 10up/action-wordpress-plugin-asset-update@stable
34+
uses: 10up/action-wordpress-plugin-asset-update@2480306f6f693672726d08b5917ea114cb2825f7 # 2.2.0
2135
env:
2236
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} # Set in repo -> Settings -> Secrets
2337
SVN_USERNAME: ${{ secrets.SVN_USERNAME }} # Set in repo -> Settings -> Secrets

.github/workflows/plugin-push-to-wordpress-org.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,29 @@ on:
1010
types: [ released ]
1111
# Allow manual triggering of the workflow.
1212
workflow_dispatch:
13+
14+
# Serialise WordPress.org SVN deploys so two concurrent releases cannot push
15+
# to the same repository at once. Do not cancel an in-progress run, since it
16+
# may already be partway through committing tag content.
17+
concurrency:
18+
group: ${{ github.workflow }}
19+
cancel-in-progress: false
20+
21+
permissions: {}
22+
1323
jobs:
1424
release:
1525
name: New release to WordPress.org
1626
runs-on: ubuntu-latest
27+
permissions:
28+
contents: read
1729
steps:
1830
- name: Checkout
19-
uses: actions/checkout@v4
31+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
32+
with:
33+
persist-credentials: false
2034
- name: Push to WordPress.org
21-
uses: 10up/action-wordpress-plugin-deploy@stable
35+
uses: 10up/action-wordpress-plugin-deploy@54bd289b8525fd23a5c365ec369185f2966529c2 # 2.3.0
2236
env:
2337
SLUG: my-super-cool-plugin # Change this
2438
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}

.wp-env.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"plugins": [
3+
"."
4+
],
5+
"phpVersion": "8.4",
6+
"config": {
7+
"WP_DEBUG": true,
8+
"WP_DEBUG_LOG": true,
9+
"SCRIPT_DEBUG": true
10+
},
11+
"env": {
12+
"tests": {
13+
"phpVersion": "8.4",
14+
"core": "WordPress/WordPress#6.9"
15+
}
16+
}
17+
}

bin/README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
# Plugin unit tests
1+
# Plugin scripts
22

3-
## For VVV
3+
This directory contains helper scripts used during development and CI:
4+
5+
- `php-lint`: lints all PHP files for syntax errors.
6+
- `xml-lint`: lints `.xml` and `.xml.dist` config files against their schemas.
7+
8+
## Running integration tests
9+
10+
Integration tests run inside [`@wordpress/env`](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/) (Docker), configured by `.wp-env.json`.
411

512
```sh
6-
bash bin/install-wp-tests.sh wordpress_test root root localhost latest
13+
npm -g install @wordpress/env
14+
wp-env start
15+
composer integration
716
```

0 commit comments

Comments
 (0)