name: ci

on:
  push:
    branches: [ "master", "develop" ]
  pull_request:
    branches: develop

jobs:

  golangci:
    name: lint
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-go@v4
        with:
          go-version-file: 'go.mod'
      - name: golangci-lint
        uses: golangci/golangci-lint-action@v3
        with:
          args: --timeout=5m

  integration:
    name: integration
    runs-on: ubuntu-20.04

    services:
      postgres:
        image: postgres:latest
        env:
          POSTGRES_DB: postgres
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
        ports:
          - 5432:5432
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    steps:
      - name: Add database extensions
        run: |
          psql -h localhost -U postgres -tc "CREATE EXTENSION pg_trgm;"
        env:
          PGPASSWORD: postgres

      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Run Tests
        uses: actions/setup-go@v4
        with:
          go-version-file: 'go.mod'
      - run: |
          go test -v -cover ./...
