trigger:
  # start a new build for every push
  batch: False
  branches:
    include:
      - main
      - maintenance/*


pr:
  branches:
    include:
    - '*'  # must quote since "*" is a YAML reserved character; we want a string


stages:

- stage: Check
  jobs:
    - job: Skip
      pool:
        vmImage: 'ubuntu-22.04'
      variables:
        DECODE_PERCENTS: 'false'
        RET: 'true'
      steps:
      - bash: |
          git_log=`git log --max-count=1 --skip=1 --pretty=format:"%B" | tr "\n" " "`
          echo "##vso[task.setvariable variable=log]$git_log"
      - bash: echo "##vso[task.setvariable variable=RET]false"
        condition: or(contains(variables.log, '[skip azp]'), contains(variables.log, '[azp skip]'), contains(variables.log, '[skip ci]'), contains(variables.log, '[ci skip]'))
      - bash: echo "##vso[task.setvariable variable=start_main;isOutput=true]$RET"
        name: result

- stage: ComprehensiveTests
  condition: and(succeeded(), eq(dependencies.Check.outputs['Skip.result.start_main'], 'true'))
  dependsOn: Check
  jobs:

  - job: Lint
    condition: and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'))
    pool:
      vmImage: 'ubuntu-22.04'
    steps:
    - task: UsePythonVersion@0
      inputs:
        versionSpec: '3.10'
        addToPath: true
        architecture: 'x64'
    - script: >-
        python -m pip install -r requirements/linter_requirements.txt
      displayName: 'Install tools'
      # pip 21.1 emits a pile of garbage messages to annoy users :)
      #      failOnStderr: true
    - script: |
        python tools/linter.py --branch origin/$(System.PullRequest.TargetBranch)
      displayName: 'Run Lint Checks'
      failOnStderr: true

  - job: Linux_Python_310_32bit_full_with_asserts
    pool:
      vmImage: 'ubuntu-22.04'
    steps:
    - script: |
        git submodule update --init
      displayName: 'Fetch submodules'
    - script: |
            # yum does not have a ninja package, so use the PyPI one
            docker run -v $(pwd):/numpy -e CFLAGS="-msse2 -std=c99 -UNDEBUG" \
            -e F77=gfortran-5 -e F90=gfortran-5 quay.io/pypa/manylinux2014_i686 \
            /bin/bash -xc "source /numpy/tools/ci/run_32_bit_linux_docker.sh"
      displayName: 'Run 32-bit manylinux2014 Docker Build / Tests'

  - job: Windows
    timeoutInMinutes: 120
    pool:
      vmImage: 'windows-2019'
    strategy:
      maxParallel: 3
      matrix:
          Python310-64bit-fast:
            PYTHON_VERSION: '3.10'
            PYTHON_ARCH: 'x64'
            TEST_MODE: fast
            BITS: 64
          Python311-64bit-full:
            PYTHON_VERSION: '3.11'
            PYTHON_ARCH: 'x64'
            TEST_MODE: full
            BITS: 64
            _USE_BLAS_ILP64: '1'
          PyPy310-64bit-fast:
            PYTHON_VERSION: 'pypy3.10'
            PYTHON_ARCH: 'x64'
            TEST_MODE: fast
            BITS: 64
            _USE_BLAS_ILP64: '1'

    steps:
    - template: azure-steps-windows.yml
