GitHub Actions CI/CD for WordPress plugin testing and deployment
GitHub Actions runs a pipeline on every push and pull request: free for public repositories and with a monthly allowance of minutes for private ones. That is enough to run PHPUnit, the WordPress Coding Standards and PHPStan for a plugin on several PHP and WordPress versions, and to deploy a release to WordPress.org. A workflow is a YAML file in .github/workflows/; it has jobs that run in parallel on fresh virtual machines, and each job has steps.
Problem: A team of four merges to main after a visual review. In one month: a fatal error that appeared only on PHP 8.1 (everyone tests on 8.0), a coding standards violation that got a plugin release rejected, and a regression that a PHPUnit test would have caught if anyone had run it.
Solution: A workflow that runs PHPUnit on a matrix of PHP and WordPress versions, PHP_CodeSniffer with WPCS and PHPStan on every pull request, blocks merging on failure, and deploys to WordPress.org when a version tag is pushed.
The workflow
.github/workflows/ci.yml:
name: Plugin CI
on:
push:
branches: [ main ]
tags: [ 'v*' ]
pull_request:
branches: [ main ]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
coverage: none
- run: composer install --prefer-dist --no-progress
- run: vendor/bin/phpcs
- run: vendor/bin/phpstan analyse --no-progress
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [ '8.0', '8.1', '8.2', '8.3' ]
wordpress: [ 'latest' ]
include:
- php: '8.0'
wordpress: '6.4'
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
ports: [ '3306:3306' ]
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mysqli
coverage: none
- run: composer install --prefer-dist --no-progress
- name: Install the WordPress test suite
run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 ${{ matrix.wordpress }}
- run: vendor/bin/phpunit
deploy:
needs: [ lint, test ]
if: startsWith( github.ref, 'refs/tags/v' )
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Deploy to WordPress.org
uses: 10up/action-wordpress-plugin-deploy@stable
env:
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SLUG: my-plugin-slug
What each part does:
on: pull requests tomain, pushes tomain, and tags likev1.2.0. The tag trigger is needed, otherwise the deploy job never sees a tag.lint: code style and static analysis need no database and run once, on one PHP version. phpcs.xml.dist and phpstan.neon in the repository hold their configuration (see PHPStan for WordPress plugins).test: the matrix runs PHPUnit on every PHP version against the latest WordPress, plus the oldest supported combination.fail-fast: falselets all of them finish, so you see every broken version at once.services.mysql: a MySQL container for the WordPress test database; the health check waits until it accepts connections.- bin/install-wp-tests.sh is the script generated by
wp scaffold plugin-tests(see unit tests with PHPUnit). It uses Subversion to download the test library; if the runner image does not havesvn, add a stepsudo apt-get install -y subversionbefore it. deploy: runs only for version tags and only after both other jobs passed (needs). The 10up action commits the tag to the plugin’s SVN repository on WordPress.org.
Composer
The tools come from composer.json, so the versions are the same locally and in CI:
composer require --dev phpunit/phpunit:^9 yoast/phpunit-polyfills wp-coding-standards/wpcs phpstan/phpstan szepeviktor/phpstan-wordpress phpstan/extension-installer
Block the merge
In Settings → Branches add a protection rule for main with “Require status checks to pass before merging” and select the lint and test checks. Each matrix combination is a separate check, so select all of them, or a failing PHP version can still be merged.
NOTE: The SVN credentials go into Settings → Secrets and variables → Actions, never into the workflow file; GitHub hides secret values in the logs. If the plugin has a build step (npm, composer install --no-dev), build it in the deploy job before the deploy action, and exclude development files from the release with a .distignore file, which the 10up action reads.