scaffold-command
scaffold-command copied to clipboard
Scaffold plugin tests using GitHub actions
Support for GitHub actions!
I've used this configuration in my plugin: https://github.com/junaidbhura/auto-cloudinary/blob/master/.github/workflows/main.yml
You can see all the workflows in action here: https://github.com/junaidbhura/auto-cloudinary/actions/runs/75118491
Key highlights
- I've used custom Docker images: https://hub.docker.com/r/junaidbhura/wp-tests (https://github.com/junaidbhura/docker-wp-tests). These images are made specifically to run these WordPress tests, and I intend to maintain them and add new versions in the future. The images used on the GitLab config don't seem to be maintained anymore (https://github.com/wp-cli/scaffold-command/issues/256, https://github.com/wp-cli/scaffold-command/issues/239)
- There's a test matrix with PHP 7.2, 7.3 and 7.4 - and the latest WordPress version by default. Users can change this as needed
- This config supports caching to make subsequent runs faster
Hey @schlessera 👋
Do you have any thoughts about this?
Hey @junaidbhura,
The GitHub Actions integration looks good. However, I'm hesitant to rely on your Docker images. I trust that you are serious about maintaining these, but in this case it is not only about maintaining to support the most recent version of WP-CLI or replace it. As this is about scaffolding, it will build the foundation for many, many projects that will be stuck on that specific configuration.
For this reason, I'd prefer to have either official, canonical images, or images that are managed under the wp-cli
organization where all WP-CLI maintainers/committers could collaborate on maintaining them.
Oh, sorry about the closing, that was me hitting a button by accident.
So, given the above reasoning, are you interested in helping me establish a more canonical version of this with official or wp-cli
Docker images?
Hey @schlessera thanks for your reply!
I totally understand, I'm happy to swap my images out for official images from WP CLI - as that would be the best approach!
Just to clarify, do those images already exist - or are you suggesting that we create them?
No, those do not exist yet, so we'd have to create them first.
Understood @schlessera I’m happy to contribute to it. Is there a Git repo for it?
So the way I see it, this is the way forward:
- Create official WP CLI Docker images for PHP and publish them on DockerHub
- Replace the images on this PR with those ones
- Merge this PR
Is this accurate?
Do we really need custom docker images? Here's a version for running PHPUnit that I'm using which doesn't require them:
phpunit.yml
name: PHPUnit
on: push
jobs:
phpunit:
name: PHPUnit (PHP ${{ matrix.php }} with WordPress ${{ matrix.wordpress }})
runs-on: ubuntu-latest
services:
mysql:
image: mysql:5.7
ports:
- 3306/tcp
env:
MYSQL_ROOT_PASSWORD: password
# Set health checks to wait until mysql has started
options: >-
--health-cmd "mysqladmin ping"
--health-interval 10s
--health-timeout 5s
--health-retries 3
strategy:
fail-fast: false
matrix:
php: ['7.3', '7.4']
wordpress: ['latest', 'trunk']
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
tools: composer, cs2pr
- name: Install WordPress test setup
env:
WP_VERSION: ${{ matrix.wordpress }}
MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
run: bash bin/install-wp-tests.sh wordpress_test root password "127.0.0.1:$MYSQL_PORT" "$WP_VERSION"
- name: Get Composer cache directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Setup cache
uses: pat-s/[email protected]
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install dependencies
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Run tests
run: composer run test
I tested the worflow suggested by @ocean90 and that worked out wonderfully for me.
I'm using this recently if you want to pick some ideas
Provides some more environments. I based it on the Travis one.
I also have this QA workflow using phpstan, psalm and phpcs that might also be interesting to you.
Proceeding with https://github.com/wp-cli/wp-cli/issues/5594 for this repository. I've captured this PR to https://gist.github.com/danielbachhuber/e942e14e1cda241e88c0495e16cf5427 in case this PR is auto-closed or broken in some way.