trigger:
  branches:
    include:
    - master
pr:
  - "*"

jobs:
- job: pytest
  strategy:
    # use cross-product when https://github.com/microsoft/azure-pipelines-yaml/issues/20 is solved
    matrix:
      UbuntuPython36:
        python.version: '3.6'
        vmImage: 'ubuntu-16.04'
        tox_env: 'py36'
      UbuntuPython37:
        python.version: '3.7'
        vmImage: 'ubuntu-16.04'
        tox_env: 'py37'
      UbuntuPython38:
        python.version: '3.8'
        vmImage: 'ubuntu-16.04'
        tox_env: 'py38'

      macOSPython36:
        python.version: '3.6'
        vmImage: 'macOS-10.13'
        tox_env: 'py36'
      macOSPython37:
        python.version: '3.7'
        vmImage: 'macOS-10.13'
        tox_env: 'py37'
      macOSPython38:
        python.version: '3.8'
        vmImage: 'macOS-10.13'
        tox_env: 'py38'

      WindowsPython36:
        python.version: '3.6'
        vmImage: 'vs2017-win2016'
        tox_env: 'py36'
      WindowsPython37:
        python.version: '3.7'
        vmImage: 'vs2017-win2016'
        tox_env: 'py37'
      WindowsPython38:
        python.version: '3.8'
        vmImage: 'vs2017-win2016'
        tox_env: 'py38'
  pool:
    vmImage: '$(vmImage)'
  steps:
  - task: UsePythonVersion@0
    inputs:
      versionSpec: '$(python.version)'
  - script: pip install tox
    displayName: Install tox
  - script: tox -e $(tox_env)-mindeps
    displayName: Run the tests with minimal dependencies
  - script: tox -e clean
    displayName: Clean
  - script: tox -e $(tox_env)-alldeps
    displayName: Run the tests

- job: coverage
  steps:
  - task: UsePythonVersion@0
    inputs:
      versionSpec: '3.7'
  - script: pip install tox
    displayName: Install tox
  - script: tox -e py37-alldeps,report
    displayName: Run the tests and generate coverage
  - script: |
      pip install codecov
      codecov -t $(CODECOV_TOKEN) -f .coverage.xml
    displayName: Test upload coverage

- job: pre_commit
  steps:
  - task: UsePythonVersion@0
    inputs:
      versionSpec: '3.7'
  - script: pip install tox
    displayName: Install tox
  - script: tox -e pre-commit
    displayName: Lining tests

- job: authors_check
  steps:
  - script: |
      MISSING_AUTHORS=$(git shortlog -s HEAD | sed -e "s/^[0-9\t ]*//"| xargs -i sh -c 'grep -q "{}" AUTHORS.md || echo "{} missing from authors"')
      if [ ! -z "$MISSING_AUTHORS" ]; then { echo $MISSING_AUTHORS; exit 1; }; fi
    displayName: 'Authors check'
    continueOnError: true