name: django-cte tests
on:
  push:
    branches: [master]
  pull_request:
    branches: [master]

jobs:
  tests:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python: ['3.8', '3.9', '3.10', '3.11', '3.12']
        django:
        - 'Django>=3.2,<3.3'
        - 'Django>=4.1,<4.2'
        - 'Django>=4.2,<4.3'
    services:
      postgres:
        image: postgres:latest
        env:
          POSTGRES_DB: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_USER: postgres
        ports:
          - 5432:5432
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
    steps:
    - uses: actions/checkout@v3
    - uses: actions/setup-python@v4
      with:
        python-version: ${{ matrix.python }}
    - name: Setup
      run: |
        python --version
        pip install --upgrade pip wheel
        pip install "${{ matrix.django }}" psycopg2-binary pynose flake8
    - name: Run tests
      env:
        DB_SETTINGS: >-
          {
            "ENGINE":"django.db.backends.postgresql_psycopg2",
            "NAME":"django_cte",
            "USER":"postgres",
            "PASSWORD":"postgres",
            "HOST":"localhost",
            "PORT":"5432"
          }
      run: nosetests -v --capture_output
    - name: Check style
      run: flake8 django_cte/ tests/
