variables:
  PYTHON_VERSION: 3.7
  CONDA_ENV: test-env
resources:
  containers:
  - container: ubuntu1404
    image: lightgbm/vsts-agent:ubuntu-14.04
jobs:
###########################################
- job: Linux
###########################################
  variables:
    COMPILER: gcc
  pool:
    vmImage: 'ubuntu-16.04'
  container: ubuntu1404
  strategy:
    maxParallel: 6
    matrix:
      regular:
        TASK: regular
      sdist:
        TASK: sdist
        PYTHON_VERSION: 3.5
      bdist:
        TASK: bdist
        PYTHON_VERSION: 3.6
      inference:
        TASK: if-else
      mpi_source:
        TASK: mpi
        METHOD: source
        PYTHON_VERSION: 2.7
      gpu_source:
        TASK: gpu
        METHOD: source
        PYTHON_VERSION: 3.6
  steps:
  - script: |
      echo "##vso[task.setvariable variable=HOME_DIRECTORY]$AGENT_HOMEDIRECTORY"
      echo "##vso[task.setvariable variable=BUILD_DIRECTORY]$BUILD_SOURCESDIRECTORY"
      echo "##vso[task.setvariable variable=OS_NAME]linux"
      echo "##vso[task.setvariable variable=AZURE]true"
      echo "##vso[task.setvariable variable=LGB_VER]$(head -n 1 VERSION.txt)"
      echo "##vso[task.prependpath]$CONDA/bin"
      AMDAPPSDK_PATH=$BUILD_SOURCESDIRECTORY/AMDAPPSDK
      echo "##vso[task.setvariable variable=AMDAPPSDK_PATH]$AMDAPPSDK_PATH"
      LD_LIBRARY_PATH=$AMDAPPSDK_PATH/lib/x86_64:$LD_LIBRARY_PATH
      echo "##vso[task.setvariable variable=LD_LIBRARY_PATH]$LD_LIBRARY_PATH"
      echo "##vso[task.setvariable variable=OPENCL_VENDOR_PATH]$AMDAPPSDK_PATH/etc/OpenCL/vendors"
    displayName: 'Set variables'
  - bash: $(Build.SourcesDirectory)/.ci/setup.sh
    displayName: Setup
  - bash: $(Build.SourcesDirectory)/.ci/test.sh
    displayName: Test
  - task: PublishBuildArtifacts@1
    condition: and(succeeded(), not(startsWith(variables['Build.SourceBranch'], 'refs/pull/')))
    inputs:
      pathtoPublish: '$(Build.ArtifactStagingDirectory)'
      artifactName: PackageAssets
      artifactType: container
###########################################
- job: MacOS
###########################################
  variables:
    COMPILER: clang
  pool:
    vmImage: 'macOS-10.13'
  strategy:
    maxParallel: 3
    matrix:
      regular:
        TASK: regular
        PYTHON_VERSION: 3.6
      sdist:
        TASK: sdist
        PYTHON_VERSION: 3.5
      bdist:
        TASK: bdist
  steps:
  - script: |
      echo "##vso[task.setvariable variable=HOME_DIRECTORY]$AGENT_HOMEDIRECTORY"
      echo "##vso[task.setvariable variable=BUILD_DIRECTORY]$BUILD_SOURCESDIRECTORY"
      echo "##vso[task.setvariable variable=OS_NAME]macos"
      echo "##vso[task.setvariable variable=AZURE]true"
      echo "##vso[task.setvariable variable=LGB_VER]$(head -n 1 VERSION.txt)"
      CONDA=$AGENT_HOMEDIRECTORY/miniconda
      echo "##vso[task.setvariable variable=CONDA]$CONDA"
      echo "##vso[task.prependpath]$CONDA/bin"
    displayName: 'Set variables'
  - bash: $(Build.SourcesDirectory)/.ci/setup.sh
    displayName: Setup
  - bash: $(Build.SourcesDirectory)/.ci/test.sh
    displayName: Test
  - task: PublishBuildArtifacts@1
    condition: and(succeeded(), not(startsWith(variables['Build.SourceBranch'], 'refs/pull/')))
    inputs:
      pathtoPublish: '$(Build.ArtifactStagingDirectory)' 
      artifactName: PackageAssets
      artifactType: container
###########################################
- job: Windows
###########################################
  pool:
    vmImage: 'vs2017-win2016'
  strategy:
    maxParallel: 3
    matrix:
      regular:
        TASK: regular
        PYTHON_VERSION: 3.5
      sdist:
        TASK: sdist
        PYTHON_VERSION: 2.7
      bdist:
        TASK: bdist
        PYTHON_VERSION: 3.6
  steps:
  - powershell: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts"
    displayName: Enable conda
  - script: |
      conda update -q -y conda
      conda create -q -y -n %CONDA_ENV% python=%PYTHON_VERSION% matplotlib nose numpy pandas psutil pytest python-graphviz scikit-learn scipy
      cmd /c "activate %CONDA_ENV% & powershell -ExecutionPolicy Bypass -File %BUILD_SOURCESDIRECTORY%/.ci/test_windows.ps1"
    displayName: Test
  - task: PublishBuildArtifacts@1
    condition: and(succeeded(), not(startsWith(variables['Build.SourceBranch'], 'refs/pull/')))
    inputs:
      pathtoPublish: '$(Build.ArtifactStagingDirectory)'
      artifactName: PackageAssets
      artifactType: container

###########################################
- job: Package
###########################################
  dependsOn:
  - Linux
  - MacOS
  - Windows
  condition: and(succeeded(), not(startsWith(variables['Build.SourceBranch'], 'refs/pull/')))
  pool:
    vmImage: 'vs2017-win2016'
  steps:
  # Download all agent packages from all previous phases
  - task: DownloadBuildArtifacts@0
    displayName: Download package assets
    inputs:
      artifactName: PackageAssets
      downloadPath: $(Build.SourcesDirectory)/binaries
  - script: |
      python %BUILD_SOURCESDIRECTORY%/.nuget/create_nuget.py %BUILD_SOURCESDIRECTORY%/binaries/PackageAssets
    displayName: 'Create NuGet configuration files'
  - task: NuGetCommand@2
    inputs:
      command: pack
      packagesToPack: '$(Build.SourcesDirectory)/.nuget/*.nuspec'
      packDestination: '$(Build.ArtifactStagingDirectory)'
  - task: PublishBuildArtifacts@1
    inputs:
      pathtoPublish: '$(Build.ArtifactStagingDirectory)'
      artifactName: NuGet
      artifactType: container
