Shivam Mathur's "node-docker" Images are Awesome for PHP CI
Today I had a scenario where I needed to expand the testing of a PHP project across two dimensions: PHP versions and PHPUnit versions. Of course, this explodes the amount of test runs somewhat.
As part of my CI test process, ran via Forgejo runner, i already used the very awesome & useful setup-php action by Shivam Mathur. But this remained the slowest part, needing to download/setup PHP for each scenario and test run. Not only does this waste time, but also bandwidth, power and resources, which can add up over many scenarios and test runs.
Thankfully, I discovered that Shivam also provides a large array of docker images in their node-docker repo. These are GitHub/Forgejo-action-ready images (Node installed), for a wide range of Debian/Ubuntu versions, for a range of common architectures, each with a range of PHP versions installed. There are also variations with only specific PHP versions if preferred.
Using these cut my per-scenario run time down from 40 seconds to 12 seconds. Definitely will be keeping these images in mind when it comes to updating my other PHP CI setups!
CI Workflow
For context, below is the CI workflow I used this in. Original source in repo here.
name: php
on: [push, pull_request]
jobs:
test:
runs-on: docker
container:
image: docker.io/setupphp/node:trixie
strategy:
matrix:
php: [8.1, 8.2, 8.3, 8.4, 8.5]
phpunit: [10, 11, 12, 13]
exclude:
- php: 8.1
phpunit: 11
- php: 8.1
phpunit: 12
- php: 8.2
phpunit: 12
- php: 8.1
phpunit: 13
- php: 8.2
phpunit: 13
- php: 8.3
phpunit: 13
steps:
- name: Checkout code
uses: https://code.forgejo.org/actions/checkout@v4
- name: Cache dependencies
uses: https://code.forgejo.org/actions/cache@v4
with:
path: ~/.composer/cache/files
key: dependencies-php-${{ matrix.php }}-phpunit-${{ matrix.phpunit }}-composer-${{ hashFiles('composer.json') }}
restore-keys: |
dependencies-php-${{ matrix.php }}-phpunit-${{ matrix.phpunit }}-composer-
dependencies-php-${{ matrix.php }}-
- name: Setup PHP
uses: https://github.com/shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring
coverage: none
- name: Require PHPUnit version
run: composer require phpunit/phpunit:"^${{ matrix.phpunit }}" --no-update --no-interaction
- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-suggest
env:
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.GH_TOKEN }}"}}'
- name: Run PHPStan
run: vendor/bin/phpstan
- name: Execute PHPUnit tests
run: vendor/bin/phpunit