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

117 lines
4.0 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@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
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@af1e73f918a031802d376d3c8bbc3fe56130a9b0 # v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 'Set up Docker Buildx'
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4
- name: 'Build Docker Test Image'
id: build_read_cache
if: ${{ !inputs.write-cache }}
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # 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@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # 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
# PHPStan analyses source, not runtime behavior, so one PHP version is sufficient coverage.
if: matrix.php == '8.3'
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: 'Export Test Image Artifact'
# Shared with live-tests/cypress-tests so they don't each rebuild the same image.
if: matrix.php == '8.5'
run: docker save fossbilling:test-8.5 | zstd -T0 -6 --stdout > /tmp/test-image-8.5.tar.zst
- name: 'Upload Test Image Artifact'
if: matrix.php == '8.5'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
archive: false
path: /tmp/test-image-8.5.tar.zst
retention-days: 1
- 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