Skip to content

Version 5: enhanced block editing and self-hosting #459

Version 5: enhanced block editing and self-hosting

Version 5: enhanced block editing and self-hosting #459

Workflow file for this run

name: PHP Tests
on:
push:
branches:
- "**"
pull_request:
branches: [master]
env:
# Seems like we should be able to use these in the services section below
# to keep things DRY, but how?
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpressdb
MYSQL_USER: wordpress
MYSQL_PASSWORD: password
MYSQL_PORT: 3306
MYSQL_HOST: 127.0.0.1
jobs:
build:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpressdb
MYSQL_USER: wordpress
MYSQL_PASSWORD: password
ports:
- 3306:3306
strategy:
matrix:
php: ["7.4", "8.0", "8.1", "8.2", "8.3"]
wordpress: [latest]
include:
- php: "8.3"
wordpress: trunk
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- name: Validate composer.json and composer.lock
id: composer-lock
run: |
if [ ${{ matrix.php }} == '8.2' ]; then
composer validate
LOCK_FILE=composer.lock
COMPOSER_FILE=composer.json
else
COMPOSER=composer-php${{ matrix.php }}.json composer validate
LOCK_FILE=composer-php${{ matrix.php }}.lock
COMPOSER_FILE=composer-php${{ matrix.php }}.json
fi
echo "COMPOSER_LOCK_HASH=$(md5sum $LOCK_FILE | cut -d' ' -f1)" >> $GITHUB_OUTPUT
echo "COMPOSER_FILE=${COMPOSER_FILE}" >> $GITHUB_OUTPUT
- name: Resolve Cache Date
id: cache-date
run: echo "DATE=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-b-${{ steps.composer-lock.outputs.COMPOSER_LOCK_HASH }}
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: COMPOSER=${{ steps.composer-lock.outputs.COMPOSER_FILE }} composer install --prefer-dist --no-progress
- name: Cache APT Sources Daily
id: apt-sources-cache
uses: actions/cache@v3
with:
path: /tmp/apt-sources-${{ steps.cache-date.outputs.DATE }}
key: ${{ runner.os }}-apt-sources-${{ steps.cache-date.outputs.DATE }}
- name: Cache APT Packages Daily
id: apt-packages-cache
uses: actions/cache@v3
with:
path: /tmp/apt-packages-${{ steps.cache-date.outputs.DATE }}
key: ${{ runner.os }}-apt-packages-${{ steps.cache-date.outputs.DATE }}
- name: Update APT Sources
if: steps.apt-sources-cache.outputs.cache-hit != 'true'
run: |
sudo apt-get update
mkdir -p /tmp/apt-sources-${{ steps.cache-date.outputs.DATE }}
sudo cp -R /var/lib/apt/lists/* /tmp/apt-sources-${{ steps.cache-date.outputs.DATE }}
- name: Download APT Packages
if: steps.apt-packages-cache.outputs.cache-hit != 'true'
run: |
sudo cp -R /tmp/apt-sources-${{ steps.cache-date.outputs.DATE }}/* /var/lib/apt/lists
sudo apt-get install -y --download-only subversion mysql-client
sudo mkdir -p /tmp/apt-packages-${{ steps.cache-date.outputs.DATE }}
sudo cp -R /var/cache/apt/archives/*.deb /tmp/apt-packages-${{ steps.cache-date.outputs.DATE }}
- name: Install OS Packages
run: sudo dpkg -i /tmp/apt-packages-${{ steps.cache-date.outputs.DATE }}/*.deb
- name: Verify DB
run: mysql --user=root --password=${MYSQL_ROOT_PASSWORD} --host=${MYSQL_HOST} --port=${MYSQL_PORT} --protocol=tcp -e 'SHOW DATABASES;'
- name: Resolve WordPress Version
run: |
curl -s https://api.wordpress.org/core/version-check/1.7/ > /tmp/wp-latest.json
LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//' | head -1)
if [ "${{ matrix.wordpress }}" == 'latest' ]; then
VERSION=$LATEST_VERSION
echo "WORDPRESS_VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "WORDPRESS_VERSION_IS_TRUNK=0" >> $GITHUB_OUTPUT
echo "WORDPRESS_CORE_DIR=/tmp/$VERSION" >> $GITHUB_OUTPUT
echo "WP_TESTS_TAG=branches/$VERSION" >> $GITHUB_OUTPUT
elif [ "${{ matrix.wordpress }}" == 'trunk' ]; then
VERSION=trunk-$(date +'%Y-%m-%d')
echo "WORDPRESS_VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "WORDPRESS_VERSION_IS_TRUNK=1" >> $GITHUB_OUTPUT
echo "WORDPRESS_CORE_DIR=/tmp/$VERSION" >> $GITHUB_OUTPUT
echo "WP_TESTS_TAG=trunk" >> $GITHUB_OUTPUT
else
VERSION=${{ matrix.wordpress }}
echo "WORDPRESS_VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "WORDPRESS_VERSION_IS_TRUNK=0" >> $GITHUB_OUTPUT
echo "WORDPRESS_CORE_DIR=/tmp/$VERSION" >> $GITHUB_OUTPUT
fi
if [[ $VERSION =~ ^[0-9]+\.[0-9]+\-(beta|RC)[0-9]+$ ]]; then
WP_BRANCH=${VERSION%\-*}
echo "WP_TESTS_TAG=branches/$WP_BRANCH" >> $GITHUB_OUTPUT
elif [[ $VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then
echo "WP_TESTS_TAG=branches/$VERSION" >> $GITHUB_OUTPUT
elif [[ $VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
if [[ $VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
echo "WP_TESTS_TAG=tags/${VERSION%??}" >> $GITHUB_OUTPUT
else
echo "WP_TESTS_TAG=tags/$VERSION" >> $GITHUB_OUTPUT
fi
elif [[ $VERSION == 'nightly' || $VERSION == 'trunk' ]]; then
echo "WP_TESTS_TAG=trunk" >> $GITHUB_OUTPUT
else
echo "WP_TESTS_TAG=tags/$LATEST_VERSION" >> $GITHUB_OUTPUT
fi
echo "WP_TESTS_DIR=/tmp/test/$VERSION" >> $GITHUB_OUTPUT
id: wordpress-version
- name: Show WordPress Version
run: echo "The current WordPress version is ${{ steps.wordpress-version.outputs.WORDPRESS_VERSION }}, and WP_TESTS_TAG=${{ steps.wordpress-version.outputs.WP_TESTS_TAG }}"
- name: Cache WordPress Core Installation
id: wordpress-cache
uses: actions/cache@v3
with:
path: ${{ steps.wordpress-version.outputs.WORDPRESS_CORE_DIR }}
key: ${{ runner.os }}-wordpress-${{ steps.wordpress-version.outputs.WORDPRESS_VERSION }}') }}
- name: Install WordPress Core
if: steps.wordpress-cache.outputs.cache-hit != 'true'
run: |
mkdir -p ${{ steps.wordpress-version.outputs.WORDPRESS_CORE_DIR }}
if [ "${{ steps.wordpress-version.outputs.WORDPRESS_VERSION_IS_TRUNK }}" == "1" ]; then
mkdir -p /tmp/wordpress-nightly
curl https://wordpress.org/nightly-builds/wordpress-latest.zip > /tmp/wordpress-nightly.zip
unzip -q /tmp/wordpress-nightly.zip -d /tmp/wordpress-nightly/
mv /tmp/wordpress-nightly/wordpress/* ${{ steps.wordpress-version.outputs.WORDPRESS_CORE_DIR }}
else
curl -s https://wordpress.org/wordpress-${{ steps.wordpress-version.outputs.WORDPRESS_VERSION }}.tar.gz > /tmp/wordpress.tar.gz
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C ${{ steps.wordpress-version.outputs.WORDPRESS_CORE_DIR }}
fi
curl https://raw.github.com/markoheijnen/wp-mysqli/master/db.php > ${{ steps.wordpress-version.outputs.WORDPRESS_CORE_DIR }}/wp-content/db.php
- name: Cache WordPress Test Installation
id: wordpress-test-cache
uses: actions/cache@v3
with:
path: ${{ steps.wordpress-version.outputs.WP_TESTS_DIR }}
key: ${{ runner.os }}-wordpress-test-${{ steps.wordpress-version.outputs.WORDPRESS_VERSION }}') }}
- name: Install WordPress Test
if: steps.wordpress-test-cache.outputs.cache-hit != 'true'
run: |
mkdir -p ${{ steps.wordpress-version.outputs.WP_TESTS_DIR }}
DB_USER=${MYSQL_USER}
DB_PASS=${MYSQL_PASSWORD}
DB_NAME=${MYSQL_DATABASE}
DB_HOST=${MYSQL_HOST}:${MYSQL_PORT}
WP_TESTS_DIR=${{ steps.wordpress-version.outputs.WP_TESTS_DIR }}
svn co --quiet https://develop.svn.wordpress.org/${{ steps.wordpress-version.outputs.WP_TESTS_TAG }}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
svn co --quiet https://develop.svn.wordpress.org/${{ steps.wordpress-version.outputs.WP_TESTS_TAG }}/tests/phpunit/data/ $WP_TESTS_DIR/data
curl https://develop.svn.wordpress.org/${{ steps.wordpress-version.outputs.WP_TESTS_TAG }}/wp-tests-config-sample.php > $WP_TESTS_DIR/wp-tests-config.php
# remove all forward slashes in the end
WP_CORE_DIR=$(echo ${{ steps.wordpress-version.outputs.WORDPRESS_CORE_DIR }} | sed "s:/\+$::")
sed -i "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
sed -i "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
sed -i "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
sed -i "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
sed -i "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
- name: Run PHPUnit Main Tests
# only run the output tests on the newer versions of php and phpunit, cause
# they're trickier
run: |
if [ "8.3" == ${{ matrix.php }} ]; then
PHP_UNIT_ARGS=""
else
PHP_UNIT_ARGS="--exclude-group output"
fi
WP_PLUGIN_DIR="$(pwd)" \
COMPOSER_VENDOR_DIR="$WP_PLUGIN_DIR/vendor" \
WP_TESTS_DIR=${{ steps.wordpress-version.outputs.WP_TESTS_DIR }} \
vendor/bin/phpunit $PHP_UNIT_ARGS --group slow
- name: Run PHPUnit Loader Tests
run: |
WP_PLUGIN_DIR="$(pwd)" \
COMPOSER_VENDOR_DIR="$WP_PLUGIN_DIR/vendor" \
WP_TESTS_DIR=${{ steps.wordpress-version.outputs.WP_TESTS_DIR }} \
vendor/bin/phpunit --config phpunit-loader.xml.dist --filter FontAwesomeLoaderTestLifecycle
WP_PLUGIN_DIR="$(pwd)" \
COMPOSER_VENDOR_DIR="$WP_PLUGIN_DIR/vendor" \
WP_TESTS_DIR=${{ steps.wordpress-version.outputs.WP_TESTS_DIR }} \
vendor/bin/phpunit --config phpunit-loader.xml.dist --filter FontAwesomeLoaderTestRedundantVersions
WP_PLUGIN_DIR="$(pwd)" \
COMPOSER_VENDOR_DIR="$WP_PLUGIN_DIR/vendor" \
WP_TESTS_DIR=${{ steps.wordpress-version.outputs.WP_TESTS_DIR }} \
vendor/bin/phpunit --config phpunit-loader.xml.dist --filter FontAwesomeLoaderTestBasic
- name: Run PHPUnit Multisite Tests
run: |
WP_PLUGIN_DIR="$(pwd)" \
COMPOSER_VENDOR_DIR="$WP_PLUGIN_DIR/vendor" \
WP_TESTS_DIR=${{ steps.wordpress-version.outputs.WP_TESTS_DIR }} \
vendor/bin/phpunit --config phpunit-multisite.xml.dist
WP_PLUGIN_DIR="$(pwd)" \
COMPOSER_VENDOR_DIR="$WP_PLUGIN_DIR/vendor" \
WP_TESTS_DIR=${{ steps.wordpress-version.outputs.WP_TESTS_DIR }} \
vendor/bin/phpunit --config phpunit-multisite-network-admin.xml.dist
- name: Run PHPUnit Multisite SLOW Tests
run: |
WP_PLUGIN_DIR="$(pwd)" \
COMPOSER_VENDOR_DIR="$WP_PLUGIN_DIR/vendor" \
WP_TESTS_DIR=${{ steps.wordpress-version.outputs.WP_TESTS_DIR }} \
vendor/bin/phpunit --config phpunit-multisite.xml.dist --group slow
WP_PLUGIN_DIR="$(pwd)" \
COMPOSER_VENDOR_DIR="$WP_PLUGIN_DIR/vendor" \
WP_TESTS_DIR=${{ steps.wordpress-version.outputs.WP_TESTS_DIR }} \
vendor/bin/phpunit --config phpunit-multisite-network-admin.xml.dist --group slow
- name: Maybe run phpcs
run: |
if [ ${{ matrix.php }} == '8.2' ] && [ ${{ matrix.wordpress }} == latest ]; then
composer phpcs
echo
echo "Skipping phpcs"
fi