Github action with MySQL test database

Viewed 3568

I have a CodeIgniter Web app connected with Mysql that is developed in the docker. I would like to do some unit test in the GitHub action fo ci/cd pipeline. The problem is some of the function would require enquiry data from Mysql database. So may I know if there is a way to setup a MySQL instance on Github action and run some .sql file so that my test data is in the database?

2 Answers

I think this script can help people to conduct unit test with MySQL database and a .sql script file to load table schema and data on Github action. I am using Codeigniter 4 with Mysql. But the process of setting up a database would be similar as long as you are using MySQL.

name:  CI Pipeline

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:

  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Build the Docker image
      run: docker-compose build

    - name: up mysql and apache container runs
      run: docker-compose up -d

     #I am using codeIgniter4
    - name: install dependencies
      run: docker exec  CI4_1 php composer.phar install

    - name: buffering time for db container
      uses: jakejarvis/wait-action@master
      with:
        time: '30s'

    #db_1 is the name of database
    - name: load database
      run: docker exec -i mysql_1  mysql -uroot  -proot  db_1< ./testDatabase.sql

   

    - name: unit test
      run: docker exec  CI4_1  ./vendor/bin/phpunit
Related