parameters:
  log_folder_name: ''
  language: ''
  deployment_type: ''

steps:
- bash:
    source ${HORTON_FRAMEWORKROOT}/bin/activate_horton &&
    ${HORTON_FRAMEWORKROOT}/scripts/fetch-logs.sh ${{ parameters.deployment_type }} $(Build.SourcesDirectory)/results ${{ parameters.log_folder_name }}
  displayName: 'Fetch logs'
  condition: and(always(), ne(variables['skipTest'],'yes'))

- task: PublishTestResults@2
  displayName: 'Publish Test Results **/TEST-*.xml'
  condition: and(always(), ne(variables['skipTest'],'yes'))
  inputs:
    testRunTitle: ${{ parameters.log_folder_name }}

- task: CopyFiles@2
  displayName: 'Copy result files to artifact staging'
  inputs:
    SourceFolder: '$(Build.SourcesDirectory)/results'
    TargetFolder: '$(Build.ArtifactStagingDirectory)'
  condition: and(always(), ne(variables['skipTest'],'yes'))

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact'
  inputs:
    pathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'Result for $(Build.DefinitionName) $(Build.BuildId)'
  condition: and(always(), ne(variables['skipTest'],'yes'))

- bash:
    ${HORTON_FRAMEWORKROOT}/bin/horton undeploy
  displayName: 'remove devices'
  env:
    IOTHUB_E2E_CONNECTION_STRING: $(IOTHUB-E2E-CONNECTION-STRING)
  condition: and(always(), ne(variables['skipTest'],'yes'))


