2424 type : boolean
2525 required : false
2626 default : false
27+ coverage-driver :
28+ description : ' Code coverage driver, either `pcov` or `xdebug`.'
29+ type : string
30+ required : false
31+ default : ' pcov'
32+ shard :
33+ description : ' Share of the scenarios to run, as `<index>/<total>`, for example `2/3`. Empty to run all of them.'
34+ type : string
35+ required : false
36+ default : ' '
37+ parallel :
38+ description : ' Number of parallel workers on the runner.'
39+ type : number
40+ required : false
41+ default : 4
2742 os :
2843 description : ' Runner to use. Defaults to ubuntu-22.04, or the RUNNERS_NAME repository variable when set.'
2944 type : string
4055 # anything omitted here is not shown anywhere. The database version is spelled
4156 # out because "MySQL" alone rendered the mysql-8.0 and mysql-8.4 legs
4257 # identically.
43- name : Behat | PHP ${{ inputs.php }} | WP ${{ inputs.wp }} | ${{ inputs.dbtype == 'sqlite' && 'SQLite' || inputs.mysql || 'MySQL' }}${{ inputs.object_cache == 'sqlite' && ' (Obj Cache)' || '' }}${{ inputs.coverage && ' (with coverage)' || '' }}${{ startsWith( inputs.os, 'windows' ) && ' (Windows)' || '' }}${{ startsWith( inputs.os, 'macos' ) && ' (macOS)' || '' }}
58+ name : Behat | PHP ${{ inputs.php }} | WP ${{ inputs.wp }} | ${{ inputs.dbtype == 'sqlite' && 'SQLite' || inputs.mysql || 'MySQL' }}${{ inputs.object_cache == 'sqlite' && ' (Obj Cache)' || '' }}${{ inputs.coverage && format( ' (with coverage{0})', inputs.shard && format( ', {0}', inputs.shard ) || '' ) || '' }}${{ startsWith( inputs.os, 'windows' ) && ' (Windows)' || '' }}${{ startsWith( inputs.os, 'macos' ) && ' (macOS)' || '' }}
4459 # Repositories with a heavy Behat suite can point the default Linux legs at a
4560 # larger runner by setting the `RUNNERS_NAME` repository variable, without
4661 # having to fork this workflow. Explicit macOS/Windows legs are unaffected.
@@ -166,9 +181,13 @@ jobs:
166181 uses : shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # v2
167182 with :
168183 php-version : ' ${{ inputs.php }}'
169- ini-values : zend.assertions=1, error_reporting=-1, display_errors=On
184+ # PCOV only instruments the files below pcov.directory. Left unset, it would pick the
185+ # working directory of every `wp` process the scenarios run, which is a temporary
186+ # WordPress install, and collect nothing. Xdebug instead instruments every file it
187+ # loads, all of WordPress included, which makes it several times slower.
188+ ini-values : zend.assertions=1, error_reporting=-1, display_errors=On${{ inputs.coverage && inputs.coverage-driver == 'pcov' && format( ', pcov.directory={0}, "pcov.exclude=~/vendor/~"', github.workspace ) || '' }}
170189 extensions : gd, imagick, mysql, zip, pdo_sqlite, exif, fileinfo
171- coverage : ${{ inputs.coverage && 'xdebug' || 'none' }}
190+ coverage : ${{ inputs.coverage && inputs.coverage-driver || 'none' }}
172191 tools : composer
173192 env :
174193 COMPOSER_TOKEN : ${{ secrets.GITHUB_TOKEN }}
@@ -214,11 +233,31 @@ jobs:
214233 if : ${{ inputs.dbtype != 'sqlite' && !startsWith(inputs.os, 'windows') && !startsWith(inputs.os, 'macos') }}
215234 run : sudo rm -f /usr/bin/mysql /usr/bin/mysqldump
216235
236+ # Versions of wp-cli/wp-cli-tests before the sharding support run every scenario on
237+ # every shard. Then only the first shard runs them, so that they run once.
238+ - name : Check whether wp-cli/wp-cli-tests can split the scenarios
239+ id : shard
240+ if : ${{ inputs.shard != '' }}
241+ env :
242+ SHARD : ${{ inputs.shard }}
243+ run : |
244+ RUNNER=vendor/wp-cli/wp-cli-tests/bin/run-behat-tests
245+ [ -f "$RUNNER" ] || RUNNER=bin/run-behat-tests
246+ if [ -f "$RUNNER" ] && grep -q WP_CLI_TEST_SHARD "$RUNNER"; then
247+ echo "shard=${SHARD}" >> "$GITHUB_OUTPUT"
248+ elif [ "${SHARD%%/*}" = 1 ]; then
249+ echo "::warning::This version of wp-cli/wp-cli-tests cannot split the scenarios across runners, so shard ${SHARD} runs all of them."
250+ else
251+ echo "This version of wp-cli/wp-cli-tests cannot split the scenarios across runners, so shard 1 runs all of them and this one none."
252+ echo "skip=true" >> "$GITHUB_OUTPUT"
253+ fi
254+
217255 - name : Prepare test database
218- if : ${{ inputs.dbtype != 'sqlite' }}
256+ if : ${{ inputs.dbtype != 'sqlite' && steps.shard.outputs.skip != 'true' }}
219257 run : composer prepare-tests
220258
221259 - name : Check Behat environment
260+ if : ${{ steps.shard.outputs.skip != 'true' }}
222261 env :
223262 WP_VERSION : ' ${{ inputs.wp }}'
224263 WP_CLI_TEST_DBTYPE : ${{ inputs.dbtype || 'mysql' }}
@@ -227,6 +266,7 @@ jobs:
227266 run : composer behat
228267
229268 - name : Run Behat
269+ if : ${{ steps.shard.outputs.skip != 'true' }}
230270 env :
231271 WP_VERSION : ' ${{ inputs.wp }}'
232272 WP_CLI_TEST_DBTYPE : ${{ inputs.dbtype || 'mysql' }}
@@ -236,23 +276,33 @@ jobs:
236276 # Spread the scenarios over parallel workers, each in its own throwaway containers.
237277 # Where Docker cannot be used, such as on Windows and macOS or when collecting code
238278 # coverage, wp-cli/wp-cli-tests falls back on its own. Older versions ignore these.
239- WP_CLI_TEST_PARALLEL : 4
279+ WP_CLI_TEST_PARALLEL : ${{ inputs.parallel }}
280+ # The test framework spreads the scenarios over the shards by their expected cost,
281+ # the same way on every runner, so that together they run every scenario once.
282+ WP_CLI_TEST_SHARD : ${{ steps.shard.outputs.shard }}
240283 WP_CLI_TEST_DOCKER : auto
241284 run : |
242285 composer behat -- $BEHAT_ARGS || composer behat-rerun -- $BEHAT_ARGS
243286
244- - name : Retrieve list of coverage files
245- id : coverage_files
246- if : ${{ inputs.coverage }}
247- run : |
248- FILES=$(find "$GITHUB_WORKSPACE/build/logs" -path '*.*' | paste -s -d "," -)
249- echo "files=$FILES" >> $GITHUB_OUTPUT
287+ # The calling workflow uploads the reports of all shards together, once all of them
288+ # finished, so that Codecov receives them as one upload and never reports on a part.
289+ - name : Name the code coverage report
290+ id : coverage_artifact
291+ if : ${{ inputs.coverage && steps.shard.outputs.skip != 'true' }}
292+ env :
293+ SHARD : ${{ inputs.shard || 'all' }}
294+ PHP : ${{ inputs.php }}
295+ DRIVER : ${{ inputs.coverage-driver }}
296+ PARALLEL : ${{ inputs.parallel }}
297+ run : echo "name=behat-coverage-${PHP}-${DRIVER}-p${PARALLEL}-${SHARD//\//-of-}" >> "$GITHUB_OUTPUT"
250298
251- - name : Upload code coverage report
252- if : ${{ inputs.coverage }}
253- uses : codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
299+ - name : Keep the code coverage report for the upload
300+ if : ${{ inputs.coverage && steps.shard.outputs.skip != 'true' }}
301+ uses : actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
254302 with :
255- # Because somehow providing `directory: build/logs` doesn't work for these files
256- files : ${{ steps.coverage_files.outputs.files }}
257- flags : feature
258- token : ${{ secrets.CODECOV_TOKEN }}
303+ name : ${{ steps.coverage_artifact.outputs.name }}
304+ path : build/logs/*.xml
305+ if-no-files-found : error
306+ retention-days : 1
307+ # A re-run of a failed shard replaces the report of its previous attempt.
308+ overwrite : true
0 commit comments