Skip to content

[WIP] Add performance tests #46

[WIP] Add performance tests

[WIP] Add performance tests #46

Workflow file for this run

name: Lint and Test
on:
push:
branches:
- main
pull_request:
jobs:
lint-js:
name: JS Lints
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: npm
- name: Install dependencies
run: npm ci
- name: Lint JS
run: npm run lint
lint-php:
name: PHP Lints
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: none
tools: composer, cs2pr
- name: Get Composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Setup Composer cache
uses: pat-s/always-upload-cache@v3.0.11
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
${{ runner.os }}-
- name: Validate composer.json
run: composer validate --no-check-all --strict
- name: Install dependencies
run: composer install
# So PHPStan uses information from the latest version
- name: Update PHPUnit
run: |
composer update --ignore-platform-reqs --no-interaction --no-scripts yoast/phpunit-polyfills --with-dependencies
- name: Lint PHP
run: composer lint
- name: PHPStan
run: composer phpstan
unit-php:
name: 'PHP ${{ matrix.php }} - WP ${{ matrix.wp }}'
runs-on: ubuntu-latest
services:
mysql:
image: mariadb:latest
env:
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: true
MARIADB_DATABASE: wordpress_test
MARIADB_MYSQL_LOCALHOST_USER: 1
MARIADB_MYSQL_LOCALHOST_GRANTS: USAGE
ports:
- 3306
options: --health-cmd="healthcheck.sh --su-mysql --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3
continue-on-error: ${{ matrix.experimental }}
strategy:
matrix:
php: ['7.4', '7.3.', '7.2', '7.1', '7.0', '5.6']
wp: ['latest']
coverage: [false]
experimental: [false]
include:
- php: '8.0'
wp: 'latest'
coverage: true
experimental: false
- php: '7.4'
wp: 'trunk'
experimental: true
- php: '8.1'
wp: 'trunk'
experimental: true
- php: '8.2'
wp: 'trunk'
experimental: true
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mysql
coverage: xdebug
tools: composer, cs2pr
- name: Install PHP dependencies
uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6
with:
composer-options: '--prefer-dist --no-scripts'
- name: Shutdown default MySQL service
run: sudo service mysql stop
- name: Set up tests
run: bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1:${{ job.services.mysql.ports['3306'] }} ${{ matrix.wp }} true
# Installs a different PHPUnit version depending on the WP/PHP version combo we're testing against.
#
# | WP / PHP | PHPUnit |
# |-----------|---------|
# | * / 5.6 | 5 |
# | * / 7.4 | 9 |
# | * / 8 | 9 |
#
# See https://make.wordpress.org/core/handbook/references/phpunit-compatibility-and-wordpress-versions/
- name: Update PHPUnit
run: |
if [[ $PHP_VERSION == "7.4" || $PHP_VERSION == "8.0" || $PHP_VERSION == "8.1" || $PHP_VERSION == "8.2" ]]; then
echo "Installing latest version of PHPUnit"
composer update --ignore-platform-reqs --no-interaction --no-scripts yoast/phpunit-polyfills --with-dependencies
fi
env:
WP_VERSION: ${{ matrix.wp }}
PHP_VERSION: ${{ matrix.php }}
- name: Run tests
run: composer test
if: ${{ ! matrix.coverage }}
- name: Run tests with coverage
run: composer test:coverage
if: ${{ matrix.coverage }}
- name: Upload code coverage report
uses: codecov/codecov-action@v3.1.4
with:
file: coverage.xml
flags: default
if: ${{ matrix.coverage }}
- name: Upload code coverage report
uses: codecov/codecov-action@v3.1.4
with:
file: coverage-integration.xml
flags: default
if: ${{ matrix.coverage }}
- name: Upload code coverage report
uses: codecov/codecov-action@v3.1.4
with:
file: coverage-integration-multisite.xml
flags: multisite
if: ${{ matrix.coverage }}
e2e-tests:
name: 'E2E Tests (${{ matrix.wp }})'
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental == true }}
strategy:
fail-fast: false
matrix:
wp: ['latest']
experimental: [false]
include:
- wp: 'trunk'
experimental: true
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: npm
- name: Install dependencies
run: npm ci
- name: Configure WordPress version
run: |
if [[ $WP_VERSION == 'trunk' ]]; then
echo "Using WordPress trunk"
echo "{\"core\":\"WordPress/WordPress#master\"}" >> .wp-env.override.json
fi
env:
WP_VERSION: ${{ matrix.wp }}
- name: Install WordPress
run: |
chmod -R 767 ./ # TODO: Possibly integrate in wp-env
npm run wp-env start
# Ensure the wp-content/languages folder exists and is writable.
# See https://github.com/WordPress/gutenberg/issues/22515
# and https://github.com/WordPress/gutenberg/tree/trunk/packages/env#installing-a-plugin-or-theme-on-the-development-instance
- name: Install languages
run: |
WP_ENV_DIR=$(npm run wp-env install-path --silent 2>&1 | head -1)
cd $WP_ENV_DIR
mkdir -p tests-WordPress/wp-content/languages tests-WordPress/wp-content/upgrade
chmod -R 767 tests-WordPress/wp-content/languages tests-WordPress/wp-content/upgrade
docker-compose run --rm -u $(id -u) -e HOME=/tmp tests-cli wp language core install de_DE es_ES fr_FR it_IT
docker-compose run --rm -u $(id -u) -e HOME=/tmp tests-cli wp language plugin update --all
docker-compose run --rm -u $(id -u) -e HOME=/tmp tests-cli wp language theme update --all
cd -
- name: Run tests
run: npm run test:e2e -- --runInBand
- name: Archive debug artifacts (screenshots, HTML snapshots)
uses: actions/upload-artifact@v3
if: always()
with:
name: failures-artifacts
path: artifacts
core-php:
name: 'WP core tests'
runs-on: ubuntu-latest
services:
mysql:
image: mariadb:latest
env:
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: true
MARIADB_DATABASE: wordpress_test
MARIADB_MYSQL_LOCALHOST_USER: 1
MARIADB_MYSQL_LOCALHOST_GRANTS: USAGE
ports:
- 3306
options: --health-cmd="healthcheck.sh --su-mysql --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Checkout
uses: actions/checkout@v3
with:
repository: 'wordpress/wordpress-develop'
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
extensions: mysql
coverage: none
tools: composer
- name: Install PHP dependencies
uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6
with:
composer-options: '--prefer-dist'
dependency-versions: 'highest'
- name: Shutdown default MySQL service
run: sudo service mysql stop
- name: Set up tests config
run: |
cp wp-tests-config-sample.php wp-tests-config.php
sed -i.bak "s/youremptytestdbnamehere/$DB_NAME/" wp-tests-config.php
sed -i.bak "s/yourusernamehere/$DB_USER/" wp-tests-config.php
sed -i.bak "s/yourpasswordhere/$DB_PASS/" wp-tests-config.php
sed -i.bak "s|localhost|${DB_HOST}|" wp-tests-config.php
cat wp-tests-config.php
env:
DB_NAME: wordpress_test
DB_USER: root
DB_PASSWORD: ''
DB_HOST: 127.0.0.1:${{ job.services.mysql.ports['3306'] }}
- name: Checkout Ginger-MO
uses: actions/checkout@v3
with:
path: 'src/wp-content/plugins/ginger-mo'
- name: Load Ginger-MO for tests
run: |
echo "require dirname( __DIR__, 3 ) . '/src/wp-content/plugins/ginger-mo/ginger-mo.php';" >> tests/phpunit/includes/bootstrap.php
- name: Run tests
run: vendor/bin/phpunit --group=l10n,i18n,pomo
performance-tests:
name: 'Performance Tests (${{ matrix.wp }})'
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental == true }}
strategy:
fail-fast: false
matrix:
wp: ['latest']
experimental: [false]
include:
- wp: 'trunk'
experimental: true
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: npm
- name: Install dependencies
run: npm ci
- name: Configure WordPress version
run: |
if [[ $WP_VERSION == 'trunk' ]]; then
echo "Using WordPress trunk"
echo "{\"core\":\"WordPress/WordPress#master\"}" >> .wp-env.override.json
fi
env:
WP_VERSION: ${{ matrix.wp }}
- name: Install WordPress
run: |
chmod -R 767 ./ # TODO: Possibly integrate in wp-env
npm run wp-env start
- name: Import mock data
run: |
npm run wp-env run tests-cli curl https://raw.githubusercontent.com/WordPress/theme-test-data/b9752e0533a5acbb876951a8cbb5bcc69a56474c/themeunittestdata.wordpress.xml -- --output /tmp/themeunittestdata.wordpress.xml
npm run wp-env run tests-cli wp import /tmp/themeunittestdata.wordpress.xml -- --authors=create
rm themeunittestdata.wordpress.xml
- name: Update permalink structure
run: |
npm run wp-env run tests-cli wp rewrite structure '/%postname%/'
# Ensure the wp-content/languages folder exists and is writable.
# See https://github.com/WordPress/gutenberg/issues/22515
# and https://github.com/WordPress/gutenberg/tree/trunk/packages/env#installing-a-plugin-or-theme-on-the-development-instance
- name: Install languages
run: |
WP_ENV_DIR=$(npm run wp-env install-path --silent 2>&1 | head -1)
cd $WP_ENV_DIR
mkdir -p tests-WordPress/wp-content/languages tests-WordPress/wp-content/upgrade
chmod -R 767 tests-WordPress/wp-content/languages tests-WordPress/wp-content/upgrade
docker-compose run --rm -u $(id -u) -e HOME=/tmp tests-cli wp language core install de_DE es_ES fr_FR it_IT
docker-compose run --rm -u $(id -u) -e HOME=/tmp tests-cli wp language plugin update --all
docker-compose run --rm -u $(id -u) -e HOME=/tmp tests-cli wp language theme update --all
cd -
- name: Run tests
run: npm run test:performance
- name: Print performance tests results
run: 'node ./tests/performance/results.js'
- name: Check if a comment was already made
id: find-comment
uses: peter-evans/find-comment@a54c31d7fa095754bfef525c0c8e5e5674c4b4b1
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: swissspidy
body-includes: Performance test results for
- name: Get comment body
id: get-comment-body
# Setting a multi-line output requires escaping line-feeds. See <https://github.community/t/set-output-truncates-multiline-strings/16852/3>.
run: |
echo 'COMMENT_BODY<<EOF' >> $GITHUB_ENV
echo 'Performance test results for ${{ github.event.pull_request.head.sha }} are in :bellhop_bell:!' >> $GITHUB_ENV
cat tests/performance/specs/summary.md >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Create or update comment on PR with links to plugin builds
uses: peter-evans/create-or-update-comment@c6c9a1a66007646a28c153e2a8580a5bad27bcfa
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body: ${{ env.COMMENT_BODY }}
- name: Add workflow summary
run: |
echo $COMMENT_BODY >> $GITHUB_STEP_SUMMARY
- name: Archive debug artifacts (screenshots, HTML snapshots)
uses: actions/upload-artifact@v3
if: always()
with:
name: failures-artifacts
path: artifacts