Skip to content

Merge latest changes to feature branch #5097

Merge latest changes to feature branch

Merge latest changes to feature branch #5097

name: Unit Testing for Plugins
on:
push:
branches:
- trunk
- 'release/**'
# Only run if PHP-related files changed.
paths:
- '.github/workflows/php-test-plugins.yml'
- 'plugins/**.php'
- '.wp-env.json'
- '**/package.json'
- 'package-lock.json'
- 'phpunit.xml.dist'
- 'composer.json'
- 'composer.lock'
pull_request:
# Only run if PHP-related files changed.
paths:
- '.github/workflows/php-test-plugins.yml'
- 'plugins/**.php'
- '.wp-env.json'
- '**/package.json'
- 'package-lock.json'
- 'phpunit.xml.dist'
- 'composer.json'
- 'composer.lock'
types:
- opened
- reopened
- synchronize
# Cancel previous workflow run groups that have not completed.
concurrency:
# Group workflow runs by workflow name, along with the head branch ref of the pull request
# or otherwise the branch or tag ref.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
cancel-in-progress: true
# Disable permissions for all available scopes by default.
# Any needed permissions should be configured at the job level.
permissions: {}
jobs:
php-test-plugins:
name: 'PHP ${{ matrix.php }} / WP ${{ matrix.wp }}'
runs-on: ubuntu-latest
timeout-minutes: 20
permissions:
contents: read # Required to clone the repo.
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.0', '7.4']
wp: ['latest']
coverage: [false]
include:
- php: '7.4'
wp: '6.9'
- php: '8.3'
wp: 'trunk'
- php: '8.4'
wp: 'trunk'
- php: '8.5'
wp: 'trunk'
- php: '8.2'
phpunit: '^9.6'
wp: 'latest'
coverage: ${{ !startsWith(github.actor, 'dependabot') }}
env:
WP_ENV_PHP_VERSION: ${{ matrix.php }}
WP_ENV_CORE: ${{ matrix.wp == 'trunk' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', matrix.wp ) }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup Node.js (.nvmrc)
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version-file: '.nvmrc'
cache: npm
- name: npm install
run: npm ci
- name: Build assets
run: npm run build
- name: Install WordPress
run: |
if [ "${{ matrix.coverage }}" == "true" ]; then
npm run wp-env-test start -- --xdebug=coverage
else
npm run wp-env-test start
fi
- name: Composer Install
run: npm run wp-env-test run wordpress -- --env-cwd="wp-content/plugins/$(basename $(pwd))" composer install --no-interaction --no-progress
- name: Update Composer Dependencies
run: composer update --with-all-dependencies --no-interaction --no-progress
- name: Install PHPUnit
run: |
if [ "${{ matrix.php }}" == "8.2" ]; then
# Version 2.1.0 of doctrine/instantiator started requiring PHP 8.4: <https://github.com/doctrine/instantiator/pull/148>.
composer require phpunit/phpunit:${{ matrix.phpunit }} "doctrine/instantiator:<2.1" --with-all-dependencies --ignore-platform-reqs
else
composer require --dev phpunit/phpunit:${{ matrix.phpunit }}
fi
if: matrix.phpunit != ''
- name: Running single site unit tests
run: |
if [ "${{ matrix.coverage }}" == "true" ]; then
for plugin in $(jq -r '.plugins[]' plugins.json); do
npm run "test-php:$plugin" -- -- -- --coverage-clover="./single-site-reports/coverage-$plugin.xml"
done
else
npm run test-php
fi
- name: Running multisite unit tests
run: |
if [ "${{ matrix.coverage }}" == "true" ]; then
for plugin in $(jq -r '.plugins[]' plugins.json); do
npm run "test-php-multisite:$plugin" -- -- -- --coverage-clover="./multisite-reports/coverage-multisite-$plugin.xml"
done
else
npm run test-php-multisite
fi
- name: Upload single site coverage reports to Codecov
if: ${{ matrix.coverage == true }}
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v6.0.2
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./single-site-reports
flags: single
name: ${{ matrix.php }}-single-site-coverage
fail_ci_if_error: true
- name: Upload multisite coverage reports to Codecov
if: ${{ matrix.coverage == true }}
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v6.0.2
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./multisite-reports
flags: multisite
name: ${{ matrix.php }}-multisite-coverage
fail_ci_if_error: true