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.11'
        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
      displayName: 'Run Lint Checks'
      failOnStderr: true
    - script: |
        python tools/check_python_h_first.py
      displayName: 'Check Python.h is first file included'

  - job: Linux_Python_311_32bit_full_with_asserts
    pool:
      vmImage: 'ubuntu-22.04'
    steps:
    - script: |
        git submodule update --init
      displayName: 'Fetch submodules'
    - script: |
            # There are few options for i686 images at https://quay.io/organization/pypa,
            # use the glibc2.17 one (manylinux2014)
            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-2022'
    strategy:
      maxParallel: 3
      matrix:
          Python311-64bit-fast:
            PYTHON_VERSION: '3.11'
            PYTHON_ARCH: 'x64'
            TEST_MODE: fast
            BITS: 64
          Python312-64bit-full:
            PYTHON_VERSION: '3.12'
            PYTHON_ARCH: 'x64'
            TEST_MODE: full
            BITS: 64
            _USE_BLAS_ILP64: '1'
# TODO pypy: uncomment when pypy3.11 comes out
#          PyPy311-64bit-fast:
#            PYTHON_VERSION: 'pypy3.11'
#            PYTHON_ARCH: 'x64'
#            TEST_MODE: fast
#            BITS: 64
#            _USE_BLAS_ILP64: '1'

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