# 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: tests
on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

# The service containers will use host port binding instead of container networking so you access them via localhost rather than the service name
jobs:
  vm-job:
    runs-on: ubuntu-latest
    timeout-minutes: 5
    strategy:
      matrix:
        node-version: [18.x, 20.x]

    services:
      postgres:
        image: postgis/postgis:16-3.4
        #image: postgres:10.8
        env:
          POSTGRES_USER: api
          POSTGRES_PASSWORD: api
          POSTGRES_DB: prostgles_server_tests
        ports:
          # will assign a random free host port
          - 5432/tcp
        # needed because the postgres container does not provide a healthcheck
        options: >-
          --health-cmd pg_isready 
          --health-interval 10s 
          --health-timeout 5s
          --health-retries 10

    steps:
      - uses: actions/checkout@v1
      - run: npm ci
        # working-directory: ./postgres
      - run: npm test
        # working-directory: ./postgres
        env:
          # use localhost for the host here because we are running the job on the VM.
          # If we were running the job on in a container this would be postgres
          POSTGRES_HOST: localhost
          POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }} # get randomly assigned published port
