name: CI
on:
  push:
  pull_request:
  workflow_dispatch:
env:
  GH_AUTH: ${{ secrets.GH_AUTH }}
  GH_USER: ${{ secrets.GH_USER }}

jobs:
  lint:
    runs-on: ubuntu-20.04
    continue-on-error: true
    steps:
      - uses: actions/checkout@v3
      - uses: ./.github/workflows/setupgo118amd64
        with:
          user: ${{ secrets.GH_USER }}
          pat: ${{ secrets.GH_AUTH }}
      - name: golangci-lint
        uses: golangci/golangci-lint-action@v3
        with:
          version: latest
          only-new-issues: true
          skip-pkg-cache: true
          skip-build-cache: true

  build_test:
    name: Build and Test
    needs:
      - lint
    runs-on: ubuntu-20.04
    services:
      postgres:
        image: postgres
        env:
          POSTGRES_PASSWORD: password
        ports:
          - 5432:5432
        # Set health checks to wait until postgres has started
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
      mongo:
        image: mongo:3.6-xenial
        options: >-
          --health-cmd "mongo test --quiet --eval 'quit(db.runCommand(\"ping\").ok ? 0 : 1)'"
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          - 27017:27017
    steps:
      - uses: actions/checkout@v3
      - name: Install dependencies
        run: sudo apt-get update -y && sudo apt-get install -y gcc git-core
      - uses: ./.github/workflows/setupgo118amd64
      - name: Build and Test
        run: go test -mod readonly ./...
        env:
          MGOCONNECTIONSTRING: localhost:27017
          PGHOST: localhost
          PGPASSWORD: password
          PGSSLMODE: disable
          PGUSER: postgres
          PGPORT: 5432
