forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreusable-performance-test-v2.yml
More file actions
276 lines (238 loc) · 10.1 KB
/
reusable-performance-test-v2.yml
File metadata and controls
276 lines (238 loc) · 10.1 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
##
# A reusable workflow that runs the performance test suite.
##
name: Run performance Tests
on:
workflow_call:
inputs:
subject:
description: Subject of the test. One of `current`, `before`, or `base`.
required: true
type: string
LOCAL_DIR:
description: 'Where to run WordPress from.'
required: false
type: 'string'
default: 'build'
BASE_TAG:
description: 'The version being used for baseline measurements.'
required: false
type: 'string'
default: '6.7.0'
TARGET_SHA:
description: 'SHA hash of the target commit used for "before" measurements.'
required: true
type: 'string'
php-version:
description: 'The PHP version to use.'
required: false
type: 'string'
default: 'latest'
memcached:
description: 'Whether to enable memcached.'
required: false
type: 'boolean'
default: false
multisite:
description: 'Whether to use Multisite.'
required: false
type: 'boolean'
default: false
outputs:
BASE_TAG:
description: 'The version being used for baseline measurements.'
value: ${{ inputs.BASE_TAG }}
secrets:
CODEVITALS_PROJECT_TOKEN:
description: 'The authorization token for https://www.codevitals.run/project/wordpress.'
required: false
env:
PUPPETEER_SKIP_DOWNLOAD: ${{ true }}
# Prevent wp-scripts from downloading extra Playwright browsers,
# since Chromium will be installed in its dedicated step already.
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: true
# Performance testing should be performed in an environment reflecting a standard production environment.
LOCAL_WP_DEBUG: false
LOCAL_SCRIPT_DEBUG: false
LOCAL_SAVEQUERIES: false
LOCAL_WP_DEVELOPMENT_MODE: "''"
BASE_TAG: ${{ inputs.BASE_TAG }}
TARGET_SHA: ${{ inputs.TARGET_SHA }}
LOCAL_DIR: ${{ inputs.LOCAL_DIR }}
LOCAL_PHP_MEMCACHED: ${{ inputs.memcached }}
LOCAL_PHP: ${{ inputs.php-version }}${{ 'latest' != inputs.php-version && '-fpm' || '' }}
LOCAL_MULTISITE: ${{ inputs.multisite }}
# Disable permissions for all available scopes by default.
# Any needed permissions should be configured at the job level.
permissions: {}
jobs:
# Performs the following steps:
# - Configure environment variables.
# - Checkout repository.
# - Set up Node.js.
# - Log debug information.
# - Install npm dependencies.
# - Install Playwright browsers.
# - Build WordPress.
# - Start Docker environment.
# - Put the baseline or target version of WordPress in place if necessary.
# - Install object cache drop-in.
# - Log running Docker containers.
# - Docker debug information.
# - Install WordPress.
# - WordPress debug information.
# - Enable themes on Multisite.
# - Install WordPress Importer plugin.
# - Import mock data.
# - Deactivate WordPress Importer plugin.
# - Update permalink structure.
# - Install additional languages.
# - Disable external HTTP requests.
# - Disable cron.
# - List defined constants.
# - Install MU plugin.
# - Run performance tests.
# - Archive artifacts.
# - Ensure version-controlled files are not modified or deleted.
performance:
name: Test ${{ inputs.subject == 'base' && inputs.BASE_TAG || inputs.subject }}
runs-on: ubuntu-24.04
permissions:
contents: read
steps:
- name: Configure environment variables
run: |
echo "PHP_FPM_UID=$(id -u)" >> "$GITHUB_ENV"
echo "PHP_FPM_GID=$(id -g)" >> "$GITHUB_ENV"
- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
fetch-depth: ${{ github.event_name == 'workflow_dispatch' && '2' || '1' }}
persist-credentials: false
- name: Create a Docker override file
if: ${{ contains( fromJSON('["8.3", "8.4"]'), inputs.php-version ) }}
env:
PHP_VERSION: ${{ inputs.php-version }}
run: cp "tools/local-env/php-$PHP_VERSION-docker-compose.override.yml" docker-compose.override.yml
- name: Set up Node.js
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
with:
node-version-file: '.nvmrc'
cache: npm
- name: Log debug information
run: |
npm --version
node --version
curl --version
git --version
locale -a
- name: Install npm dependencies
run: npm ci
- name: Install Playwright browsers
run: npx playwright install --with-deps chromium
- name: Start Docker environment
run: npm run env:start
- name: Build WordPress
run: npm run build
- name: Download previous build artifact (target branch or previous commit)
if: ${{ inputs.subject == 'before' }}
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
id: get-previous-build
with:
script: |
const artifacts = await github.rest.actions.listArtifactsForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'wordpress-build-' + process.env.TARGET_SHA,
});
const matchArtifact = artifacts.data.artifacts[0];
if ( ! matchArtifact ) {
core.setFailed( 'No artifact found!' );
return false;
}
const download = await github.rest.actions.downloadArtifact( {
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
} );
const fs = require( 'fs' );
fs.writeFileSync( process.env.GITHUB_WORKSPACE + '/before.zip', Buffer.from( download.data ) )
return true;
- name: Unzip the previous build
if: ${{ inputs.subject == 'before' }}
run: |
unzip "${GITHUB_WORKSPACE}/before.zip"
unzip -o "${GITHUB_WORKSPACE}/wordpress.zip"
- name: Set the environment to the baseline version
if: ${{ inputs.subject == 'base' }}
run: |
VERSION="${BASE_TAG%.0}"
npm run env:cli -- core download --version="$VERSION" --force --path="/var/www/${LOCAL_DIR}"
- name: Install object cache drop-in
if: ${{ inputs.memcached }}
run: cp src/wp-content/object-cache.php build/wp-content/object-cache.php
- name: Log running Docker containers
run: docker ps -a
- name: Docker debug information
run: |
docker -v
docker compose run --rm mysql mysql --version
docker compose run --rm php php --version
docker compose run --rm php php -m
docker compose run --rm php php -i
docker compose run --rm php locale -a
- name: Install WordPress
run: npm run env:install
- name: Check version number
run: npm run env:cli -- core version --path="/var/www/${LOCAL_DIR}"
- name: Enable themes on Multisite
if: ${{ inputs.multisite }}
run: |
npm run env:cli -- theme enable twentytwentyone --network --path="/var/www/${LOCAL_DIR}"
npm run env:cli -- theme enable twentytwentythree --network --path="/var/www/${LOCAL_DIR}"
npm run env:cli -- theme enable twentytwentyfour --network --path="/var/www/${LOCAL_DIR}"
npm run env:cli -- theme enable twentytwentyfive --network --path="/var/www/${LOCAL_DIR}"
- name: Install WordPress Importer plugin
run: npm run env:cli -- plugin install wordpress-importer --activate --path="/var/www/${LOCAL_DIR}"
- name: Import mock data
run: |
curl -O https://raw.githubusercontent.com/WordPress/theme-test-data/b9752e0533a5acbb876951a8cbb5bcc69a56474c/themeunittestdata.wordpress.xml
npm run env:cli -- import themeunittestdata.wordpress.xml --authors=create --path="/var/www/${LOCAL_DIR}"
rm themeunittestdata.wordpress.xml
- name: Deactivate WordPress Importer plugin
run: npm run env:cli -- plugin deactivate wordpress-importer --path="/var/www/${LOCAL_DIR}"
- name: Update permalink structure
run: npm run env:cli -- rewrite structure '/%year%/%monthnum%/%postname%/' --path="/var/www/${LOCAL_DIR}"
- name: Install additional languages
run: |
npm run env:cli -- language core install de_DE --path="/var/www/${LOCAL_DIR}"
npm run env:cli -- language plugin install de_DE --all --path="/var/www/${LOCAL_DIR}"
npm run env:cli -- language theme install de_DE --all --path="/var/www/${LOCAL_DIR}"
# Prevent background update checks from impacting test stability.
- name: Disable external HTTP requests
run: npm run env:cli -- config set WP_HTTP_BLOCK_EXTERNAL true --raw --type=constant --path="/var/www/${LOCAL_DIR}"
# Prevent background tasks from impacting test stability.
- name: Disable cron
run: npm run env:cli -- config set DISABLE_WP_CRON true --raw --type=constant --path="/var/www/${LOCAL_DIR}"
- name: List defined constants
run: npm run env:cli -- config list --path="/var/www/${LOCAL_DIR}"
- name: Install MU plugin
run: |
mkdir "./${LOCAL_DIR}/wp-content/mu-plugins"
cp ./tests/performance/wp-content/mu-plugins/server-timing.php "./${LOCAL_DIR}/wp-content/mu-plugins/server-timing.php"
- name: Run performance tests
run: npm run test:performance
env:
TEST_RESULTS_PREFIX: ${{ inputs.subject != 'current' && inputs.subject || '' }}
- name: Archive artifacts
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
if: always()
with:
name: performance-${{ inputs.multisite && 'multisite' || 'single' }}-${{ inputs.memcached && 'memcached' || 'default' }}-${{ inputs.subject }}
path: artifacts
if-no-files-found: error
include-hidden-files: true
- name: Ensure version-controlled files are not modified or deleted
run: git diff --exit-code