# Azure hosted agents specification:
# https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops

jobs:
- job: 'ubuntu_1804_python36'
  pool:
    vmImage: 'Ubuntu 18.04'

  steps:
  - script: |
      set -e
      python3 -m pip install --upgrade pip setuptools --user
      python3 -m pip install coverage --user
      echo "##vso[task.setvariable variable=PATH]${HOME}/.local/bin:${PATH}"
    displayName: 'Install python tools'
  - script: |
      source install.sh
    displayName: 'Install nni toolkit via source code'
  - script: |
      set -e
      cd src/nni_manager
      yarn eslint
      # uncomment following 2 lines to enable webui eslint
      cd ../webui
      yarn eslint
    displayName: 'Run eslint'
  - script: |
      set -e
      sudo apt-get install -y pandoc
      python3 -m pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html --user
      python3 -m pip install tensorflow==2.2.0 --user
      python3 -m pip install keras==2.4.2 --user
      python3 -m pip install gym onnx peewee thop --user
      python3 -m pip install sphinx==1.8.3 sphinx-argparse==0.2.5 sphinx-markdown-tables==0.0.9 sphinx-rtd-theme==0.4.2 sphinxcontrib-websupport==1.1.0 recommonmark==0.5.0 nbsphinx --user
      sudo apt-get install swig -y
      nnictl package install --name=SMAC
      nnictl package install --name=BOHB
    displayName: 'Install dependencies'
  - script: |
      cd test
      source scripts/unittest.sh
    displayName: 'Unit test'
  - script: |
      cd test
      python3 nni_test/nnitest/run_tests.py --config config/pr_tests.yml
    displayName: 'Simple test'
  - script: |
      cd docs/en_US/
      sphinx-build -M html . _build -W
    displayName: 'Sphinx Documentation Build check'

- job: 'ubuntu_1604_python35_legacy_torch_tf'
  pool:
    vmImage: 'Ubuntu 16.04'

  steps:
  - script: |
      set -e
      python3 -m pip install --upgrade pip setuptools --user
      python3 -m pip install pylint==2.3.1 astroid==2.2.5 --user
      python3 -m pip install coverage --user
      python3 -m pip install thop --user
      echo "##vso[task.setvariable variable=PATH]${HOME}/.local/bin:${PATH}"
    displayName: 'Install python tools'
  - script: |
      source install.sh
    displayName: 'Install nni toolkit via source code'
  - script: |
      set -e
      python3 -m pip install torch==1.3.1+cpu torchvision==0.4.2+cpu -f https://download.pytorch.org/whl/torch_stable.html --user
      python3 -m pip install tensorflow==1.15.2 --user
      python3 -m pip install keras==2.1.6 --user
      python3 -m pip install gym onnx peewee --user
      sudo apt-get install swig -y
      nnictl package install --name=SMAC
      nnictl package install --name=BOHB
    displayName: 'Install dependencies'
  - script: |
      set -e
      python3 -m pylint --rcfile pylintrc nni_annotation
      python3 -m pylint --rcfile pylintrc nni_cmd
      python3 -m pylint --rcfile pylintrc nni_gpu_tool
      python3 -m pylint --rcfile pylintrc nni_trial_tool
      python3 -m pylint --rcfile pylintrc nni
      python3 -m pylint --rcfile pylintrc nnicli
    displayName: 'Run pylint'
  - script: |
      set -e
      python3 -m pip install flake8 --user
      EXCLUDES=./src/nni_manager/,./src/webui,./tools/nni_annotation/testcase/,./examples/trials/mnist-nas/*/mnist*.py,./examples/trials/nas_cifar10/src/cifar10/general_child.py
      python3 -m flake8 . --count --exclude=$EXCLUDES --select=E9,F63,F72,F82 --show-source --statistics
    displayName: 'Run flake8 tests to find Python syntax errors and undefined names'
  - script: |
      cd test
      source scripts/unittest.sh
    displayName: 'Unit test'
  - script: |
      cd test
      python3 nni_test/nnitest/run_tests.py --config config/pr_tests.yml
    displayName: 'Simple test'


- job: 'macos_1015_python37'
  pool:
    vmImage: 'macOS-10.15'

  steps:
  - script: |
      echo "##vso[task.setvariable variable=PATH]/usr/local/Cellar/python@3.7/3.7.8_1/bin:${HOME}/Library/Python/3.7/bin:${PATH}"
      python3 -m pip install --upgrade pip setuptools
    displayName: 'Install python tools'
  - script: |
      echo "network-timeout 600000" >> ${HOME}/.yarnrc
      source install.sh
    displayName: 'Install nni toolkit via source code'
  - script: |
      set -e
      # pytorch Mac binary does not support CUDA, default is cpu version
      python3 -m pip install torchvision==0.6.0 torch==1.5.0 --user
      python3 -m pip install tensorflow==1.15.2 --user
      brew install swig@3
      rm -f /usr/local/bin/swig
      ln -s /usr/local/opt/swig\@3/bin/swig /usr/local/bin/swig
      nnictl package install --name=SMAC
    displayName: 'Install dependencies'
  - script: |
      cd test
      source scripts/unittest.sh
    displayName: 'Unit test'
  - script: |
      cd test
      python3 nni_test/nnitest/run_tests.py --config config/pr_tests.yml
    displayName: 'Simple test'

- job: 'win2016_python37'
  pool:
    vmImage: 'vs2017-win2016'

  steps:
  - script: |
      powershell.exe -file install.ps1
    displayName: 'Install nni toolkit via source code'
  - script: |
      python -m pip install scikit-learn==0.20.0 --user
      python -m pip install keras==2.1.6 --user
      python -m pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html --user
      python -m pip install tensorflow==1.15.2 --user
    displayName: 'Install dependencies'
  - script: |
      cd test
      powershell.exe -file scripts/unittest.ps1
    displayName: 'unit test'
  - script: |
      cd test
      python nni_test/nnitest/run_tests.py --config config/pr_tests.yml
    displayName: 'Simple test'
