jobs:
  - job: "integration_test_remote_linux_to_windows"
    timeoutInMinutes: 120
    steps:
      - script: make clean
        displayName: "clean nni source code"
      - task: CopyFilesOverSSH@0
        inputs:
          sshEndpoint: $(end_point)
          contents: |
            **
            !**/dist/**
            !**/node_modules/**
          targetFolder: /tmp/nnitest/$(Build.BuildId)
          overwrite: true
        displayName: "Copy all files to remote machine"
        timeoutInMinutes: 10
      - task: SSH@0
        inputs:
          sshEndpoint: $(end_point)
          runOptions: commands
          commands: cd "\tmp\nnitest\$(Build.BuildId)" && powershell.exe -command "conda activate l2w | .\uninstall.ps1 | .\install.ps1"
          failOnStdErr: false
        displayName: "install on remote windows"
      - script: python3 -m pip install --upgrade pip setuptools --user
        displayName: "Install python tools"
      - script: make easy-install
        displayName: "Install nni via source code"
      - script: |
          sudo apt-get install swig -y
          PATH=$HOME/.local/bin:$PATH nnictl package install --name=SMAC
          PATH=$HOME/.local/bin:$PATH nnictl package install --name=BOHB
        displayName: "Install dependencies for integration tests in remote mode"
      - script: |
          set -e
          cd test
          python3 nni_test/nnitest/generate_ts_config.py --ts remote --remote_user $(remote_user) --remote_host $(remote_host) \
          --remote_port $(remote_port) --remote_pwd $(remote_pwd) --nni_manager_ip $(nni_manager_ip)
          cat config/training_service.yml
          PATH=$HOME/.local/bin:$PATH python3 nni_test/nnitest/run_tests.py --config config/integration_tests.yml --ts remote
        displayName: "integration test"
      - task: SSH@0
        inputs:
          sshEndpoint: $(end_point)
          runOptions: commands
          commands: rmdir /s /q "\\?\c:\tmp\nnitest\$(Build.BuildId)"
        condition: always()
        displayName: "clean up on remote server"
