steps:
  - bash: "rm -rf $(Agent.WorkFolder)/_tools/node"
    displayName: "Clear Node cache"

  - bash: |
      rm -rf /tmp/metro-bundler-cache-*
      rm -rf /tmp/haste-map-react-native-packager-*
      rm -rf ~/.cache/yarn
    displayName: Clear RN, Yarn cache
    condition: and(succeeded(), or(eq(variables['Agent.OS'], 'Linux'), eq(variables['Agent.OS'], 'Darwin')))

  - task: NodeTool@0
    displayName: Use Node
    inputs:
      versionSpec: 10.x
      checkLatest: true

  - task: Npm@1
    displayName: "npm i gulp vsce -g"
    inputs:
      command: custom
      verbose: false
      customCommand: "i gulp vsce -g"

  - task: Npm@1
    displayName: "npm ci"
    inputs:
      command: custom
      verbose: false
      customCommand: ci

  - task: Gulp@0
    displayName: "gulp release"
    inputs:
      targets: release
      arguments: --nightly

  - task: CopyFiles@2
    displayName: "Copy Files to: test/smoke/package/resources/drop-win"
    inputs:
      Contents: "*.vsix"
      TargetFolder: "test/smoke/package/resources/drop-win"

  - bash: |
      /usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
      echo ">>> Started xvfb"
    displayName: Start xvfb
    condition: and(succeeded(), eq(variables['Agent.OS'], 'Linux'))

  - bash: |
      npm install -g yarn react-native-cli
      npm install -g appium@$(appiumVersion)
      npm install -g expo-cli@$(expoCLIVersion)
    displayName: "npm install -g yarn react-native-cli expo-cli appium"

  - bash: npm install --global windows-build-tools --vs2015
    displayName: "npm install --global windows-build-tools --vs2015"
    condition: and(succeeded(), eq(variables['Agent.OS'], 'Windows_NT'))

  - bash: |
      export MOCHA_FILE=./ReactNativeSmokeTests.xml
      export BASIC_ONLY=""
      export NIGHTLY=""
      if [ $(nightlyBuild) = true ]; then
        NIGHTLY="true"
      fi
      if [ $(basicOnly) = true ]; then
        BASIC_ONLY="--basic-only"
      fi
      yarn smoke-tests $BASIC_ONLY
    displayName: "Run smoke tests"
    env:
      DISPLAY: ":99.0"

  - task: PublishTestResults@2
    displayName: "Publish Test Results"
    inputs:
      testResultsFiles: "./$(smokeTestDirectory)/vscode/test/smoke/ReactNativeSmokeTests.xml"
      failTaskOnFailedTests: true
      testRunTitle: $(Agent.OS) React Native extension smoke tests - Attempt №$(System.JobAttempt)
    condition: always()

  - task: ArchiveFiles@2
    displayName: "Archive SmokeTestLogs"
    inputs:
      rootFolderOrFile: SmokeTestLogs
      archiveFile: "$(Build.ArtifactStagingDirectory)/SmokeTestLogs_$(Agent.JobName)"
    condition: always()

  - task: PublishBuildArtifacts@1
    displayName: "Publish Artifact: SmokeTestLogs"
    inputs:
      ArtifactName: SmokeTestLogs
    condition: always()
