name: Tests

on: [push, pull_request]

defaults:
  run:
    shell: bash

jobs:
  tests:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [14.x]

    env:
      LD_LIBRARY_PATH: /opt/oracle/instantclient_21_1

    steps:
      - uses: actions/checkout@v2

      - name: Install Oracle client
        run: |
          sudo apt install unzip
          wget -q https://download.oracle.com/otn_software/linux/instantclient/211000/instantclient-basiclite-linux.x64-21.1.0.0.0.zip
          sudo mkdir -p /opt/oracle
          sudo unzip -qo instantclient-basiclite-linux.x64-21.1.0.0.0.zip -d /opt/oracle

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}

      - run: docker-compose up -d

      - run: npm ci

      - run: "while ! docker-compose logs mysql | grep -q 'mysqld: ready for connections.'; do sleep 2; done"
      - run: "while ! docker-compose logs postgres | grep -q 'database system is ready to accept connections'; do sleep 2; done"
      - run: "while ! docker-compose logs mssql | grep -q 'SQL Server is now ready for client connections'; do sleep 2; done"

      - run: npm test
