# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
# https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-nodejs
# https://docs.github.com/en/actions/use-cases-and-examples/using-containerized-services/creating-postgresql-service-containers

name: test

on:
  push:
    branches: [ "**" ]
  pull_request:
    branches: [ "master" ]

jobs:
  cockroachdb:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        node-version: [18.x] #["node:16", "node:18", "node:20", "node:22"]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
    - uses: actions/setup-node@v4
      with:
        node-version: ${{matrix.node-version}}
    - uses: actions/checkout@v4
    - run: docker compose -f .github/workflows/test/cockroachdb.docker-compose up -d
    - run: npm i
    - run: cp .github/workflows/test/cockroachdb.ormconfig.json ormconfig.json
    - run: npm test


  mongodb:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        node-container: ["node:18"] #["node:16", "node:18", "node:20", "node:22"]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    container: ${{ matrix.node-container }}
    services:
      mongodb:
        image: mongo:5.0.12

    steps:
    - uses: actions/checkout@v4
    - run: npm i
    - run: cp .github/workflows/test/mongodb.ormconfig.json ormconfig.json
    - run: npm test


  mssql:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        node-container: ["node:18"] #["node:16", "node:18", "node:20", "node:22"]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    container: ${{ matrix.node-container }}
    services:
      mssql:
        image: "mcr.microsoft.com/mssql/server:2022-latest"
        env:
          SA_PASSWORD: "Admin12345"
          ACCEPT_EULA: "Y"

    steps:
    - uses: actions/checkout@v4
    - run: npm i
    - run: cp .github/workflows/test/mssql.ormconfig.json ormconfig.json
    - run: npm test


  mysql_mariadb:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        node-container: ["node:18"] #["node:16", "node:18", "node:20", "node:22"]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    container: ${{ matrix.node-container }}
    services:
      mysql:
        image: mysql:5.7.37
        env:
          MYSQL_ROOT_PASSWORD: "admin"
          MYSQL_USER: "test"
          MYSQL_PASSWORD: "test"
          MYSQL_DATABASE: "test"
      mariadb:
        image: mariadb:10.10.3
        env:
          MYSQL_ROOT_PASSWORD: "admin"
          MYSQL_USER: "test"
          MYSQL_PASSWORD: "test"
          MYSQL_DATABASE: "test"

    steps:
    - uses: actions/checkout@v4
    - run: npm i
    - run: cp .github/workflows/test/mysql-mariadb.ormconfig.json ormconfig.json
    - run: npm test


  oracle:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        node-version: [18.x] #["node:16", "node:18", "node:20", "node:22"]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
    - uses: actions/setup-node@v4
      with:
        node-version: ${{matrix.node-version}}
    - uses: actions/checkout@v4
    - run: docker compose -f .github/workflows/test/oracle.docker-compose up -d
    - run: npm i
    - run: cp .github/workflows/test/oracle.ormconfig.json ormconfig.json
    - run: npm test


  better-sqlite3:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        node-container: ["node:18"] #["node:16", "node:18", "node:20", "node:22"]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    container: ${{ matrix.node-container }}

    steps:
    - uses: actions/checkout@v4
    - run: npm i
    - run: cp .github/workflows/test/better-sqlite3.ormconfig.json ormconfig.json
    - run: npm test
  

  sqlite:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        node-container: ["node:18"] #["node:16", "node:18", "node:20", "node:22"]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    container: ${{ matrix.node-container }}

    steps:
    - uses: actions/checkout@v4
    - run: npm i
    - run: cp .github/workflows/test/sqlite.ormconfig.json ormconfig.json
    - run: npm test


  sqljs:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        node-container: ["node:18"] #["node:16", "node:18", "node:20", "node:22"]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    container: ${{ matrix.node-container }}

    steps:
    - uses: actions/checkout@v4
    - run: npm i
    - run: cp .github/workflows/test/sqljs.ormconfig.json ormconfig.json
    - run: npm test


  posgres:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        node-container: ["node:18"] #["node:16", "node:18", "node:20", "node:22"]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    container: ${{ matrix.node-container }}
    services:
      postgres:
        image: postgis/postgis:14-3.3
        env:
          POSTGRES_USERNAME: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: postgres
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    steps:
    - uses: actions/checkout@v4
    - run: npm i
    - run: cp .github/workflows/test/postgres.ormconfig.json ormconfig.json
    - run: npm test
