name: CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  testenv:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: ['3.5', '3.6', '3.7', '3.8', '3.9']
        django-version: ['master', '2.0', '2.1', '2.2', '3.0', '3.1', '3.2', '4.0']
        exclude:
          - python-version: '3.8'
            django-version: '2.0'
          - python-version: '3.9'
            django-version: '2.0'

          - python-version: '3.8'
            django-version: '2.1'
          - python-version: '3.9'
            django-version: '2.1'

          - python-version: '3.5'
            django-version: '3.0'

          - python-version: '3.5'
            django-version: '3.1'

          - python-version: '3.5'
            django-version: '3.2'

          - python-version: '3.5'
            django-version: '4.0'
          - python-version: '3.6'
            django-version: '4.0'
          - python-version: '3.7'
            django-version: '4.0'

          - python-version: '3.5'
            django-version: 'master'
          - python-version: '3.6'
            django-version: 'master'
          - python-version: '3.7'
            django-version: 'master'
          - python-version: '3.8'
            django-version: 'master'

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install tox tox-gh-actions coveralls
    - name: Tox Test
      run: tox
      env:
        PYTHON_VER: ${{ matrix.python-version }}
        DJANGO: ${{ matrix.django-version }}
    - name: Coverage (Coveralls)
      if: ${{ success() }}
      run: coveralls --service=github
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  extra:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        extra-env: ['docs', 'checkqa', 'standardjs']
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v2
      if: ${{ matrix.extra-env == 'standardjs' }}
      with:
        node-version: '8'
    - name: Set up Python 3.7
      uses: actions/setup-python@v2
      with:
        python-version: '3.7'
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install tox
    - name: Tox Test
      run: tox
      env:
        TOXENV: ${{ matrix.extra-env }}
