name: tests

on:
  pull_request:
    types: [opened, synchronize]
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest
    timeout-minutes: 5
    strategy:
      matrix:
        node-version: ["10", "12", "14"]

    name: Testing on Node.js ${{ matrix.node }}
    steps:
      - uses: actions/checkout@v3
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
      # - name: Prettier Action on PR
      #   if: github.event_name == 'pull_request'
      #   uses: creyD/prettier_action@v3.0
      #   with:
      #     prettier_version: ^2.1.1
      #     commit_message: "Run prettier via GitHub Action"
      #     file_pattern: "."
      #   env:
      #     GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      # 
      # - name: Prettier Action on master
      #   if: github.ref == 'refs/heads/master'
      #   uses: creyD/prettier_action@v3.0
      #   with:
      #     prettier_version: ^2.1.1
      #     commit_message: "Run prettier via GitHub Action"
      #     file_pattern: "."
      #   env:
      #     GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      
      - uses: harmon758/postgresql-action@v1
        with:
          postgresql version: "12"
          postgresql user: "user"
          postgresql password: "password"

      - run: npm ci
      - run: npm test
        env:
          CI: true
          NODE_ENV: test
          PG_CONNECTION_STRING: "postgresql://user:password@localhost"
