Skip to content

Instantly share code, notes, and snippets.

@msonowal
Forked from nasrulhazim/ci.yml
Created February 8, 2024 19:33
Show Gist options
  • Save msonowal/bff7bb8d5f4a852d1e3b17ed88d6609b to your computer and use it in GitHub Desktop.
Save msonowal/bff7bb8d5f4a852d1e3b17ed88d6609b to your computer and use it in GitHub Desktop.
GitHub Action - MySQL Service for Laravel with Multiple Databases
name: Unit Test
on:
push:
branches: [develop]
pull_request:
branches: [master, develop]
jobs:
PHPUnit:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0.21
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: unittest
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- uses: actions/checkout@v2
- name: Verify unittest DB exists
run: mysql --host 127.0.0.1 --port 3306 -uroot -e "SHOW DATABASES LIKE 'unittest'"
- name: Create 2nd Database
run: mysql --host 127.0.0.1 --port 3306 -uroot -e "CREATE DATABASE IF NOT EXISTS unittest_second;"
- name: Verify unittest_second DB exists
run: mysql --host 127.0.0.1 --port 3306 -uroot -e "SHOW DATABASES LIKE 'unittest_second'"
- name: Copy the .env
run: cp .env.example .env
- name: Install dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Configrue Storage Permission
run: chmod -R 777 storage bootstrap/cache
- name: Generate Application Key
run: php artisan key:generate
- name: Clear Configuration
run: php artisan config:clear
- name: Configure Application
run:
- name: Execute tests (Unit and Feature tests) via PHPUnit
env:
DB_CONNECTION: mysql
DB_PORT: 3306
DB_USER: root
DB_PASSWORD: ""
DB_DATABASE: unittest
run: vendor/bin/phpunit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment