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:
      UbuntuPy36:
        python.version: '3.6'
        vmImage: 'ubuntu-latest'
        tox_env: 'py36'
      UbuntuPy37:
        python.version: '3.7'
        vmImage: 'ubuntu-latest'
        tox_env: 'py37'
      UbuntuPy38:
        python.version: '3.8'
        vmImage: 'ubuntu-latest'
        tox_env: 'py38'

      macOSPy36:
        python.version: '3.6'
        vmImage: 'macOS-latest'
        tox_env: 'py36'
      macOSPy37:
        python.version: '3.7'
        vmImage: 'macOS-latest'
        tox_env: 'py37'
      macOSPy38:
        python.version: '3.8'
        vmImage: 'macOS-latest'
        tox_env: 'py38'

      WindowsServerPy36:
        python.version: '3.6'
        vmImage: 'vs2017-win2016'
        tox_env: 'py36'
      WindowsServerPy37:
        python.version: '3.7'
        vmImage: 'vs2017-win2016'
        tox_env: 'py37'
      WindowsServerPy38:
        python.version: '3.8'
        vmImage: 'vs2017-win2016'
        tox_env: 'py38'

      WindowsPy36:
        python.version: '3.6'
        vmImage: 'windows-latest'
        tox_env: 'py36'
      WindowsPy37:
        python.version: '3.7'
        vmImage: 'windows-latest'
        tox_env: 'py37'
      WindowsPy38:
        python.version: '3.8'
        vmImage: 'windows-latest'
        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