# This pipeline
# 1. Scheduled to run UTC midnight everyday
# 2. Makes sure master branch is in healthy state (run live tests)

trigger: none

pr: none

schedules:
- cron: "0 0 * * *"
  displayName: Daily midnight build
  branches:
    include:
    - master
  always: true

jobs:

- job: 'Build_Publish_Azure_DevOps_CLI_Extension'
  pool:
    vmImage: 'ubuntu-latest'

  steps:
  - task: UsePythonVersion@0
    inputs:
      versionSpec: '3.x'
      architecture: 'x64'

  - template: templates/setup-ci-machine.yml

  - template: templates/build-publish-azure-devops-cli-extension.yml

- job: 'Build_Publish_Azure_CLI_Test_SDK'
  pool:
    vmImage: 'ubuntu-latest'

  steps:
  - task: UsePythonVersion@0
    inputs:
      versionSpec: '3.x'
      architecture: 'x64'

  - template: templates/setup-ci-machine.yml

  - template: templates/build-publish-azure-cli-test-sdk.yml

- job: 'Run_Test_Ubuntu'
  dependsOn : [ 'Build_Publish_Azure_CLI_Test_SDK', 'Build_Publish_Azure_DevOps_CLI_Extension']
  pool:
    vmImage: 'ubuntu-latest'
  
  steps:
  - task: UsePythonVersion@0
    inputs:
      versionSpec: '$(python.version)'

  - template: templates/install-azure-cli-edge.yml

  - template: templates/download-install-local-azure-test-sdk.yml

  - template: templates/setup-ci-machine.yml

  - template: templates/download-install-local-azure-devops-cli-extension.yml

  # Run a Python script.
  - task: PythonScript@0
    inputs:
      scriptSource: 'filePath'
      scriptPath: 'scripts/prepareLiveRecordingTestsRun.py'
      failOnStderr: true
    env:
      AZURE_DEVOPS_EXT_PAT: $(pat)

  - script: pytest tests --junitxml "TEST-results.xml"
    displayName: 'Run Live Tests'
    env:
      AZURE_DEVOPS_EXT_PAT: $(pat)

  - task: PublishTestResults@2
    displayName: 'Publish Test Results'
    inputs:
      testResultsFormat: 'JUnit'
      testResultsFiles: '**TEST-*.xml'
      searchFolder: '$(System.DefaultWorkingDirectory)'
    condition: succeededOrFailed()
