mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Build/Test Tools: Switch to always running the tests via Composer.
Previously the tests were run via a PHPUnit Phar file for PHP 5.6–7.4, with PHP 8.0 using a Composer-installed version of PHPUnit. Running the tests via a Phar without the need for a `composer install` is (marginally) faster in overall build time, however, this commit is part of a larger chain of changes which will make the test suite PHPUnit cross-version compatible. With an eye on those upcoming changes, which will allow us to run the tests on the most appropriate PHPUnit version for each supported PHP version, it is opportune to switch to using a Composer-installed version of PHPUnit for all PHP versions supported by WordPress. Previously this was not possible without additional conditional `update` commands being run, due to the `composer.lock` file being in place and being locked at PHPUnit 7.5.20. Switching over to using the Composer-installed PHPUnit version, with that PHPUnit version adjusting based on the PHP version, allows for some minor simplifications in the GitHub Actions script. This means we need additional measures to make sure that the Composer cache file does not go too far out of date as that would significantly slow down the builds. By adding a "Last Monday" date to the cache key, in combination with the pre-existing OS, PHP version and the hash of the `composer.json` file, we can guarantee that: 1. There will be a cache created for each OS/PHP combination. 2. These caches will be replaced whenever a change is made to the `composer.json` file. 3. These caches will be replaced every Monday of each week ensuring that the cache file does not go too far out of date. Note: The NPM script `test:php` is now no longer needed during the builds. However, to prevent breaking the workflow of contributors who may be used to having the command available, the command remains available. In a future iteration we may be able to replace the caching of the Composer dependencies with the Composer cache action as offered on the GitHub marketplace, which would further simplify the script. Follow-up to [42960], [46290], [47881], [48957], [49037], [51543], [51544]. Props jrf, desrosj. Fixes #47381. git-svn-id: https://develop.svn.wordpress.org/trunk@51545 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
461f7764e4
commit
3e6cd53b4a
42
.github/workflows/phpunit-tests.yml
vendored
42
.github/workflows/phpunit-tests.yml
vendored
@ -30,9 +30,6 @@ concurrency:
|
||||
|
||||
env:
|
||||
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: ${{ true }}
|
||||
COMPOSER_INSTALL: ${{ false }}
|
||||
# Controls which NPM script to use for running PHPUnit tests. Options ar `php` and `php-composer`.
|
||||
PHPUNIT_SCRIPT: php
|
||||
LOCAL_PHP_MEMCACHED: ${{ false }}
|
||||
SLOW_TESTS: 'external-http,media,restapi'
|
||||
|
||||
@ -121,33 +118,34 @@ jobs:
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Get composer cache directory
|
||||
# This date is used to ensure that the Composer cache is refreshed at least once every week.
|
||||
# http://man7.org/linux/man-pages/man1/date.1.html
|
||||
- name: "Get last Monday's date"
|
||||
id: get-date
|
||||
run: echo "::set-output name=date::$(/bin/date -u --date='last Mon' "+%F")"
|
||||
shell: bash
|
||||
|
||||
- name: Get Composer cache directory
|
||||
id: composer-cache
|
||||
if: ${{ env.COMPOSER_INSTALL == true || env.LOCAL_PHP == '8.0-fpm' }}
|
||||
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
|
||||
|
||||
- name: Cache Composer dependencies
|
||||
if: ${{ env.COMPOSER_INSTALL == true || env.LOCAL_PHP == '8.0-fpm' }}
|
||||
uses: actions/cache@26968a09c0ea4f3e233fdddbafd1166051a095f6 # v2.1.4
|
||||
env:
|
||||
cache-name: cache-composer-dependencies
|
||||
with:
|
||||
path: ${{ steps.composer-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
|
||||
key: ${{ runner.os }}-php-${{ matrix.php }}-date-${{ steps.get-date.outputs.date }}-composer-${{ hashFiles('**/composer.json') }}
|
||||
|
||||
- name: Install Composer dependencies
|
||||
if: ${{ env.COMPOSER_INSTALL == true || env.LOCAL_PHP == '8.0-fpm' }}
|
||||
run: |
|
||||
docker-compose run --rm php composer --version
|
||||
|
||||
# The PHPUnit 7.x phar is not compatible with PHP 8 and won't be updated,
|
||||
# as PHPUnit 7 is no longer supported. The Composer-installed PHPUnit should be
|
||||
# used for PHP 8 testing instead.
|
||||
# Install using `composer update` as there is no `composer.lock` file.
|
||||
if [ ${{ env.LOCAL_PHP }} == '8.0-fpm' ]; then
|
||||
docker-compose run --rm php composer install --ignore-platform-reqs
|
||||
echo "PHPUNIT_SCRIPT=php-composer" >> $GITHUB_ENV
|
||||
docker-compose run --rm php composer update --ignore-platform-reqs
|
||||
else
|
||||
docker-compose run --rm php composer install
|
||||
docker-compose run --rm php composer update
|
||||
fi
|
||||
|
||||
- name: Docker debug information
|
||||
@ -190,36 +188,36 @@ jobs:
|
||||
|
||||
- name: Run slow PHPUnit tests
|
||||
if: ${{ matrix.split_slow }}
|
||||
run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c ${{ env.PHPUNIT_CONFIG }} --group ${{ env.SLOW_TESTS }}
|
||||
run: npm run test:php-composer -- --verbose -c ${{ env.PHPUNIT_CONFIG }} --group ${{ env.SLOW_TESTS }}
|
||||
|
||||
- name: Run PHPUnit tests for single site excluding slow tests
|
||||
if: ${{ matrix.php < '7.0' && ! matrix.split_slow && ! matrix.multisite }}
|
||||
run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c ${{ env.PHPUNIT_CONFIG }} --exclude-group ${{ env.SLOW_TESTS }},ajax,ms-files,ms-required
|
||||
run: npm run test:php-composer -- --verbose -c ${{ env.PHPUNIT_CONFIG }} --exclude-group ${{ env.SLOW_TESTS }},ajax,ms-files,ms-required
|
||||
|
||||
- name: Run PHPUnit tests for Multisite excluding slow tests
|
||||
if: ${{ matrix.php < '7.0' && ! matrix.split_slow && matrix.multisite }}
|
||||
run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c ${{ env.PHPUNIT_CONFIG }} --exclude-group ${{ env.SLOW_TESTS }},ajax,ms-files,ms-excluded,oembed-headers
|
||||
run: npm run test:php-composer -- --verbose -c ${{ env.PHPUNIT_CONFIG }} --exclude-group ${{ env.SLOW_TESTS }},ajax,ms-files,ms-excluded,oembed-headers
|
||||
|
||||
- name: Run PHPUnit tests
|
||||
if: ${{ matrix.php >= '7.0' }}
|
||||
run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c ${{ env.PHPUNIT_CONFIG }}
|
||||
run: npm run test:php-composer -- --verbose -c ${{ env.PHPUNIT_CONFIG }}
|
||||
|
||||
- name: Run AJAX tests
|
||||
if: ${{ ! matrix.split_slow }}
|
||||
run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c ${{ env.PHPUNIT_CONFIG }} --group ajax
|
||||
run: npm run test:php-composer -- --verbose -c ${{ env.PHPUNIT_CONFIG }} --group ajax
|
||||
|
||||
- name: Run ms-files tests as a multisite install
|
||||
if: ${{ matrix.multisite && ! matrix.split_slow }}
|
||||
run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c tests/phpunit/multisite.xml --group ms-files
|
||||
run: npm run test:php-composer -- --verbose -c tests/phpunit/multisite.xml --group ms-files
|
||||
|
||||
- name: Run external HTTP tests
|
||||
if: ${{ ! matrix.multisite && ! matrix.split_slow }}
|
||||
run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c phpunit.xml.dist --group external-http
|
||||
run: npm run test:php-composer -- --verbose -c phpunit.xml.dist --group external-http
|
||||
|
||||
# __fakegroup__ is excluded to force PHPUnit to ignore the <exclude> settings in phpunit.xml.dist.
|
||||
- name: Run (xDebug) tests
|
||||
if: ${{ ! matrix.split_slow }}
|
||||
run: LOCAL_PHP_XDEBUG=true npm run test:${{ env.PHPUNIT_SCRIPT }} -- -v --group xdebug --exclude-group __fakegroup__
|
||||
run: LOCAL_PHP_XDEBUG=true npm run test:php-composer -- -v --group xdebug --exclude-group __fakegroup__
|
||||
|
||||
- name: Ensure version-controlled files are not modified or deleted
|
||||
run: git diff --exit-code
|
||||
|
||||
33
.github/workflows/test-coverage.yml
vendored
33
.github/workflows/test-coverage.yml
vendored
@ -18,9 +18,6 @@ on:
|
||||
|
||||
env:
|
||||
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: ${{ true }}
|
||||
COMPOSER_INSTALL: ${{ false }}
|
||||
# Controls which NPM script to use for running PHPUnit tests. Options ar `php` and `php-composer`.
|
||||
PHPUNIT_SCRIPT: php
|
||||
LOCAL_PHP: '7.4-fpm'
|
||||
LOCAL_PHP_XDEBUG: true
|
||||
LOCAL_PHP_MEMCACHED: ${{ false }}
|
||||
@ -88,6 +85,32 @@ jobs:
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
|
||||
# This date is used to ensure that the Composer cache is refreshed at least once every week.
|
||||
# http://man7.org/linux/man-pages/man1/date.1.html
|
||||
- name: "Get last Monday's date"
|
||||
id: get-date
|
||||
run: echo "::set-output name=date::$(/bin/date -u --date='last Mon' "+%F")"
|
||||
shell: bash
|
||||
|
||||
- name: Get Composer cache directory
|
||||
id: composer-cache
|
||||
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
|
||||
|
||||
- name: Cache Composer dependencies
|
||||
uses: actions/cache@26968a09c0ea4f3e233fdddbafd1166051a095f6 # v2.1.4
|
||||
env:
|
||||
cache-name: cache-composer-dependencies
|
||||
with:
|
||||
path: ${{ steps.composer-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-php-${{ matrix.php }}-date-${{ steps.get-date.outputs.date }}-composer-${{ hashFiles('**/composer.json') }}
|
||||
|
||||
- name: Install Composer dependencies
|
||||
run: |
|
||||
docker-compose run --rm php composer --version
|
||||
|
||||
# Install using `composer update` as there is no `composer.lock` file.
|
||||
docker-compose run --rm php composer update
|
||||
|
||||
- name: Docker debug information
|
||||
run: |
|
||||
docker -v
|
||||
@ -121,7 +144,7 @@ jobs:
|
||||
|
||||
- name: Run tests as a single site
|
||||
if: ${{ ! matrix.multisite }}
|
||||
run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c phpunit.xml.dist --coverage-clover wp-code-coverage-single-clover-${{ github.sha }}.xml
|
||||
run: npm run test:php-composer -- --verbose -c phpunit.xml.dist --coverage-clover wp-code-coverage-single-clover-${{ github.sha }}.xml
|
||||
|
||||
- name: Ensure version-controlled files are not modified during the tests
|
||||
run: git diff --exit-code
|
||||
@ -135,7 +158,7 @@ jobs:
|
||||
|
||||
- name: Run tests as a multisite install
|
||||
if: ${{ matrix.multisite }}
|
||||
run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c tests/phpunit/multisite.xml --coverage-clover wp-code-coverage-multisite-clover-${{ github.sha }}.xml
|
||||
run: npm run test:php-composer -- --verbose -c tests/phpunit/multisite.xml --coverage-clover wp-code-coverage-multisite-clover-${{ github.sha }}.xml
|
||||
|
||||
- name: Ensure version-controlled files are not modified during the tests
|
||||
run: git diff --exit-code
|
||||
|
||||
Loading…
Reference in New Issue
Block a user