Files
FOSSBilling/.github/workflows/php-build-test.yml
T

102 lines
3.4 KiB
YAML

name: PHP Build and Test
on:
workflow_call:
inputs:
write-cache:
required: true
type: boolean
jobs:
php-build-test:
name: 'PHP Build and Test (${{ matrix.php }})'
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
matrix:
php: ['8.3', '8.4', '8.5']
fail-fast: true
steps:
- name: 'Checkout Repository'
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
with:
persist-credentials: false
- name: 'Set Registry Cache Image'
run: echo "CACHE_IMAGE=ghcr.io/${GITHUB_REPOSITORY@L}-build-cache" >> "${GITHUB_ENV}"
- name: 'Login to GitHub Container Registry'
if: inputs.write-cache
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 'Set up Docker Buildx'
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4
- name: 'Build Docker Test Image'
id: build_read_cache
if: ${{ !inputs.write-cache }}
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7
with:
build-args: |
PHP_VERSION=${{ matrix.php }}
INSTALL_TRANSLATIONS=false
cache-from: type=registry,ref=${{ env.CACHE_IMAGE }}:cache-ci-${{ matrix.php }}
context: .
load: true
tags: |
fossbilling:test-${{ matrix.php }}
target: test
- name: 'Build Docker Test Image'
id: build_write_cache
if: inputs.write-cache
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7
with:
build-args: |
PHP_VERSION=${{ matrix.php }}
INSTALL_TRANSLATIONS=false
cache-from: type=registry,ref=${{ env.CACHE_IMAGE }}:cache-ci-${{ matrix.php }}
cache-to: type=registry,ref=${{ env.CACHE_IMAGE }}:cache-ci-${{ matrix.php }},mode=max
context: .
load: true
tags: |
fossbilling:test-${{ matrix.php }}
target: test
- name: 'PHPStan'
id: phpstan
run: |
docker run --rm \
--env APP_ENV=test \
fossbilling:test-${{ matrix.php }} \
./src/vendor/bin/phpstan analyse --configuration phpstan.neon --memory-limit=512M
- name: 'Pest'
id: pest
run: |
docker run --rm \
--env APP_ENV=test \
fossbilling:test-${{ matrix.php }} \
./src/vendor/bin/pest --test-directory ../tests --configuration phpunit.xml.dist --ci
- name: 'Write Job Summary'
if: always()
run: |
cat >> "${GITHUB_STEP_SUMMARY}" <<'EOF'
## PHP Build and Test
| Item | Value |
| --- | --- |
| PHP version | `${{ matrix.php }}` |
| Test image | `fossbilling:test-${{ matrix.php }}` |
| Registry cache | `${{ env.CACHE_IMAGE }}:cache-ci-${{ matrix.php }}` |
| Cache mode | `${{ inputs.write-cache && 'read/write' || 'read-only' }}` |
| Docker build | `${{ inputs.write-cache && steps.build_write_cache.outcome || steps.build_read_cache.outcome }}` |
| PHPStan | `${{ steps.phpstan.outcome }}` |
| Pest | `${{ steps.pest.outcome }}` |
EOF