diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index aba74879f0..b368524ca5 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -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 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 diff --git a/.github/workflows/test-coverage.yml b/.github/workflows/test-coverage.yml index e82fa1e1e4..3c804c5ca6 100644 --- a/.github/workflows/test-coverage.yml +++ b/.github/workflows/test-coverage.yml @@ -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