Make WordPress Core

Changeset 51545


Ignore:
Timestamp:
08/04/2021 07:48:56 PM (3 years ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk/.github/workflows
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/.github/workflows/phpunit-tests.yml

    r51535 r51545  
    3131env:
    3232  PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: ${{ true }}
    33   COMPOSER_INSTALL: ${{ false }}
    34   # Controls which NPM script to use for running PHPUnit tests. Options ar `php` and `php-composer`.
    35   PHPUNIT_SCRIPT: php
    3633  LOCAL_PHP_MEMCACHED: ${{ false }}
    3734  SLOW_TESTS: 'external-http,media,restapi'
     
    122119        run: npm ci
    123120
    124       - name: Get composer cache directory
     121      # This date is used to ensure that the Composer cache is refreshed at least once every week.
     122      # http://man7.org/linux/man-pages/man1/date.1.html
     123      - name: "Get last Monday's date"
     124        id: get-date
     125        run: echo "::set-output name=date::$(/bin/date -u --date='last Mon' "+%F")"
     126        shell: bash
     127
     128      - name: Get Composer cache directory
    125129        id: composer-cache
    126         if: ${{ env.COMPOSER_INSTALL == true || env.LOCAL_PHP == '8.0-fpm' }}
    127130        run: echo "::set-output name=dir::$(composer config cache-files-dir)"
    128131
    129132      - name: Cache Composer dependencies
    130         if: ${{ env.COMPOSER_INSTALL == true || env.LOCAL_PHP == '8.0-fpm' }}
    131133        uses: actions/cache@26968a09c0ea4f3e233fdddbafd1166051a095f6 # v2.1.4
    132134        env:
     
    134136        with:
    135137          path: ${{ steps.composer-cache.outputs.dir }}
    136           key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
     138          key: ${{ runner.os }}-php-${{ matrix.php }}-date-${{ steps.get-date.outputs.date }}-composer-${{ hashFiles('**/composer.json') }}
    137139
    138140      - name: Install Composer dependencies
    139         if: ${{ env.COMPOSER_INSTALL == true || env.LOCAL_PHP == '8.0-fpm' }}
    140141        run: |
    141142          docker-compose run --rm php composer --version
    142143
    143           # The PHPUnit 7.x phar is not compatible with PHP 8 and won't be updated,
    144           # as PHPUnit 7 is no longer supported. The Composer-installed PHPUnit should be
    145           # used for PHP 8 testing instead.
     144          # Install using `composer update` as there is no `composer.lock` file.
    146145          if [ ${{ env.LOCAL_PHP }} == '8.0-fpm' ]; then
    147             docker-compose run --rm php composer install --ignore-platform-reqs
    148             echo "PHPUNIT_SCRIPT=php-composer" >> $GITHUB_ENV
     146            docker-compose run --rm php composer update --ignore-platform-reqs
    149147          else
    150             docker-compose run --rm php composer install
     148            docker-compose run --rm php composer update
    151149          fi
    152150
     
    191189      - name: Run slow PHPUnit tests
    192190        if: ${{ matrix.split_slow }}
    193         run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c ${{ env.PHPUNIT_CONFIG }} --group ${{ env.SLOW_TESTS }}
     191        run: npm run test:php-composer -- --verbose -c ${{ env.PHPUNIT_CONFIG }} --group ${{ env.SLOW_TESTS }}
    194192
    195193      - name: Run PHPUnit tests for single site excluding slow tests
    196194        if: ${{ matrix.php < '7.0' && ! matrix.split_slow && ! matrix.multisite }}
    197         run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c ${{ env.PHPUNIT_CONFIG }} --exclude-group ${{ env.SLOW_TESTS }},ajax,ms-files,ms-required
     195        run: npm run test:php-composer -- --verbose -c ${{ env.PHPUNIT_CONFIG }} --exclude-group ${{ env.SLOW_TESTS }},ajax,ms-files,ms-required
    198196
    199197      - name: Run PHPUnit tests for Multisite excluding slow tests
    200198        if: ${{ matrix.php < '7.0' && ! matrix.split_slow && matrix.multisite }}
    201         run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c ${{ env.PHPUNIT_CONFIG }} --exclude-group ${{ env.SLOW_TESTS }},ajax,ms-files,ms-excluded,oembed-headers
     199        run: npm run test:php-composer -- --verbose -c ${{ env.PHPUNIT_CONFIG }} --exclude-group ${{ env.SLOW_TESTS }},ajax,ms-files,ms-excluded,oembed-headers
    202200
    203201      - name: Run PHPUnit tests
    204202        if: ${{ matrix.php >= '7.0' }}
    205         run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c ${{ env.PHPUNIT_CONFIG }}
     203        run: npm run test:php-composer -- --verbose -c ${{ env.PHPUNIT_CONFIG }}
    206204
    207205      - name: Run AJAX tests
    208206        if: ${{ ! matrix.split_slow }}
    209         run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c ${{ env.PHPUNIT_CONFIG }} --group ajax
     207        run: npm run test:php-composer -- --verbose -c ${{ env.PHPUNIT_CONFIG }} --group ajax
    210208
    211209      - name: Run ms-files tests as a multisite install
    212210        if: ${{ matrix.multisite && ! matrix.split_slow }}
    213         run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c tests/phpunit/multisite.xml --group ms-files
     211        run: npm run test:php-composer -- --verbose -c tests/phpunit/multisite.xml --group ms-files
    214212
    215213      - name: Run external HTTP tests
    216214        if: ${{ ! matrix.multisite && ! matrix.split_slow }}
    217         run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c phpunit.xml.dist --group external-http
     215        run: npm run test:php-composer -- --verbose -c phpunit.xml.dist --group external-http
    218216
    219217      # __fakegroup__ is excluded to force PHPUnit to ignore the <exclude> settings in phpunit.xml.dist.
    220218      - name: Run (xDebug) tests
    221219        if: ${{ ! matrix.split_slow }}
    222         run: LOCAL_PHP_XDEBUG=true npm run test:${{ env.PHPUNIT_SCRIPT }} -- -v --group xdebug --exclude-group __fakegroup__
     220        run: LOCAL_PHP_XDEBUG=true npm run test:php-composer -- -v --group xdebug --exclude-group __fakegroup__
    223221
    224222      - name: Ensure version-controlled files are not modified or deleted
  • trunk/.github/workflows/test-coverage.yml

    r51535 r51545  
    1919env:
    2020  PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: ${{ true }}
    21   COMPOSER_INSTALL: ${{ false }}
    22   # Controls which NPM script to use for running PHPUnit tests. Options ar `php` and `php-composer`.
    23   PHPUNIT_SCRIPT: php
    2421  LOCAL_PHP: '7.4-fpm'
    2522  LOCAL_PHP_XDEBUG: true
     
    8986        run: npm ci
    9087
     88      # This date is used to ensure that the Composer cache is refreshed at least once every week.
     89      # http://man7.org/linux/man-pages/man1/date.1.html
     90      - name: "Get last Monday's date"
     91        id: get-date
     92        run: echo "::set-output name=date::$(/bin/date -u --date='last Mon' "+%F")"
     93        shell: bash
     94
     95      - name: Get Composer cache directory
     96        id: composer-cache
     97        run: echo "::set-output name=dir::$(composer config cache-files-dir)"
     98
     99      - name: Cache Composer dependencies
     100        uses: actions/cache@26968a09c0ea4f3e233fdddbafd1166051a095f6 # v2.1.4
     101        env:
     102          cache-name: cache-composer-dependencies
     103        with:
     104          path: ${{ steps.composer-cache.outputs.dir }}
     105          key: ${{ runner.os }}-php-${{ matrix.php }}-date-${{ steps.get-date.outputs.date }}-composer-${{ hashFiles('**/composer.json') }}
     106
     107      - name: Install Composer dependencies
     108        run: |
     109          docker-compose run --rm php composer --version
     110
     111          # Install using `composer update` as there is no `composer.lock` file.
     112          docker-compose run --rm php composer update
     113
    91114      - name: Docker debug information
    92115        run: |
     
    122145      - name: Run tests as a single site
    123146        if: ${{ ! matrix.multisite }}
    124         run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c phpunit.xml.dist --coverage-clover wp-code-coverage-single-clover-${{ github.sha }}.xml
     147        run: npm run test:php-composer -- --verbose -c phpunit.xml.dist --coverage-clover wp-code-coverage-single-clover-${{ github.sha }}.xml
    125148
    126149      - name: Ensure version-controlled files are not modified during the tests
     
    136159      - name: Run tests as a multisite install
    137160        if: ${{ matrix.multisite }}
    138         run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c tests/phpunit/multisite.xml --coverage-clover wp-code-coverage-multisite-clover-${{ github.sha }}.xml
     161        run: npm run test:php-composer -- --verbose -c tests/phpunit/multisite.xml --coverage-clover wp-code-coverage-multisite-clover-${{ github.sha }}.xml
    139162
    140163      - name: Ensure version-controlled files are not modified during the tests
Note: See TracChangeset for help on using the changeset viewer.