Make WordPress Core


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.