2026-02-23 01:20:35 +00:00
|
|
|
# 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"]'
|
|
|
|
|
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
|
2026-02-23 13:45:43 +00:00
|
|
|
container:
|
|
|
|
|
image: lthn/build:php-${{ matrix.php }}
|
2026-02-23 01:20:35 +00:00
|
|
|
|
|
|
|
|
strategy:
|
|
|
|
|
fail-fast: true
|
|
|
|
|
matrix:
|
|
|
|
|
php: ${{ fromJson(inputs.php-version) }}
|
|
|
|
|
|
|
|
|
|
steps:
|
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
|
|
2026-02-23 04:56:56 +00:00
|
|
|
- name: Checkout dependencies
|
|
|
|
|
env:
|
|
|
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
|
run: |
|
|
|
|
|
# Clone path-repository dependencies that composer.json references
|
|
|
|
|
# These are sister packages not on Packagist
|
|
|
|
|
if grep -q '"path":' composer.json 2>/dev/null; then
|
|
|
|
|
for path in $(php -r "
|
|
|
|
|
\$d = json_decode(file_get_contents('composer.json'), true);
|
|
|
|
|
foreach (\$d['repositories'] ?? [] as \$r) {
|
|
|
|
|
if ((\$r['type'] ?? '') === 'path') echo \$r['url'] . \"\\n\";
|
|
|
|
|
}
|
|
|
|
|
"); do
|
|
|
|
|
dir_name=$(basename "$path")
|
|
|
|
|
if [ ! -d "$path" ]; then
|
|
|
|
|
echo "Cloning $dir_name into $path"
|
|
|
|
|
git clone --depth 1 \
|
|
|
|
|
"https://x-access-token:${GITHUB_TOKEN}@forge.lthn.ai/core/${dir_name}.git" \
|
|
|
|
|
"$path" || echo "Warning: Failed to clone $dir_name"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
|
2026-02-23 01:20:35 +00:00
|
|
|
- name: Install dependencies
|
|
|
|
|
run: composer install --prefer-dist --no-interaction --no-progress
|
|
|
|
|
|
|
|
|
|
- name: Run Pint
|
|
|
|
|
if: inputs.pint
|
2026-02-23 04:55:04 +00:00
|
|
|
run: |
|
|
|
|
|
if [ -f vendor/bin/pint ]; then
|
|
|
|
|
vendor/bin/pint --test
|
|
|
|
|
else
|
|
|
|
|
echo "Pint not installed, skipping"
|
|
|
|
|
fi
|
2026-02-23 01:20:35 +00:00
|
|
|
|
|
|
|
|
- name: Run tests
|
|
|
|
|
run: |
|
2026-02-23 04:55:04 +00:00
|
|
|
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"
|
2026-02-23 01:20:35 +00:00
|
|
|
fi
|