From 4554441cb6029b035384e6b9d4bbc947035b919c Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Fri, 13 Jan 2023 00:24:34 +0100 Subject: [PATCH] Move the unit tests to unit-test.yml. This is needed because: 1. unit-php job has to be preserved as it's set as required in the GH settings. 2. unit-php job now depends on the test-php job. --- .github/workflows/phpunit-tests.yml | 126 ---------------------------- .github/workflows/unit-test.yml | 123 +++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 126 deletions(-) delete mode 100644 .github/workflows/phpunit-tests.yml diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml deleted file mode 100644 index 8612b2b3ddbf73..00000000000000 --- a/.github/workflows/phpunit-tests.yml +++ /dev/null @@ -1,126 +0,0 @@ -name: PHPUnit Tests - -# Since Unit Tests are required to pass for each PR, -# we cannot disable them for documentation-only changes. -on: - pull_request: - push: - branches: - - trunk - - 'release/**' - - 'wp/**' - # Allow manually triggering the workflow. - workflow_dispatch: - -# Cancels all previous workflow runs for pull requests that have not completed. -concurrency: - # The concurrency group contains the workflow name and the branch name for pull requests - # or the commit hash for any other events. - group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} - cancel-in-progress: true - -jobs: - test-php: - name: ${{ matrix.php }}${{ matrix.multisite && ' multisite' || '' }} on ubuntu-latest - runs-on: ubuntu-latest - timeout-minutes: 20 - if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }} - strategy: - fail-fast: true - matrix: - php: - - '5.6' - - '7.0' - - '7.1' - - '7.2' - - '7.3' - - '7.4' - - '8.0' - - '8.1' - - '8.2' - multisite: [false, true] - - env: - WP_ENV_PHP_VERSION: ${{ matrix.php }} - - steps: - - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0 - - - name: Set up Node.js - uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.1 - with: - node-version-file: '.nvmrc' - cache: npm - - ## - # This allows Composer dependencies to be installed using a single step. - # - # Since the tests are currently run within the Docker containers where the PHP version varies, - # the same PHP version needs to be configured for the action runner machine so that the correct - # dependency versions are installed and cached. - ## - - name: Set up PHP - uses: shivammathur/setup-php@1a18b2267f80291a81ca1d33e7c851fe09e7dfc4 # v2.22.0 - with: - php-version: '${{ matrix.php }}' - ini-file: development - coverage: none - - # Ensure that Composer installs the correct versions of packages. - - name: Override PHP version in composer.json - run: composer config platform.php ${{ matrix.php }} - - # The spatie/phpunit-watcher package is not compatible with PHP < 7.2. - # It must be removed before running the tests. - - name: Remove incompatible Composer packages - if: ${{ matrix.php < '7.2' }} - run: composer remove spatie/phpunit-watcher --dev --no-update - - # Since Composer dependencies are installed using `composer update` and no lock file is in version control, - # passing a custom cache suffix ensures that the cache is flushed at least once per week. - - name: Install Composer dependencies - uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0 - with: - custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F") - - - name: Install npm dependencies - run: | - npm ci - npm run build - - - name: Docker debug information - run: | - docker -v - docker-compose -v - - - name: General debug information - run: | - npm --version - node --version - curl --version - git --version - svn --version - locale -a - - - name: Start Docker environment - run: npm run wp-env start - - - name: Log running Docker containers - run: docker ps -a - - - name: Docker container debug information - run: | - npm run wp-env run tests-mysql "mysql --version" - npm run wp-env run tests-wordpress "php --version" - npm run wp-env run tests-wordpress "php -m" - npm run wp-env run tests-wordpress "php -i" - npm run wp-env run tests-wordpress "/var/www/html/wp-content/plugins/gutenberg/vendor/bin/phpunit --version" - npm run wp-env run tests-wordpress "locale -a" - - - name: Running single site unit tests - if: ${{ ! matrix.multisite }} - run: npm run test:unit:php - - - name: Running multisite unit tests - if: ${{ matrix.multisite }} - run: npm run test:unit:php:multisite diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 3b68bfd57c0360..a14eb2c53f1594 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -9,6 +9,8 @@ on: - trunk - 'release/**' - 'wp/**' + # Allow manually triggering the workflow. + workflow_dispatch: # Cancels all previous workflow runs for pull requests that have not completed. concurrency: @@ -51,6 +53,127 @@ jobs: - name: Running the date tests run: npm run test:unit:date -- --ci --maxWorkers=2 --cacheDirectory="$HOME/.jest-cache" + test-php: + name: PHP ${{ matrix.php }}${{ matrix.multisite && ' multisite' || '' }} on ubuntu-latest + runs-on: ubuntu-latest + timeout-minutes: 20 + if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }} + strategy: + fail-fast: true + matrix: + php: + - '5.6' + - '7.0' + - '7.1' + - '7.2' + - '7.3' + - '7.4' + - '8.0' + - '8.1' + - '8.2' + multisite: [false, true] + + env: + WP_ENV_PHP_VERSION: ${{ matrix.php }} + + steps: + - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0 + + - name: Set up Node.js + uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.1 + with: + node-version-file: '.nvmrc' + cache: npm + + ## + # This allows Composer dependencies to be installed using a single step. + # + # Since the tests are currently run within the Docker containers where the PHP version varies, + # the same PHP version needs to be configured for the action runner machine so that the correct + # dependency versions are installed and cached. + ## + - name: Set up PHP + uses: shivammathur/setup-php@1a18b2267f80291a81ca1d33e7c851fe09e7dfc4 # v2.22.0 + with: + php-version: '${{ matrix.php }}' + ini-file: development + coverage: none + + # Ensure that Composer installs the correct versions of packages. + - name: Override PHP version in composer.json + run: composer config platform.php ${{ matrix.php }} + + # The spatie/phpunit-watcher package is not compatible with PHP < 7.2. + # It must be removed before running the tests. + - name: Remove incompatible Composer packages + if: ${{ matrix.php < '7.2' }} + run: composer remove spatie/phpunit-watcher --dev --no-update + + # Since Composer dependencies are installed using `composer update` and no lock file is in version control, + # passing a custom cache suffix ensures that the cache is flushed at least once per week. + - name: Install Composer dependencies + uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0 + with: + custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F") + + - name: Install npm dependencies + run: | + npm ci + npm run build + + - name: Docker debug information + run: | + docker -v + docker-compose -v + + - name: General debug information + run: | + npm --version + node --version + curl --version + git --version + svn --version + locale -a + + - name: Start Docker environment + run: npm run wp-env start + + - name: Log running Docker containers + run: docker ps -a + + - name: Docker container debug information + run: | + npm run wp-env run tests-mysql "mysql --version" + npm run wp-env run tests-wordpress "php --version" + npm run wp-env run tests-wordpress "php -m" + npm run wp-env run tests-wordpress "php -i" + npm run wp-env run tests-wordpress "/var/www/html/wp-content/plugins/gutenberg/vendor/bin/phpunit --version" + npm run wp-env run tests-wordpress "locale -a" + + - name: Running single site unit tests + if: ${{ ! matrix.multisite }} + run: npm run test:unit:php + + - name: Running multisite unit tests + if: ${{ matrix.multisite }} + run: npm run test:unit:php:multisite + + # This job is deprecated but should temporarily be present for compatibility reasons. + # All PHPUnit checks have been moved to the "test-php" job. + unit-php: + name: PHP + runs-on: ubuntu-latest + needs: test-php + if: always() + steps: + - name: Fail the job if the PHPUnit tests fail + if: needs.test-php.result != 'success' + run: exit 1 + + - name: Mark the job as passed if the PHPUnit tests pass + if: needs.test-php.result == 'success' + run: exit 0 + mobile-unit-js: name: Mobile runs-on: ubuntu-latest