# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
- master

jobs:
- job: Windows
  pool:
    vmIMage: 'VS2017-Win2016'
  variables:
    AZURE_CI_WINDOWS: 'true'
    LIBGL_ALWAYS_SOFTWARE: true
    LIBGL_ALWAYS_INDIRECT: false
  strategy:
    maxParallel: 4
    matrix:
      Python37-64bit + OPTIONAL_DEPS:
        python.version: '3.7'
        OPTIONAL_DEPS: true
      Python37-64bit:
        python.version: '3.7'
      Python38-64bit:
        python.version: '3.8'
      Python39-64bit:
        python.version: '3.9'
      CONDA Python38-64bit + OPTIONAL_DEPS:
        python.version: '3.8'
        OPTIONAL_DEPS: true
        INSTALL_TYPE: "conda"
      CONDA Python39-64bit:
        python.version: '3.9'
        INSTALL_TYPE: "conda"
  steps:
  - task: UsePythonVersion@0
    inputs:
      versionSpec: $(python.version)
      architecture: 'x64'
      addToPath: true
  - powershell: |
      Write-Host "##vso[task.prependpath]$env:CONDA\Scripts"
    displayName: Add Conda to PATH
    condition: eq( variables['INSTALL_TYPE'], 'conda' )
  - powershell: |
      Invoke-WebRequest -Uri https://stacks.stanford.edu/file/druid:yx282xq2090/dwi.bvals -UseDefaultCredentials
    displayName: Add/Verify whether the certificate has been installed correctly
  - powershell: |
      Set-StrictMode -Version Latest
      $ErrorActionPreference = "Stop"
      $PSDefaultParameterValues['*:ErrorAction']='Stop'
      powershell ./ci/windows/install_opengl.ps1
    displayName: 'Install OpenGL'
  - powershell: |
      Set-StrictMode -Version Latest
      $ErrorActionPreference = "Stop"
      $PSDefaultParameterValues['*:ErrorAction']='Stop'
      ./ci/windows/install.ps1
    displayName: 'Install dependencies'
  - powershell: |
      $overall_code = 0
      $fileList = Get-ChildItem -Recurse -Path ./fury -Include test_*.py | Select-Object -ExpandProperty FullName
      foreach ($textfile in $fileList) {
        Write-Output "Processed file: $textfile"
        powershell -File ci/windows/script.ps1 $textfile
        $Code1 = $LASTEXITCODE
        if ( $Code1 -ne 0 )
        {
          $overall_code = 1
        }
      }
      if ($env:INSTALL_TYPE -eq 'conda' -And $overall_code -ne 0) {
        Write-Host "\043#vso[task.logissue type=warning;] Error during tests on Conda matrix"
      }
      else {
        exit $overall_code
      }
    displayName: 'Run Tests'
