name: CI
on: 
  push:
    paths-ignore:
      - 'docs/**'
      - '**.md'

jobs:
  test:
    runs-on: ubuntu-latest
    services:
      mysql:
        image: mysql:latest
        env:
          MYSQL_ALLOW_EMPTY_PASSWORD: yes
          MYSQL_DATABASE: test
        ports:
          - 3306:3306
        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
    strategy:
      matrix:
       include:
        - node-version: 14.x
        - node-version: 16.x
    steps:
      - uses: actions/checkout@v2
      - name: change __temp_sync__db charset
        run: mysql --host 127.0.0.1 --port 3306 -uroot -e "CREATE DATABASE IF NOT EXISTS __temp_sync__db CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;"
      - name: Create auto_db_migrate Database
        run: mysql --host 127.0.0.1 --port 3306 -uroot -e "CREATE DATABASE IF NOT EXISTS auto_db_migrate CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;"
      - name: Create __temp_sync__temp_db Database
        run: mysql --host 127.0.0.1 --port 3306 -uroot -e "CREATE DATABASE IF NOT EXISTS __temp_sync__temp_db CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;"
      - name: Install Node - ${{ matrix.node-version }}
        uses: actions/setup-node@v2        
        with:
          node-version: ${{ matrix.node-version }}
      - name: Cache node modules
        uses: actions/cache@v2
        env:
          cache-name: cache-node-modules
        with:
          # npm cache files are stored in `~/.npm` on Linux/macOS
          path: ~/.npm
          key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
      - name: Install Dependencies
        run: npm install
      - name: Test On Node ${{ matrix.node-version }}

        run: |
          npm run test
