trigger:
  branches:
    include:
    - '*'
  tags:
    include:
    - v*
variables:
  PYTHON_VERSION: 3.8
  CONDA_ENV: test-env
resources:
  containers:
  - container: ubuntu1404
    image: lightgbm/vsts-agent:ubuntu-14.04
jobs:
###########################################
- job: Linux
###########################################
  variables:
    COMPILER: gcc
  pool:
    vmImage: 'ubuntu-latest'
  container: ubuntu1404
  strategy:
    maxParallel: 6
    matrix:
      regular:
        TASK: regular
      sdist:
        TASK: sdist
        PYTHON_VERSION: 3.5
      bdist:
        TASK: bdist
        PYTHON_VERSION: 3.7
      inference:
        TASK: if-else
      mpi_source:
        TASK: mpi
        METHOD: source
      gpu_source:
        TASK: gpu
        METHOD: source
        PYTHON_VERSION: 3.6
  steps:
  - script: |
      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(), in(variables['TASK'], 'regular', 'sdist', 'bdist'), not(startsWith(variables['Build.SourceBranch'], 'refs/pull/')))
    inputs:
      pathtoPublish: '$(Build.ArtifactStagingDirectory)'
      artifactName: PackageAssets
      artifactType: container
###########################################
- job: MacOS
###########################################
  variables:
    COMPILER: clang
  pool:
    vmImage: 'macOS-10.14'
  strategy:
    maxParallel: 3
    matrix:
      regular:
        TASK: regular
        PYTHON_VERSION: 3.7
      sdist:
        TASK: sdist
        PYTHON_VERSION: 3.5
      bdist:
        TASK: bdist
  steps:
  - script: |
      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"
      echo "##vso[task.setvariable variable=JAVA_HOME]$JAVA_HOME_8_X64"
    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(), in(variables['TASK'], 'regular', 'sdist', 'bdist'), not(startsWith(variables['Build.SourceBranch'], 'refs/pull/')))
    inputs:
      pathtoPublish: '$(Build.ArtifactStagingDirectory)'
      artifactName: PackageAssets
      artifactType: container
###########################################
- job: Windows
###########################################
  pool:
    vmImage: 'vs2017-win2016'
  strategy:
    maxParallel: 4
    matrix:
      r_package:
        TASK: r-package
        COMPILER: MSVC
      regular:
        TASK: regular
        PYTHON_VERSION: 3.6
      sdist:
        TASK: sdist
        PYTHON_VERSION: 2.7
      bdist:
        TASK: bdist
  steps:
  - powershell: |
      Write-Host "##vso[task.prependpath]$env:CONDA\Scripts"
      Write-Host "##vso[task.setvariable variable=AZURE]true"
    displayName: 'Set Variables'
  - script: |
      cmd /c "conda init powershell"
      cmd /c "powershell -ExecutionPolicy Bypass -File %BUILD_SOURCESDIRECTORY%/.ci/test_windows.ps1"
    displayName: Test
  - task: PublishBuildArtifacts@1
    condition: and(succeeded(), in(variables['TASK'], 'regular', 'sdist', 'bdist'), 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
  - task: GitHubRelease@0
    displayName: 'Create GitHub Release'
    condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
    inputs:
      gitHubConnection: guolinke
      repositoryName: '$(Build.Repository.Name)'
      action: 'create'
      target: '$(Build.SourceVersion)'
      tagSource: 'auto'
      title: '$(Build.SourceBranchName)'
      assets: |
        $(Build.SourcesDirectory)/binaries/PackageAssets/*
        $(Build.ArtifactStagingDirectory)/*.nupkg
      assetUploadMode: 'delete'
      isDraft: true
      isPreRelease: false
      addChangeLog: false
