php/.forgejo/workflows/php-test.yml
Claude d231c72661
fix: make reusable workflow resilient to missing test runners
Detect whether pest, phpunit, or pint are installed before running them.
Repos without test runners will skip gracefully instead of failing with
"No such file or directory".

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 04:55:04 +00:00

70 lines
1.8 KiB
YAML

# Reusable PHP test workflow
# Usage: uses: core/php/.forgejo/workflows/php-test.yml@main
name: PHP Test
on:
workflow_call:
inputs:
php-version:
description: PHP versions to test (JSON array)
type: string
default: '["8.3", "8.4"]'
extensions:
description: PHP extensions to install
type: string
default: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite
coverage:
description: Generate coverage report
type: boolean
default: false
pint:
description: Run Pint code style check
type: boolean
default: true
jobs:
test:
name: PHP ${{ matrix.php }}
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
php: ${{ fromJson(inputs.php-version) }}
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: https://github.com/shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ inputs.extensions }}
coverage: pcov
- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-progress
- name: Run Pint
if: inputs.pint
run: |
if [ -f vendor/bin/pint ]; then
vendor/bin/pint --test
else
echo "Pint not installed, skipping"
fi
- name: Run tests
run: |
if [ -f vendor/bin/pest ]; then
FLAGS="--ci"
if [ "${{ inputs.coverage }}" = "true" ]; then
FLAGS="$FLAGS --coverage"
fi
vendor/bin/pest $FLAGS
elif [ -f vendor/bin/phpunit ]; then
vendor/bin/phpunit
else
echo "No test runner found (pest or phpunit), skipping tests"
fi