resources:
  - repo: self

trigger:
  batch: true
  branches:
    include:
      - '*'

pr:
  branches:
    include:
      - '*'

jobs:
  - job: TestInstall
    timeoutInMinutes: 10

    pool:
      name: 'pool-ubuntu-2204'
    strategy:
      matrix:
        Python39:
          python.version: '3.9'
        Python310:
          python.version: '3.10'
        Python311:
          python.version: '3.11'
        Python312:
          python.version: '3.12'
    steps:
      - task: UsePythonVersion@0
        displayName: 'Use Python $(python.version)'
        inputs:
          versionSpec: '$(python.version)'
      - bash: |
          set -ev

          pip install -e .
        displayName: Install from Source

  - job: BuildPythonWheel
    condition: succeeded()
    pool:
      name: 'pool-ubuntu-2204'
    steps:
      - task: UsePythonVersion@0
        displayName: Use Python 3.12
        inputs:
          versionSpec: 3.12
      - bash: |
          set -ev

          : "${BUILD_STAGINGDIRECTORY:?BUILD_STAGINGDIRECTORY environment variable not set}"

          echo "Build knack"
          pip install -U pip setuptools wheel
          python setup.py bdist_wheel -d "${BUILD_STAGINGDIRECTORY}"
          python setup.py sdist -d "${BUILD_STAGINGDIRECTORY}"
        displayName: Build Wheel
      - task: PublishPipelineArtifact@0
        displayName: 'Publish Artifact: pypi'
        inputs:
          TargetPath: $(Build.ArtifactStagingDirectory)
          ArtifactName: pypi
      - task: DownloadPipelineArtifact@1
        displayName: 'Download PyPI Packages'
        inputs:
          TargetPath: '$(Build.ArtifactStagingDirectory)/pypi'
          artifactName: pypi
      - bash: |
          set -ev

          cd $BUILD_ARTIFACTSTAGINGDIRECTORY/pypi
          pwd
          ls -la
        displayName: Test Build Wheel
