Skip to content

Instantly share code, notes, and snippets.

@lruozzi9
Created January 23, 2021 18:00
Show Gist options
  • Save lruozzi9/e90db627376d1d80d935f56159d2010a to your computer and use it in GitHub Desktop.
Save lruozzi9/e90db627376d1d80d935f56159d2010a to your computer and use it in GitHub Desktop.
GitHub action for testing Laravel app with MySQL
name: Laravel
on: [push, pull_request]
jobs:
laravel-tests:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:5.7
env:
MYSQL_DATABASE: ${{ secrets.DB_DATABASE }}
MYSQL_ROOT_PASSWORD: ${{ secrets.DB_PASSWORD }}
ports:
- 3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
steps:
- uses: actions/checkout@v2
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.ci', '.env');"
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
- name: Install Node Dependencies
run: npm install
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Generate key
run: php artisan key:generate
- name: Create Database Schema
env:
DB_DATABASE: ${{ secrets.DB_DATABASE }}
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
DB_USERNAME: root
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
run: php artisan migrate
- name: Execute tests (Unit and Feature tests) via PHPUnit
env:
DB_DATABASE: ${{ secrets.DB_DATABASE }}
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
DB_USERNAME: root
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
run: vendor/bin/phpunit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment