name: postgres
on:
  pull_request:
  push:
    branches:
      - master
    paths:
      - pyproject.toml
      - poetry.lock
      - "**.py"
jobs:
  postgres-version:
    runs-on: ubuntu-latest
    strategy:
      max-parallel: 4
      matrix:
        postgres-version: [13, 14, 15, 16, 17]
        psycopg-version: ["psycopg", "psycopg2"]
    services:
      postgres:
        image: postgres:${{ matrix.postgres-version }}
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: sandbox
        ports:
          - 5432:5432
        options: --name postgres --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
    steps:
      - uses: actions/checkout@v3
      - name: Install poetry
        run: pipx install poetry
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: "3.x"
      - name: Install Dependencies
        run: poetry install
      - name: Install psycopg specific version ${{ matrix.psycopg-version }}
        run: poetry run pip install ${{ matrix.psycopg-version }}
      - name: Run Tests
        run: poetry run pytest sandbox/tests
