# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on: [push]

jobs:
  test:
    strategy:
      matrix:
        node_version: ['12']
        db_dialect: ['postgres']
        pg_version: ['12']

    runs-on: ubuntu-latest
    container: node:${{ matrix.node_version }}
    services:
      # Label used to access the service container
      postgres:
        # Docker Hub image
        image: postgres:${{ matrix.pg_version }}
        # Provide the password for postgres
        env:
          POSTGRES_USER: nocobase
          POSTGRES_PASSWORD: password
        # Set health checks to wait until postgres has started
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    steps:
    - uses: actions/checkout@v2
    - run: npm i
    - run: npm run bootstrap
    - run: npm run build
    - name: Test
      run: npm test
      env:
        DB_DIALECT: ${{ matrix.db_dialect }}
        DB_HOST: ${{ matrix.db_dialect }}
        DB_PORT: 5432
        DB_USER: nocobase
        DB_PASSWORD: password
        DB_DATABASE: nocobase