Skip to content

Instantly share code, notes, and snippets.

@nasrulhazim
Created November 20, 2020 15:32
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nasrulhazim/b46944ac0707ba54f3a055aeae333a68 to your computer and use it in GitHub Desktop.
Save nasrulhazim/b46944ac0707ba54f3a055aeae333a68 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
@hamza-saqib
Copy link

this isn't working, keep getting this error,
Illuminate\Database\QueryException: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')

@nasrulhazim
Copy link
Author

this isn't working, keep getting this error, Illuminate\Database\QueryException: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')

it's been 2 years, might not up-to-date. You may check with latest Github Action setup.

@hamza-saqib
Copy link

@nasrulhazim found the issue, there should by one more line to update the authentication of MySQL to password by default its something else maybe authentication with socket. so i changed the authentication to password by adding following command and now its working fine.

- name: change authentication method
      run: mysql --host 127.0.0.1 --port 3306 -uroot -proot -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root'";

in my yaml i am using password so i change the password to root.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment