|
name: Run tests |
|
|
|
on: [push] |
|
|
|
jobs: |
|
|
|
php-tests: |
|
name: Run PHP tests |
|
runs-on: ubuntu-latest |
|
services: |
|
postgres: |
|
image: postgres:16 |
|
env: |
|
POSTGRES_DB: laravel |
|
POSTGRES_USER: root |
|
POSTGRES_PASSWORD: secret |
|
# Set health checks to wait until postgres has started |
|
options: >- |
|
--health-cmd pg_isready |
|
--health-interval 10s |
|
--health-timeout 5s |
|
--health-retries 5 |
|
ports: |
|
# Maps tcp port 5432 on service container to the host |
|
- 5432:5432 |
|
|
|
steps: |
|
- uses: actions/checkout@v4 |
|
|
|
- name: Setup PHP |
|
uses: shivammathur/setup-php@v2 |
|
with: |
|
php-version: '8.3' |
|
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv |
|
coverage: none |
|
|
|
- name: Install Composer dependencies |
|
uses: ramsey/composer-install@v3 |
|
|
|
- name: Prepare Laravel Application |
|
run: | |
|
cp .env.example .env |
|
php artisan key:generate |
|
|
|
# It speeds up (in theory) the following steps and sort of tests routes: |
|
# this command may fail in case of route definition issues (e.g., not existing controller). |
|
# Please it tests whether routes are cacheable (what is essential for production) |
|
- name: Cache Laravel routes |
|
run: php artisan route:cache |
|
|
|
- name: Run tests |
|
run: php artisan test --parallel |
|
env: |
|
DB_HOST: 127.0.0.1 |
|
DB_PORT: 5432 |
|
DB_DATABASE: laravel |
|
DB_USERNAME: root |
|
DB_PASSWORD: secret |
|
|
|
- name: Run composer security audit |
|
run: composer audit |
|
|
|
|
|
deploy: |
|
name: Deploy |
|
runs-on: ubuntu-latest |
|
# jobs that must complete successfully before this job will run |
|
needs: [ php-tests ] |
|
# Deploy if the push is tagged by a git tag (release) |
|
if: ${{ startsWith(github.ref, 'refs/tags/') && github.event_name == 'push' }} |
|
concurrency: deploy-${{ github.ref }} |
|
steps: |
|
- uses: actions/checkout@v4 |
|
with: |
|
ref: ${{ github.ref }} |
|
|
|
#todo add next steps, e.g. ping Laravel Forge deployment URL |