Skip to content

Commit d09b4eb

Browse files
authored
Use WordPress Playground (#173)
1 parent a9ad476 commit d09b4eb

20 files changed

Lines changed: 4933 additions & 4030 deletions

.github/workflows/test-basic.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'build-test'
1+
name: 'Basic Tests'
22
on: # rebuild any PRs and main branch changes
33
pull_request:
44
push:
@@ -8,6 +8,7 @@ on: # rebuild any PRs and main branch changes
88

99
jobs:
1010
basic:
11+
name: 'Run tests'
1112
runs-on: ubuntu-latest
1213
steps:
1314
- name: Checkout
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: 'Test with comparison'
2+
on: # rebuild any PRs and main branch changes
3+
pull_request:
4+
push:
5+
branches:
6+
- main
7+
- 'releases/*'
8+
9+
jobs:
10+
comparison-same:
11+
name: 'Run tests with same version'
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Run performance tests (before)
18+
id: before
19+
uses: ./
20+
with:
21+
urls: |
22+
/
23+
/sample-page/
24+
plugins: |
25+
./tests/dummy-plugin
26+
blueprint: './tests/blueprint-complex.json'
27+
iterations: 5
28+
repetitions: 1
29+
wp-version: 'latest'
30+
print-results: false
31+
upload-artifacts: false
32+
33+
- name: Run performance tests (after)
34+
id: after
35+
uses: ./
36+
with:
37+
urls: |
38+
/
39+
/sample-page/
40+
plugins: |
41+
./tests/dummy-plugin
42+
blueprint: './tests/blueprint-complex.json'
43+
iterations: 5
44+
repetitions: 1
45+
wp-version: 'latest'
46+
previous-results: ${{ steps.before.outputs.results }}
47+
print-results: true
48+
upload-artifacts: false
49+
comparison-different:
50+
name: 'Run tests with different versions'
51+
runs-on: ubuntu-latest
52+
steps:
53+
- name: Checkout
54+
uses: actions/checkout@v4
55+
56+
- name: Run performance tests (before)
57+
id: before
58+
uses: ./
59+
with:
60+
urls: |
61+
/
62+
/sample-page/
63+
plugins: |
64+
./tests/dummy-plugin
65+
blueprint: './tests/blueprint-complex.json'
66+
iterations: 5
67+
repetitions: 1
68+
wp-version: '6.5'
69+
print-results: false
70+
upload-artifacts: false
71+
72+
- name: Run performance tests (after)
73+
id: after
74+
uses: ./
75+
with:
76+
urls: |
77+
/
78+
/sample-page/
79+
plugins: |
80+
./tests/dummy-plugin
81+
blueprint: './tests/blueprint-complex.json'
82+
iterations: 5
83+
repetitions: 1
84+
wp-version: '6.6'
85+
previous-results: ${{ steps.before.outputs.results }}
86+
print-results: true
87+
upload-artifacts: false

.github/workflows/test-complex.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'build-test'
1+
name: 'Complex Tests'
22
on: # rebuild any PRs and main branch changes
33
pull_request:
44
push:
@@ -8,6 +8,7 @@ on: # rebuild any PRs and main branch changes
88

99
jobs:
1010
complex:
11+
name: 'Run tests'
1112
runs-on: ubuntu-latest
1213
steps:
1314
- name: Checkout
@@ -20,9 +21,8 @@ jobs:
2021
/
2122
/sample-page/
2223
plugins: |
23-
./dummy-plugin
24-
https://downloads.wordpress.org/plugin/performant-translations.zip
25-
https://downloads.wordpress.org/plugin/wordpress-seo.zip
24+
./tests/dummy-plugin
25+
blueprint: './tests/blueprint-complex.json'
2626
iterations: 5
2727
repetitions: 1
2828
wp-version: 'trunk'

.github/workflows/test-matrix.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'build-test'
1+
name: 'Matrix Tests'
22
on: # rebuild any PRs and main branch changes
33
pull_request:
44
push:
@@ -8,6 +8,7 @@ on: # rebuild any PRs and main branch changes
88

99
jobs:
1010
matrix:
11+
name: 'Run tests'
1112
timeout-minutes: 60
1213
runs-on: ubuntu-latest
1314
strategy:
@@ -25,10 +26,11 @@ jobs:
2526
/
2627
/sample-page/
2728
plugins: |
28-
./dummy-plugin
29+
./tests/dummy-plugin
2930
shard: ${{ matrix.shard }}
3031

3132
merge-reports:
33+
name: 'Merge reports'
3234
# Merge reports after playwright-tests, even if some shards have failed
3335
if: always()
3436
needs: [matrix]

.github/workflows/test-pr-comment.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'test-pr-comment'
1+
name: 'Test with PR comment'
22
on: # rebuild any PRs and main branch changes
33
pull_request:
44
push:
@@ -8,6 +8,7 @@ on: # rebuild any PRs and main branch changes
88

99
jobs:
1010
basic:
11+
name: 'Run tests'
1112
runs-on: ubuntu-latest
1213
steps:
1314
- name: Checkout
@@ -21,3 +22,4 @@ jobs:
2122
/sample-page/
2223
create-comment: true
2324
github-token: ${{ secrets.PR_COMMENT_TOKEN }}
25+
repetitions: 5

README.md

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ A GitHub action to measure performance metrics of WordPress sites.
44

55
Results are posted as comments to pull requests and as [GitHub Action job summaries](https://github.blog/2022-05-09-supercharging-github-actions-with-job-summaries/).
66

7-
It collects data from the `Server-Timing` header and runs Lighthouse on a given set of URLs.
7+
It collects data from the `Server-Timing` header and runs Lighthouse on a given set of URLs.
8+
9+
**Note:** Tests are run using [WordPress Playground](https://wordpress.org/playground/), which means you can use [blueprints](https://wordpress.github.io/wordpress-playground/blueprints) to prepare the test environment suitable to your needs.
10+
11+
## Example
812

913
<img width="1154" alt="Screenshot of a GitHub Action job summary output by this action" src="https://github.com/swissspidy/wp-performance-action/assets/841956/bb543ba2-a142-49d5-bb45-77d11f121824">
1014

@@ -24,59 +28,78 @@ See [action.yml](action.yml)
2428
github-token: ''
2529

2630
# Whether to create PR comments with performance results.
31+
#
2732
# Might require a custom `github-token` to be set.
2833
#
2934
# Default: false
3035
create-comment: ''
3136

37+
# Whether to add results to the workflow summary.
38+
#
39+
# Default: true
40+
print-results: ''
41+
42+
# Whether to upload any artifacts.
43+
#
44+
# Default: true
45+
upload-artifacts: ''
46+
3247
# Whether to log additional debugging information
3348
#
3449
# Default: ${{ runner.debug == '1' }}
3550
debug: ''
3651

3752
# List of URLs on the WordPress site to test.
53+
#
3854
# Each URL should be separated with new lines.
3955
#
4056
# Default: ''
4157
urls: ''
4258

43-
# List of plugins to install.
59+
# List of plugin directories to mount.
60+
#
4461
# Each plugin should be separated with new lines.
45-
# Supports paths to local directories or ZIP URLs.
46-
# Performance Lab (performance-lab) is always installed.
62+
# Needs to be a path to a local directory.
63+
# For installing plugins from the plugin directory
64+
# or a ZIP file, use a blueprint.
4765
#
4866
# Default: ''
4967
plugins: ''
5068

51-
# List of themes to install.
69+
# List of theme directories to mount.
70+
#
5271
# Each theme should be separated with new lines.
53-
# Supports paths to local directories or ZIP URLs.
54-
# Twenty Twenty-One (twentytwentyone) and Twenty Twenty-Three (twentytwentythree)
55-
# are always installed.
72+
# Needs to be a path to a local directory.
73+
# For installing themes from the theme directory
74+
# or a ZIP file, use a blueprint.
5675
#
5776
# Default: ''
5877
themes: ''
5978

60-
# Theme to activate on the site.
61-
# Theme needs to be already installed.
79+
# Blueprint to use for setting up the environment.
80+
#
81+
# Use this to install or activate additional plugins, defining constants,
82+
# and much more.
6283
#
63-
# Default: 'twentytwentyone'
64-
active-theme: ''
84+
# See https://wordpress.github.io/wordpress-playground/blueprints for more information.
85+
#
86+
# Default: ''
87+
blueprint: ''
6588

6689
# WordPress version to use.
67-
# Supports aliases such as latest, nightly, or trunk.
68-
# Also supports ZIP URLs or a Git reference from https://github.com/WordPress/wordpress
69-
# to install a specific version.
90+
#
91+
# Loads the specified WordPress version.
92+
# Accepts the last four major WordPress versions.
93+
# You can also use the generic values 'latest', 'nightly', or 'beta'.
7094
#
7195
# Default: 'latest'
7296
wp-version: ''
7397

7498
# PHP version to use.
75-
# Defaults to whatever version is the default
76-
# in the Docker-maintained WordPress image
77-
# (currently 8.0 as of November 2023)
7899
#
79-
# Default: 'auto'
100+
# Accepts 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3.
101+
#
102+
# Default: 'latest'
80103
php-version: ''
81104

82105
# Number of times the tests should be repeated.
@@ -133,6 +156,8 @@ steps:
133156

134157
### Advanced
135158

159+
Add a workflow (`.github/workflows/build-test.yml`):
160+
136161
```yaml
137162
steps:
138163
- name: Checkout
@@ -146,12 +171,37 @@ steps:
146171
/sample-page/
147172
plugins: |
148173
./my-awesome-plugin
149-
https://downloads.wordpress.org/plugin/performant-translations.zip
150-
https://downloads.wordpress.org/plugin/wordpress-seo.zip
174+
blueprint: ./my-custom-blueprint.json
151175
iterations: 5
152176
repetitions: 1
153177
```
154178

179+
Add a blueprint (`my-custom-blueprint.json`):
180+
181+
```json
182+
{
183+
"$schema": "https://playground.wordpress.net/blueprint-schema.json",
184+
"plugins": [
185+
"performant-translations",
186+
"akismet"
187+
],
188+
"steps": [
189+
{
190+
"step": "defineWpConfigConsts",
191+
"consts": {
192+
"WP_DEBUG": true
193+
}
194+
},
195+
{
196+
"step": "activatePlugin",
197+
"pluginName": "My Awesome Plugin",
198+
"pluginPath": "/wordpress/wp-content/plugins/my-awesome-plugin"
199+
}
200+
]
201+
}
202+
203+
```
204+
155205
### Running tests in parallel (sharding)
156206

157207
```yaml

0 commit comments

Comments
 (0)