@bwrigley Feel free to use as is or customize it to your liking.
GitHub Action:
name: Deployment
on:
push:
workflow_dispatch:
jobs:
fabpot-security-checker:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
- name: Install security-checker
uses: symfonycorp/security-checker-action@v5
pest:
runs-on: ubuntu-latest
needs: [fabpot-security-checker, phpcpd]
services:
mariadb:
image: mariadb:10.11
env:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
redis:
image: redis:7.0-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Setup PHP with composer v2
uses: shivammathur/setup-php@v2
with:
php-version: "8.2"
tools: composer:v2
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, mysql, mysqli, pdo_mysql, bcmath, soap, intl, gd, exif, iconv, imagick, redis
coverage: xdebug
- name: Install composer packages
run: |
php -v
composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts
- name: npm install
run: |
npm --version
npm install
npm run production
- name: Create temp database
run: |
mysql --host 127.0.0.1 -uroot -proot -e "CREATE DATABASE IF NOT EXISTS laravel_db"
- name: Execute tests
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
cp .env.github .env
php -v
php artisan migrate --force
php artisan key:generate
./vendor/bin/pest --parallel --coverage-clover=coverage.xml
bash <(curl -s https://codecov.io/bash) || echo 'Codecov failed to upload'
phpstan:
runs-on: ubuntu-latest
needs: [fabpot-security-checker, phpcpd]
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Setup PHP with composer v2
uses: shivammathur/setup-php@v2
with:
php-version: "8.2"
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, mysql, mysqli, pdo_mysql, bcmath, soap, intl, gd, exif, iconv, imagick, redis
tools: composer:v2
- name: Install composer packages
run: |
php -v
composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts
- name: Static analysis with phpstan
run: ./vendor/bin/phpstan analyse
phpcpd:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
- name: Install phpcpd
run: test -f phpcpd.phar || curl -L https://phar.phpunit.de/phpcpd.phar -o phpcpd.phar
- name: Run phpcpd
run: php phpcpd.phar app/ --min-lines=50
ploi_deploy:
runs-on: ubuntu-latest
needs: [pest, phpstan]
if: github.ref == 'refs/heads/main'
steps:
- name: Trigger Ploi webhook
run: curl -X POST ${{ secrets.PLOI_DEPLOY_WEBHOOK }}
Ploi deployment script:
php artisan down --refresh=15 --render="errors::503" --with-secret
git reset --hard
git pull origin main
composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev
npm ci
npm run build
echo "" | sudo -S service php8.2-fpm reload
php artisan config:cache
php artisan event:cache
php artisan route:cache
php artisan view:cache
{FLUSH_CLOUDFLARE_CACHE}
php artisan migrate --force
php artisan queue:restart
php artisan horizon:terminate # supervisord should pick this up and then restart it
php artisan up
echo "🚀 Application deployed!"