Use WordPress
Coding Standards ruleset
#265
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run Tests | |
# When to run tests. | |
on: | |
pull_request: | |
types: | |
- opened | |
- synchronize | |
push: | |
branches: | |
- main | |
jobs: | |
tests: | |
# Name. | |
name: WordPress ${{ matrix.wp-versions }} / PHP ${{ matrix.php-versions }} | |
# Virtual Environment to use. | |
# @see: https://github.com/actions/virtual-environments | |
runs-on: ubuntu-latest | |
# Environment Variables. | |
# Accessible by using ${{ env.NAME }} | |
# Use ${{ secrets.NAME }} to include any GitHub Secrets in ${{ env.NAME }} | |
# The base folder will always be /home/runner/work/github-repo-name/github-repo-name | |
env: | |
ROOT_DIR: /var/www/html | |
PLUGIN_DIR: /var/www/html/wp-content/plugins/convertkit-wordpress-libraries | |
DB_NAME: test | |
DB_USER: root | |
DB_PASS: root | |
DB_HOST: localhost | |
INSTALL_PLUGINS: "woocommerce" # Don't include this repository's Plugin here. | |
CONVERTKIT_API_KEY: ${{ secrets.CONVERTKIT_API_KEY }} | |
CONVERTKIT_API_SECRET: ${{ secrets.CONVERTKIT_API_SECRET }} | |
CONVERTKIT_OAUTH_ACCESS_TOKEN: ${{ secrets.CONVERTKIT_OAUTH_ACCESS_TOKEN }} | |
CONVERTKIT_OAUTH_REFRESH_TOKEN: ${{ secrets.CONVERTKIT_OAUTH_REFRESH_TOKEN }} | |
CONVERTKIT_OAUTH_ACCESS_TOKEN_NO_DATA: ${{ secrets.CONVERTKIT_OAUTH_ACCESS_TOKEN_NO_DATA }} | |
CONVERTKIT_OAUTH_REFRESH_TOKEN_NO_DATA: ${{ secrets.CONVERTKIT_OAUTH_REFRESH_TOKEN_NO_DATA }} | |
CONVERTKIT_OAUTH_CLIENT_ID: ${{ secrets.CONVERTKIT_OAUTH_CLIENT_ID }} | |
CONVERTKIT_OAUTH_REDIRECT_URI: ${{ secrets.CONVERTKIT_OAUTH_REDIRECT_URI }} | |
CONVERTKIT_API_SIGNED_SUBSCRIBER_ID: ${{ secrets.CONVERTKIT_API_SIGNED_SUBSCRIBER_ID }} | |
CONVERTKIT_API_SUBSCRIBER_TOKEN: ${{ secrets.CONVERTKIT_API_SUBSCRIBER_TOKEN }} | |
# Defines the WordPress and PHP Versions matrix to run tests on. | |
strategy: | |
fail-fast: false | |
matrix: | |
wp-versions: [ 'latest' ] #[ 'latest', '6.1.1' ] | |
php-versions: [ '7.4', '8.0', '8.1', '8.2', '8.3' ] #[ '7.4', '8.0', '8.1', '8.2' ] | |
# Steps to install, configure and run tests | |
steps: | |
# Checkout Plugin to /home/runner/work/convertkit-wordpress-libraries/convertkit-wordpress-libraries/convertkit-wordpress-libraries | |
# We cannot checkout to ${{ env.PLUGIN_DIR }} as GitHub Actions require it be first placed in /home/runner/work/repo/repo | |
- name: Checkout Plugin | |
uses: actions/checkout@v4 | |
with: | |
path: /home/runner/work/convertkit-wordpress-libraries/convertkit-wordpress-libraries/convertkit-wordpress-libraries | |
- name: Start MySQL | |
run: sudo systemctl start mysql.service | |
- name: Create MySQL Database | |
run: | | |
mysql -e 'CREATE DATABASE test;' -u${{ env.DB_USER }} -p${{ env.DB_PASS }} | |
mysql -e 'SHOW DATABASES;' -u${{ env.DB_USER }} -p${{ env.DB_PASS }} | |
# WordPress won't be able to connect to the DB if we don't perform this step. | |
- name: Permit MySQL Password Auth for MySQL 8.0 | |
run: mysql -e "ALTER USER '${{ env.DB_USER }}'@'${{ env.DB_HOST }}' IDENTIFIED WITH mysql_native_password BY '${{ env.DB_PASS }}';" -u${{ env.DB_USER }} -p${{ env.DB_PASS }} | |
# Some workflows checkout WordPress from GitHub, but that seems to bring a bunch of uncompiled files with it. | |
# Instead download from wordpress.org stable. | |
- name: Download and Extract WordPress | |
run: | | |
sudo chown -R runner:docker /var/www/html | |
ls -la /var/www/html | |
cd /var/www/html | |
wget https://wordpress.org/wordpress-${{ matrix.wp-versions }}.tar.gz | |
tar xfz wordpress-${{ matrix.wp-versions }}.tar.gz | |
mv wordpress/* . | |
rm -rf wordpress wordpress-${{ matrix.wp-versions }}.tar.gz | |
# We install WP-CLI, as it provides useful commands to setup and install WordPress through the command line. | |
- name: Install WP-CLI | |
run: | | |
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar | |
chmod +x wp-cli.phar | |
sudo mv wp-cli.phar /usr/local/bin/wp-cli | |
- name: Setup wp-config.php | |
working-directory: ${{ env.ROOT_DIR }} | |
run: wp-cli config create --dbname=${{ env.DB_NAME }} --dbuser=${{ env.DB_USER }} --dbpass=${{ env.DB_PASS }} --dbhost=${{ env.DB_HOST }} --locale=en_DB | |
- name: Install WordPress | |
working-directory: ${{ env.ROOT_DIR }} | |
run: wp-cli core install --url=127.0.0.1 --title=ConvertKit --admin_user=admin --admin_password=password [email protected] | |
# env.INSTALL_PLUGINS is a list of Plugin slugs, space separated e.g. contact-form-7 woocommerce. | |
- name: Install Free Third Party WordPress Plugins | |
working-directory: ${{ env.ROOT_DIR }} | |
run: wp-cli plugin install ${{ env.INSTALL_PLUGINS }} | |
# Move Plugin | |
- name: Move Plugin | |
run: mv /home/runner/work/convertkit-wordpress-libraries/convertkit-wordpress-libraries/convertkit-wordpress-libraries ${{ env.PLUGIN_DIR }} | |
# Install PHP version to run tests against. | |
- name: Install PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: ${{ matrix.php-versions }} | |
coverage: xdebug | |
tools: cs2pr | |
# Write any secrets, such as API keys, to the .env.dist.testing file now. | |
# Make sure your committed .env.dist.testing file ends with a newline. | |
# The formatting of the contents to include a blank newline is deliberate. | |
- name: Define GitHub Secrets in .env.dist.testing | |
uses: DamianReeves/[email protected] | |
with: | |
path: ${{ env.PLUGIN_DIR }}/.env.dist.testing | |
contents: | | |
CONVERTKIT_API_KEY=${{ env.CONVERTKIT_API_KEY }} | |
CONVERTKIT_API_SECRET=${{ env.CONVERTKIT_API_SECRET }} | |
CONVERTKIT_OAUTH_ACCESS_TOKEN=${{ env.CONVERTKIT_OAUTH_ACCESS_TOKEN }} | |
CONVERTKIT_OAUTH_REFRESH_TOKEN=${{ env.CONVERTKIT_OAUTH_REFRESH_TOKEN }} | |
CONVERTKIT_OAUTH_ACCESS_TOKEN_NO_DATA=${{ env.CONVERTKIT_OAUTH_ACCESS_TOKEN_NO_DATA }} | |
CONVERTKIT_OAUTH_REFRESH_TOKEN_NO_DATA=${{ env.CONVERTKIT_OAUTH_REFRESH_TOKEN_NO_DATA }} | |
CONVERTKIT_OAUTH_CLIENT_ID=${{ env.CONVERTKIT_OAUTH_CLIENT_ID }} | |
CONVERTKIT_OAUTH_REDIRECT_URI=${{ env.CONVERTKIT_OAUTH_REDIRECT_URI }} | |
CONVERTKIT_API_SIGNED_SUBSCRIBER_ID=${{ env.CONVERTKIT_API_SIGNED_SUBSCRIBER_ID }} | |
CONVERTKIT_API_SUBSCRIBER_TOKEN=${{ env.CONVERTKIT_API_SUBSCRIBER_TOKEN }} | |
write-mode: append | |
# Installs wp-browser, Codeception, PHP CodeSniffer and anything else needed to run tests. | |
- name: Run Composer | |
working-directory: ${{ env.PLUGIN_DIR }} | |
run: composer update | |
- name: Build PHP Autoloader | |
working-directory: ${{ env.PLUGIN_DIR }} | |
run: composer dump-autoload | |
# Run Coding Standards on Tests. | |
- name: Run Coding Standards on Tests | |
working-directory: ${{ env.PLUGIN_DIR }} | |
run: php vendor/bin/phpcs -q --standard=phpcs.tests.xml --report=checkstyle ./tests | cs2pr | |
# Run WordPress Coding Standards on Plugin. | |
- name: Run WordPress Coding Standards | |
working-directory: ${{ env.PLUGIN_DIR }} | |
run: php vendor/bin/phpcs -q --standard=phpcs.xml --report=checkstyle ./ | cs2pr | |
# Run PHPStan for static analysis. | |
- name: Run PHPStan Static Analysis | |
working-directory: ${{ env.PLUGIN_DIR }} | |
run: php vendor/bin/phpstan analyse --memory-limit=1024M | |
# Build Codeception Tests. | |
- name: Build Tests | |
working-directory: ${{ env.PLUGIN_DIR }} | |
run: php vendor/bin/codecept build | |
# Run Codeception WPUnit Tests | |
- name: Run WPUnit Tests | |
working-directory: ${{ env.PLUGIN_DIR }} | |
run: php vendor/bin/codecept run tests/wpunit --fail-fast |