Owen Conti

GitHub Action to Deploy Laravel Vapor Apps

Posted on under Laravel by Owen Conti.

Here's a quick GitHub Actions file you can use to deploy Laravel Vapor applications.

  • Uses MySQL 8.0
  • Uses PHP 7.4
  • Runs phpcs and phpunit
  • Deploys staging branch to the staging Vapor environment
  • Deploys master branch to the production Vapor environment

Feel free to change any details to suite your application.

The only requirement is you will need to define a VAPOR_API_TOKEN secret.

1name: Build
2on: [push, workflow_dispatch]
3 
4jobs:
5 build-php:
6 services:
7 mysql:
8 image: mysql:8.0
9 env:
10 MYSQL_USER: root
11 MYSQL_ROOT_PASSWORD: root
12 MYSQL_DATABASE: laravel
13 ports:
14 - 3306:3306
15 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
16 
17 name: Build PHP
18 runs-on: ubuntu-latest
19 container: lorisleiva/laravel-docker:7.4
20 steps:
21 - uses: actions/checkout@v2
22 - run: composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts
23 - run: ./vendor/bin/phpcs --standard=./phpcs.xml --extensions=php app --warning-severity=0
24 - run: npm ci
25 - run: npm run dev
26 - name: Configure application
27 run: |
28 cp .env.ci .env
29 php artisan cache:clear
30 php artisan config:clear
31 php artisan key:generate
32 - run: ./vendor/bin/phpunit --colors=never
33 
34 deploy:
35 if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/staging'
36 name: Deploy application
37 runs-on: ubuntu-latest
38 container: lorisleiva/laravel-docker:7.4
39 needs: [build-php]
40 env:
41 VAPOR_API_TOKEN: ${{ secrets.VAPOR_API_TOKEN }}
42 VAPOR_ENV: ${{ github.ref == 'refs/heads/master' && 'production' || 'staging' }}
43 steps:
44 - uses: actions/checkout@v2
45 - run: composer install --no-dev --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts
46 - run: ./vendor/bin/vapor deploy ${{ env.VAPOR_ENV }}

Thanks for reading this article!

Hopefully you found this article useful! If you did, share it on X!

Found an issue with the article? Submit your edits against the repository.