Skip to content

Commit

Permalink
Merge pull request #18230 from Yoast/JRF/switch-to-ghactions-step-6
Browse files Browse the repository at this point in the history
Switch to GH Actions - step 6: integration tests
  • Loading branch information
diedexx committed Mar 17, 2022
2 parents 78d9d7c + 451af0b commit 9582b85
Show file tree
Hide file tree
Showing 6 changed files with 439 additions and 140 deletions.
176 changes: 176 additions & 0 deletions .github/workflows/integrationtest.yml
@@ -0,0 +1,176 @@
name: Integration Test

on:
# Run on pushes to select branches and on all pull requests.
push:
branches:
- master
- trunk
- 'release/**'
- 'hotfix/[0-9]+.[0-9]+*'
- 'feature/**'
pull_request:
# Allow manually triggering the workflow.
workflow_dispatch:

# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
integration-test:
runs-on: ubuntu-latest

strategy:
matrix:
include:
- php_version: '5.6'
wp_version: '5.8'
multisite: true

- php_version: '7.0'
wp_version: 'latest'
multisite: false

- php_version: '7.3'
wp_version: 'trunk'
multisite: true

- php_version: '7.4'
wp_version: 'latest'
multisite: false

# WP 5.6 is the earliest version which (sort of) supports PHP 8.0.
- php_version: '8.0'
wp_version: '5.8'
multisite: false

# WP 5.9 is the earliest version which (sort of) supports PHP 8.1.
- php_version: '8.1'
wp_version: 'latest'
multisite: true

name: "Integration Test: PHP ${{ matrix.php_version }} | WP ${{ matrix.wp_version }}${{ matrix.multisite == true && ' (+ ms)' || '' }}"

# Allow builds to fail on as-of-yet unreleased WordPress versions.
continue-on-error: ${{ matrix.wp_version == 'trunk' }}

services:
mysql:
# Use MySQL 5.6 for PHP 5.6, use MySQL 5.7 for PHP 7.0 < 7.4, otherwise MySQL 8.0.
# Also see: https://core.trac.wordpress.org/ticket/52496
image: mysql:${{ ( matrix.php_version == '5.6' && '5.6' ) || ( matrix.php_version < '7.4' && '5.7' ) || '8.0' }}
env:
MYSQL_ALLOW_EMPTY_PASSWORD: false
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=10s --health-retries=10

steps:
- name: Checkout code
uses: actions/checkout@v3

# The prefix-dependencies task makes use of reflection-based PHP code that only works on PHP > 7.2.
- name: Install PHP 7.x for generating the vendor_prefixed directory and dependency injection
uses: shivammathur/setup-php@v2
with:
php-version: 7.2
coverage: none

- name: Install Composer dependencies, generate vendor_prefixed directory and run dependency injection
uses: ramsey/composer-install@v2

# Remove packages which are not PHP cross-version compatible and only used for the prefixing.
# - humbug/php-scoper is only needed to actually do the prefixing, so won't be shipped anyway.
# - league/oauth2-client and its dependencies *are* the packages being prefixed.
- name: Delete dependencies which are not cross-version compatible
run: composer remove --dev --no-scripts humbug/php-scoper league/oauth2-client

- name: Remove vendor directory
run: rm -rf vendor/*

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_version }}
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
coverage: none

# Determine the type of Composer install which is needed.
# 1: WP 5.9 or higher - all PHPUnit versions needed are supported, use the most appropriate one.
# 2. WP < 5.9 with PHP 8.0 or higher - PHPUnit 5 - 7 supported, locked at 5.x, but needs upgrade to 7 for PHP >= 8.0.
# 3. WP < 5.9 with PHP < 8.0 - just use the locked PHPUnit 5 version.
- name: Determine the type of Composer install to use
id: composer_toggle
run: |
if [[ "${{ matrix.wp_version }}" =~ ^(trunk|latest|5\.9|[6789]\.[0-9])$ ]]; then
echo '::set-output name=TYPE::1'
elif [[ "${{ matrix.php_version }}" > "7.4" ]]; then
echo '::set-output name=TYPE::2'
else
echo '::set-output name=TYPE::3'
fi
- name: Debug info - show type determined
run: echo ${{ steps.composer_toggle.outputs.TYPE }}

# Install dependencies and handle caching in one go.
# Includes updating the test dependencies to the most appropriate version
# for the PHP/WP version combination on which the tests will be run.
# @link https://github.com/marketplace/actions/install-composer-dependencies

### Install type 1.
- name: "Install type 1: remove PHPUnit root requirement"
if: ${{ steps.composer_toggle.outputs.TYPE == '1' }}
run: composer remove --dev phpunit/phpunit --no-update --no-scripts

- name: "Install type 1: install Composer dependencies - WP 5.9 or higher"
if: ${{ steps.composer_toggle.outputs.TYPE == '1' }}
uses: ramsey/composer-install@v2
with:
# Force a `composer update` run.
dependency-versions: "highest"
# But make it selective.
composer-options: "yoast/wp-test-utils --with-dependencies --no-scripts"

### Install type 2.
- name: "Install type 2: conditionally require a higher PHPUnit version"
if: ${{ steps.composer_toggle.outputs.TYPE == '2' }}
run: composer require --dev phpunit/phpunit:"^7.5" --no-update --ignore-platform-req=php --no-scripts

- name: "Install type 2: install Composer dependencies - WP < 5.9 with PHP >= 8.0"
if: ${{ steps.composer_toggle.outputs.TYPE == '2' }}
uses: ramsey/composer-install@v2
with:
# Force a `composer update` run.
dependency-versions: "highest"
# But make it selective.
composer-options: "yoast/wp-test-utils phpunit/phpunit --with-dependencies --no-scripts --ignore-platform-req=php"

### Install type 3.
# As PHPUnit is a root requirement and some of the PHPUnit dependencies are locked at versions incompatible
# with all supported PHP versions, the PHPUnit dependency needs to explicitly also be allowed to update
# (within the version constraints as per the `composer.json` file, i.e. PHPUnit 5.7).
- name: "Install type 3: install Composer dependencies - WP < 5.9 with PHP < 8.0"
if: ${{ steps.composer_toggle.outputs.TYPE == '3' }}
uses: ramsey/composer-install@v2
with:
# Force a `composer update` run.
dependency-versions: "highest"
# But make it selective.
composer-options: "yoast/wp-test-utils phpunit/phpunit --with-dependencies --no-scripts"

- name: Install WP
shell: bash
run: config/scripts/install-wp-tests.sh wordpress_test root '' 127.0.0.1:3306 ${{ matrix.wp_version }}

- name: Run unit tests - single site
run: composer integration-test

- name: Run unit tests - multisite
if: ${{ matrix.multisite == true }}
run: composer integration-test
env:
WP_MULTISITE: 1
135 changes: 4 additions & 131 deletions .travis.yml
Expand Up @@ -2,9 +2,6 @@ os: linux
dist: xenial
language: php

services:
- mysql

branches:
only:
- master
Expand All @@ -15,33 +12,13 @@ branches:
# Also build tags like 1.1.1 or 1.1 for deployment.
- /^\d+\.\d+(\.\d+)?(-\S*)?$/

stages:
# Don't run the test steps on tag builds, this makes tag deployments a ton faster.
- name: test
if: NOT tag is present
- 🚀 deployment

jobs:
fast_finish: true
include:
- php: 7.3.24
env: WP_VERSION=latest WP_MULTISITE=1 COVERAGE=1
- php: 5.6
env: WP_VERSION=5.8 WP_MULTISITE=1 PHPUNIT=1
# Use 'trusty' to test against MySQL 5.6, 'xenial' contains 5.7 by default.
dist: trusty
- php: 7.3
env: WP_VERSION=trunk PHPUNIT=1
- php: 7.4
env: WP_VERSION=latest PHPUNIT=1
- php: 8.0
env: WP_VERSION=latest PHPUNIT=1
- php: "nightly"
- stage: 🚀 deployment
name: "Deploy to S3"
if: branch = deploy # Only build when on the `deploy` branch, this functionality is not used yet and is taking a long time to complete.
env: SC_ATTR=wordpress-seo
before_script: skip
script: grunt artifact
install:
- yarn global add grunt-cli
Expand All @@ -66,7 +43,6 @@ jobs:
install:
- yarn global add grunt-cli
- yarn install
before_script: skip
script:
- |
if [[ ! -z "$TRAVIS_TAG" ]]; then
Expand All @@ -93,25 +69,18 @@ jobs:
repo: $TRAVIS_REPO_SLUG
all_branches: true

allow_failures:
# Allow failures for unstable builds.
- php: "nightly"
- php: 7.3
env: WP_VERSION=trunk PHPUNIT=1

cache:
yarn: true
directories:
- $HOME/.composer/cache
- node_modules

before_install:
- if [[ -z "$CC_TEST_REPORTER_ID" ]]; then COVERAGE="0"; fi
- if [[ "$COVERAGE" != "1" ]]; then phpenv config-rm xdebug.ini || echo 'No xdebug config.'; fi
- phpenv config-rm xdebug.ini || echo 'No xdebug config.'

install:
- |
if [[ "$PHPUNIT" == "1" || "$COVERAGE" == "1" || "$TRAVIS_BUILD_STAGE_NAME" == "🚀 deployment" ]]; then
if [[ "$TRAVIS_BUILD_STAGE_NAME" == "🚀 deployment" ]]; then
# The prefix-dependencies task only works on PHP 7.1 and we need to prefix our dependencies to accurately test them.
# So we temporarily switch PHP versions, do a full install and then remove the package.
# Then switch back to the PHP version we want to test and delete the vendor directory.
Expand All @@ -126,110 +95,14 @@ install:
rm -rf vendor/*
fi
- |
if [[ "$COVERAGE" == "1" ]]; then
# Install phpcov so we can combine the coverage results of unit and integration tests.
travis_retry composer require phpunit/phpcov ^3.1 --no-interaction
fi
- |
if [[ ${TRAVIS_PHP_VERSION:0:1} == "8" || $TRAVIS_PHP_VERSION == "nightly" ]]; then
travis_retry composer install --no-interaction --ignore-platform-reqs --no-scripts --no-suggest
elif [[ "$PHPUNIT" == "1" || "$COVERAGE" == "1" ]]; then
# Run composer update as we have dev dependencies locked at PHP ^7.0 versions.
travis_retry composer update --no-interaction --no-scripts
travis_retry composer install --no-interaction --no-scripts
travis_retry composer du --no-scripts
elif [[ "$TRAVIS_BUILD_STAGE_NAME" == "🚀 deployment" ]]; then
if [[ "$TRAVIS_BUILD_STAGE_NAME" == "🚀 deployment" ]]; then
travis_retry composer update --no-interaction
travis_retry composer install --no-dev --no-interaction
composer du
fi
before_script:
# Careful: The HTTPS version of the following URL is different, therefore we need to use HTTP.
- |
if [[ "$PHPUNIT" == "1" || "$COVERAGE" == "1" ]]; then
if [[ "$WP_VERSION" == "latest" ]]; then
curl -s http://api.wordpress.org/core/version-check/1.7/ > /tmp/wp-latest.json
WP_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
fi
PLUGIN_SLUG=$(basename $(pwd))
export WP_DEVELOP_DIR=/tmp/wordpress/
git clone --depth=1 --branch="$WP_VERSION" git://develop.git.wordpress.org/ /tmp/wordpress
cd ..
cp -r "$PLUGIN_SLUG" "/tmp/wordpress/src/wp-content/plugins/$PLUGIN_SLUG"
cd /tmp/wordpress/
cp wp-tests-config-sample.php wp-tests-config.php
sed -i "s/youremptytestdbnamehere/wordpress_tests/" wp-tests-config.php
sed -i "s/yourusernamehere/travis/" wp-tests-config.php
sed -i "s/yourpasswordhere//" wp-tests-config.php
mysql -e "CREATE DATABASE wordpress_tests;" -uroot
cd "/tmp/wordpress/src/wp-content/plugins/$PLUGIN_SLUG"
mkdir src/generated/assets
echo "<?php return [ 'post-edit.js' => [ 'dependencies' => [], 'version' => 'test' ], 'installation-success.js' => [ 'dependencies' => [], 'version' => 'test' ], 'workouts.js' => [ 'dependencies' => [], 'version' => 'test' ] ];" >> src/generated/assets/plugin.php
echo "<?php return [];" >> src/generated/assets/externals.php
echo "<?php return [];" >> src/generated/assets/languages.php
fi
- phpenv rehash
- |
if [[ "$COVERAGE" == "1" ]]; then
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build
mkdir -p /tmp/coverage
fi
- export -f travis_fold
- export -f travis_time_start
- export -f travis_time_finish
- mysql --version
- phpenv versions
- php --version
- php -m
- curl --version
- git --version
- svn --version
- locale -a

script:
# PHP Unit
- |
if [[ "$PHPUNIT" == "1" && ${TRAVIS_PHP_VERSION:0:1} != "8" && $TRAVIS_PHP_VERSION != "nightly" ]]; then
# PHP < 8
travis_fold start "PHP.integration-tests" && travis_time_start
vendor/bin/phpunit -c phpunit-integration.xml.dist
travis_time_finish && travis_fold end "PHP.integration-tests"
elif [[ "$PHPUNIT" == "1" ]] && [[ ${TRAVIS_PHP_VERSION:0:1} == "8" || $TRAVIS_PHP_VERSION == "nightly" ]] && [[ ${WP_VERSION:0:3} == "5.9" || ${WP_VERSION:0:1} == "6" || $WP_VERSION == "trunk" ]]; then
# PHP >= 8 with WP >= 5.9
travis_fold start "PHP.integration-tests" && travis_time_start
travis_retry composer remove --dev phpunit/phpunit --no-update --no-interaction &&
travis_retry composer update yoast/wp-test-utils --no-interaction --with-dependencies --ignore-platform-req=php &&
vendor/bin/phpunit -c phpunit-integration.xml.dist
travis_time_finish && travis_fold end "PHP.integration-tests"
elif [[ "$PHPUNIT" == "1" ]] && [[ ${TRAVIS_PHP_VERSION:0:1} == "8" || $TRAVIS_PHP_VERSION == "nightly" ]]; then
# PHP >= 8 with WP < 5.9
travis_fold start "PHP.integration-tests" && travis_time_start
travis_retry composer require --dev phpunit/phpunit:"^7.5" --update-with-dependencies --ignore-platform-reqs --no-interaction &&
vendor/bin/phpunit -c phpunit-integration.xml.dist
travis_time_finish && travis_fold end "PHP.integration-tests"
fi
- |
if [[ "$COVERAGE" == "1" ]]; then
travis_fold start "PHP.coverage" && travis_time_start
vendor/bin/phpunit -c phpunit-integration.xml.dist --coverage-php /tmp/coverage/integration-tests.cov
travis_time_finish && travis_fold end "PHP.coverage"
fi
- |
if [[ "$COVERAGE" == "1" ]]; then
travis_fold start "PHP.coverage" && travis_time_start
vendor/bin/phpunit --coverage-php /tmp/coverage/tests.cov
travis_time_finish && travis_fold end "PHP.coverage"
fi
after_script:
- |
if [[ "$COVERAGE" == "1" ]]; then
./vendor/bin/phpcov merge /tmp/coverage --clover build/logs/clover.xml
fi
- if [[ "$COVERAGE" == "1" ]]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi
- git status

notifications:
slack:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -5,7 +5,7 @@
[![LintJS](https://github.com/Yoast/wordpress-seo/actions/workflows/jslint.yml/badge.svg)](https://github.com/Yoast/wordpress-seo/actions/workflows/jslint.yml)
[![TestJS](https://github.com/Yoast/wordpress-seo/actions/workflows/jstest.yml/badge.svg)](https://github.com/Yoast/wordpress-seo/actions/workflows/jstest.yml)
[![Unit Tests](https://github.com/Yoast/wordpress-seo/actions/workflows/unittest.yml/badge.svg)](https://github.com/Yoast/wordpress-seo/actions/workflows/unittest.yml)
[![Build Status](https://api.travis-ci.com/Yoast/wordpress-seo.svg?branch=master)](https://travis-ci.com/Yoast/wordpress-seo)
[![Integration Tests](https://github.com/Yoast/wordpress-seo/actions/workflows/integrationtest.yml/badge.svg)](https://github.com/Yoast/wordpress-seo/actions/workflows/integrationtest.yml)
[![Stable Version](https://poser.pugx.org/yoast/wordpress-seo/v/stable.svg)](https://packagist.org/packages/yoast/wordpress-seo)
[![License](https://poser.pugx.org/yoast/wordpress-seo/license.svg)](https://packagist.org/packages/yoast/wordpress-seo)

Expand Down

0 comments on commit 9582b85

Please sign in to comment.