Repository navigation
349 lines (316 loc) · 17.4 KB
/
Copy pathplugin-compatibility.yml
File metadata and controls
349 lines (316 loc) · 17.4 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
##
# Confirms that the most popular plugins in the WordPress.org directory can be activated against a version of
# WordPress without fataling.
#
# Core's test suites cover core itself, but nothing checks that a new version of WordPress can still boot with
# popular plugins active. When a plugin's assumptions about core stop holding, the result is a fatal error on
# every request and a white screen for real sites. This workflow is a smoke test for that class of failure, so
# that it can be found while there is still time to fix core or notify the plugin author.
#
# The plugin list is fetched from the WordPress.org API at run time and is sharded across a matrix sized to the
# number of plugins being tested. Each plugin is installed and activated on its own, so one broken plugin cannot
# hide another.
#
# It runs weekly against nightly, and can be dispatched manually against any version with any number of plugins,
# which is the intended way to use it as part of the pre-release checklist: point it at the beta or RC and give
# it a count.
#
# A dispatched run can also name the plugins to test instead of taking them from the directory, which is how to
# check a single plugin against a release candidate, or to reproduce a failure from an earlier run without
# waiting for the other plugins in its shard.
#
# The checks each shard runs live in `tools/plugin-compatibility/test-plugins.sh`. Running that script from a
# terminal runs exactly what a shard here runs, which is the quickest way to reproduce a result from a run
# without waiting on Actions.
#
# This workflow tests packaged builds downloaded from WordPress.org: a release, a beta or RC, or the nightly
# build of trunk. It never tests the code in this checkout, so a change to core is only tested here once it
# has reached a nightly build.
##
name: Plugin Compatibility Tests
on:
push:
branches:
- trunk
# Always test the workflow after it's updated.
paths:
- '.github/workflows/plugin-compatibility.yml'
- '.github/workflows/reusable-plugin-compatibility.yml'
- 'tools/plugin-compatibility/**'
pull_request:
# This workflow is only meant to run from trunk. Pull requests changing this file with different BASE branches should be ignored.
branches:
- trunk
# Always test the workflow when changes are suggested.
paths:
- '.github/workflows/plugin-compatibility.yml'
- '.github/workflows/reusable-plugin-compatibility.yml'
- 'tools/plugin-compatibility/**'
schedule:
- cron: '0 2 * * 1'
workflow_dispatch:
inputs:
wp-version:
description: 'The version of WordPress to test plugins against. Accepts "latest", "nightly", or a specific version number such as a beta or RC, for a pre-release check.'
type: string
default: 'nightly'
plugin-count:
description: 'Number of most popular plugins to test. Accepts any number from 1 to 1000, eg. 10, 50, or 250. Ignored when plugin-slugs is given.'
type: string
default: '100'
plugin-slugs:
description: 'Optional. Test these WordPress.org plugin slugs instead of the most popular ones. Accepts a comma or space separated list, eg. "woocommerce, classic-editor".'
type: string
default: ''
# Cancels all previous workflow runs for pull requests that have not completed.
concurrency:
# The concurrency group contains the workflow name and the branch name for pull requests
# or the commit hash for any other events.
#
# Dispatched runs are grouped by run instead, so that testing one plugin list does not cancel a run someone
# else started with a different one against the same version of WordPress.
group: ${{ github.workflow }}-${{ github.event_name == 'workflow_dispatch' && github.run_id || github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true
# Disable permissions for all available scopes by default.
# Any needed permissions should be configured at the job level.
permissions: {}
jobs:
# Builds the list of plugins to test and splits it into shards for the test matrix.
#
# The list is fetched at run time so that it never goes stale, and it is ordered by popularity so that a
# smaller count still tests the plugins with the widest reach. A dispatched run can name the plugins to test
# instead, in which case the directory is not queried at all.
#
# Performs the following steps:
# - Queries the WordPress.org plugin directory API for the most popular plugins, or reads the plugin-slugs input.
# - Splits the resulting slugs into shards and returns them as a job output.
build-plugin-matrix:
name: Build plugin matrix
permissions:
contents: read
runs-on: ubuntu-24.04
# Dispatched runs are allowed anywhere so that this can be run from a fork, which is the only way for
# someone without write access to the repository to try it against a plugin of their choosing.
if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'workflow_dispatch' }}
timeout-minutes: 5
outputs:
shards: ${{ steps.plugin-shards.outputs.shards }}
steps:
- name: Build the list of plugins to test
id: plugin-shards
env:
# An explicit list of slugs to test in place of the most popular ones. Empty for everything but a
# dispatched run that filled the input in.
PLUGIN_SLUGS: ${{ inputs.plugin-slugs }}
# Runs that carry no inputs fall back to the defaults. Pull request and push runs exist to test
# this workflow rather than the ecosystem, so they use a small count. See the note on the
# plugin-compatibility-tests job below.
PLUGIN_COUNT: ${{ inputs.plugin-count || ( contains( fromJSON('["pull_request", "push"]'), github.event_name ) && '10' ) || '100' }}
# Anything higher would take longer than the 20 minute wall time this is meant to fit inside. The
# directory holds roughly 66,000 plugins, so this is a guard against a typo, not a real limit.
MAX_PLUGIN_COUNT: '1000'
# Shards are sized rather than counted, so that a run of 10 does not spin up 5 near empty jobs and a
# run of 250 is not squeezed into the same 5.
TARGET_PER_SHARD: '25'
MAX_SHARDS: '10'
run: |
set -euo pipefail
RAW_SLUGS="${RUNNER_TEMP}/slugs-raw.txt"
DEDUPED_SLUGS="${RUNNER_TEMP}/slugs.txt"
: > "${RAW_SLUGS}"
if [ -n "${PLUGIN_SLUGS}" ]; then
# A named list replaces the popularity query entirely. Commas and whitespace both separate slugs,
# so a list can be pasted in however it was written down.
printf '%s' "${PLUGIN_SLUGS}" | tr ',[:space:]' '\n' > "${RAW_SLUGS}"
awk '!seen[$0]++ && NF > 0' "${RAW_SLUGS}" > "${DEDUPED_SLUGS}"
# A value outside the character set the directory uses is a typo worth stopping for now, rather
# than a plugin reported as impossible to download several minutes from now.
if INVALID_SLUGS="$( grep -Ev '^[a-z0-9-]+$' "${DEDUPED_SLUGS}" )"; then
printf 'The plugin-slugs input contains values that are not WordPress.org plugin slugs:\n%s\n' "${INVALID_SLUGS}"
exit 1
fi
PLUGIN_COUNT="$( wc -l < "${DEDUPED_SLUGS}" | tr -d ' ' )"
if [ "${PLUGIN_COUNT}" -lt 1 ]; then
printf 'The plugin-slugs input did not contain any plugin slugs.\n'
exit 1
fi
if [ "${PLUGIN_COUNT}" -gt "${MAX_PLUGIN_COUNT}" ]; then
printf 'The plugin-slugs input names %s plugins, more than the %s this workflow will test in one run.\n' "${PLUGIN_COUNT}" "${MAX_PLUGIN_COUNT}"
exit 1
fi
printf 'Testing the %s plugin(s) named in the plugin-slugs input.\n' "${PLUGIN_COUNT}"
else
# Guard against a non-numeric value being passed to the API.
if ! printf '%s' "${PLUGIN_COUNT}" | grep -Eq '^[0-9]+$'; then
printf 'The plugin-count input must be a positive integer, got "%s".\n' "${PLUGIN_COUNT}"
exit 1
fi
if [ "${PLUGIN_COUNT}" -lt 1 ] || [ "${PLUGIN_COUNT}" -gt "${MAX_PLUGIN_COUNT}" ]; then
printf 'The plugin-count input must be between 1 and %s, got %s.\n' "${MAX_PLUGIN_COUNT}" "${PLUGIN_COUNT}"
printf 'Testing more than %s plugins will not fit in the wall time this workflow targets.\n' "${MAX_PLUGIN_COUNT}"
exit 1
fi
# The API caps `per_page` at 250 and returns 250 without complaint for anything larger, so counts
# above that have to be paged.
PAGE_SIZE=250
PAGE=1
UNIQUE_COUNT=0
while : ; do
# The bracketed `request[...]` parameters are URL encoded by curl rather than written inline.
# The unneeded response fields are turned off to keep the payload small.
curl -sS --fail --retry 3 --retry-delay 5 \
--get 'https://api.wordpress.org/plugins/info/1.2/' \
--data-urlencode 'action=query_plugins' \
--data-urlencode 'request[browse]=popular' \
--data-urlencode "request[per_page]=${PAGE_SIZE}" \
--data-urlencode "request[page]=${PAGE}" \
--data-urlencode 'request[fields][short_description]=0' \
--data-urlencode 'request[fields][sections]=0' \
--data-urlencode 'request[fields][icons]=0' \
--data-urlencode 'request[fields][banners]=0' \
--data-urlencode 'request[fields][ratings]=0' \
--data-urlencode 'request[fields][tags]=0' \
--data-urlencode 'request[fields][compatibility]=0' \
--data-urlencode 'request[fields][screenshots]=0' \
-o "${RUNNER_TEMP}/plugins-page.json"
PAGE_COUNT="$( jq '.plugins | length' "${RUNNER_TEMP}/plugins-page.json" )"
jq -r '.plugins[] | .slug // empty' "${RUNNER_TEMP}/plugins-page.json" >> "${RAW_SLUGS}"
# Popularity ordering can shift between two requests, so the same slug can turn up on more than
# one page. Duplicates are dropped while the first occurrence keeps its position.
awk '!seen[$0]++ && NF > 0' "${RAW_SLUGS}" > "${DEDUPED_SLUGS}"
UNIQUE_COUNT="$( wc -l < "${DEDUPED_SLUGS}" | tr -d ' ' )"
printf 'Page %s returned %s plugins, %s unique slugs collected so far.\n' "${PAGE}" "${PAGE_COUNT}" "${UNIQUE_COUNT}"
if [ "${UNIQUE_COUNT}" -ge "${PLUGIN_COUNT}" ]; then
break
fi
# A short page means the directory has nothing left to give.
if [ "${PAGE_COUNT}" -lt "${PAGE_SIZE}" ]; then
printf 'The API returned fewer than %s plugins on page %s, so %s is everything available.\n' "${PAGE_SIZE}" "${PAGE}" "${UNIQUE_COUNT}"
break
fi
PAGE=$(( PAGE + 1 ))
done
fi
SLUGS="$( head -n "${PLUGIN_COUNT}" "${DEDUPED_SLUGS}" | jq -R -s -c 'split( "\n" ) | map( select( . != "" ) )' )"
TOTAL="$( printf '%s' "${SLUGS}" | jq 'length' )"
if [ "${TOTAL}" -lt 1 ]; then
printf 'The WordPress.org API did not return any plugins.\n'
exit 1
fi
if [ "${TOTAL}" -lt "${PLUGIN_COUNT}" ]; then
printf 'Only %s plugins were available, fewer than the %s requested.\n' "${TOTAL}" "${PLUGIN_COUNT}"
fi
# Aim for TARGET_PER_SHARD plugins in each shard, up to MAX_SHARDS shards. Past that point the
# shards get longer instead of more numerous.
SHARD_COUNT="$( awk -v total="${TOTAL}" -v per="${TARGET_PER_SHARD}" -v max="${MAX_SHARDS}" 'BEGIN {
count = int( ( total + per - 1 ) / per );
if ( count < 1 ) { count = 1 }
if ( count > max ) { count = max }
print count
}' )"
# Split the slugs into evenly sized shards, dropping any shard that ends up empty because fewer
# plugins were requested than there are shards. Each shard's slugs are passed to the reusable
# workflow as a JSON string.
SHARDS="$( printf '%s' "${SLUGS}" | jq -c --argjson shard_count "${SHARD_COUNT}" '
. as $slugs
| ( ( length + $shard_count - 1 ) / $shard_count | floor ) as $size
| [
range( 0; $shard_count )
| { index: ( . + 1 ), slugs: $slugs[ ( . * $size ) : ( ( . + 1 ) * $size ) ] }
]
| map( select( .slugs | length > 0 ) )
| map( { index: .index, slugs: ( .slugs | @json ) } )
' )"
printf 'Testing %s plugins across %s shard(s).\n' "${TOTAL}" "$( printf '%s' "${SHARDS}" | jq 'length' )"
printf '%s\n' "${SHARDS}" | jq -r '.[] | "Shard \(.index): \(.slugs)"'
printf 'shards=%s\n' "${SHARDS}" >> "${GITHUB_OUTPUT}"
# Tests each shard of plugins against the version of WordPress being tested.
#
# Pull request and push runs are here to check that this workflow itself still works, not to report on the
# health of the ecosystem. They use the latest stable release and a small number of plugins, because a genuine
# fatal against nightly is a true result that should not sit as a red check on every future change to these
# two files. Scheduled and manually dispatched runs are the ones that carry the ecosystem signal, and they
# default to nightly and the full count.
plugin-compatibility-tests:
name: WP ${{ inputs.wp-version || ( contains( fromJSON('["pull_request", "push"]'), github.event_name ) && 'latest' ) || 'nightly' }} / Shard ${{ matrix.shard.index }}
uses: ./.github/workflows/reusable-plugin-compatibility.yml
permissions:
contents: read
needs: [ build-plugin-matrix ]
if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'workflow_dispatch' }}
strategy:
fail-fast: false
matrix:
shard: ${{ fromJSON( needs.build-plugin-matrix.outputs.shards ) }}
with:
wp-version: ${{ inputs.wp-version || ( contains( fromJSON('["pull_request", "push"]'), github.event_name ) && 'latest' ) || 'nightly' }}
php-version: '8.5'
plugin-slugs: ${{ matrix.shard.slugs }}
db-type: 'mysql'
db-version: '9.7'
# Tests the fixture plugins, each built to break in one specific way, and passes only when every one of them
# gets the result listed for it in tools/plugin-compatibility/fixtures/expected.txt.
#
# The real plugins above can only show that nothing broke. This is what shows that a broken plugin is still
# caught, so a change to the checks that stops catching one fails here instead of quietly passing everything.
# The fixtures are installed from the checkout, so nothing is downloaded but WordPress itself.
fixture-tests:
name: WP ${{ inputs.wp-version || ( contains( fromJSON('["pull_request", "push"]'), github.event_name ) && 'latest' ) || 'nightly' }} / Fixture plugins
uses: ./.github/workflows/reusable-plugin-compatibility.yml
permissions:
contents: read
if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'workflow_dispatch' }}
with:
wp-version: ${{ inputs.wp-version || ( contains( fromJSON('["pull_request", "push"]'), github.event_name ) && 'latest' ) || 'nightly' }}
php-version: '8.5'
fixtures: true
db-type: 'mysql'
db-version: '9.7'
slack-notifications:
name: Slack Notifications
uses: ./.github/workflows/slack-notifications.yml
permissions:
actions: read
contents: read
needs: [ build-plugin-matrix, plugin-compatibility-tests, fixture-tests ]
if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name != 'pull_request' && always() }}
with:
calling_status: ${{ contains( needs.*.result, 'cancelled' ) && 'cancelled' || contains( needs.*.result, 'failure' ) && 'failure' || 'success' }}
secrets:
SLACK_GHA_SUCCESS_WEBHOOK: ${{ secrets.SLACK_GHA_SUCCESS_WEBHOOK }}
SLACK_GHA_CANCELLED_WEBHOOK: ${{ secrets.SLACK_GHA_CANCELLED_WEBHOOK }}
SLACK_GHA_FIXED_WEBHOOK: ${{ secrets.SLACK_GHA_FIXED_WEBHOOK }}
SLACK_GHA_FAILURE_WEBHOOK: ${{ secrets.SLACK_GHA_FAILURE_WEBHOOK }}
failed-workflow:
name: Failed workflow tasks
runs-on: ubuntu-24.04
permissions:
actions: write
# `needs` only exposes the result of the jobs listed here, and Slack succeeds whether or not the runs it
# reports on did, so the test jobs are listed too.
needs: [ build-plugin-matrix, plugin-compatibility-tests, fixture-tests, slack-notifications ]
if: |
always() &&
github.repository == 'WordPress/wordpress-develop' &&
github.event_name != 'pull_request' &&
github.run_attempt < 2 &&
(
contains( needs.*.result, 'cancelled' ) ||
contains( needs.*.result, 'failure' )
)
steps:
- name: Dispatch workflow run
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
retries: 2
retry-exempt-status-codes: 418
script: |
github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'failed-workflow.yml',
ref: 'trunk',
inputs: {
run_id: `${context.runId}`,
}
});