parameters:
  configuration: 'Release'
  platform: ''
  additionalBuildArguments: ''
  minimumExpectedTestsExecutedCount: 1  # Sanity check for minimum expected tests to be reported
  rerunPassesRequiredToAvoidFailure: 0

jobs:
- job: Build${{ parameters.platform }}${{ parameters.configuration }}
  displayName: Build ${{ parameters.platform }} ${{ parameters.configuration }}
  variables:
    BuildConfiguration: ${{ parameters.configuration }}
    BuildPlatform: ${{ parameters.platform }}
    PGOBuildMode: 'Instrument'
  pool: "windevbuildagents"
  # The public pool is also an option!
  # pool: { vmImage: windows-2019 }

  steps:
  - template: build-console-steps.yml
    parameters:
      additionalBuildArguments: ${{ parameters.additionalBuildArguments }}

- template: helix-runtests-job.yml
  parameters:
    name: 'RunTestsInHelix'
    dependsOn: Build${{ parameters.platform }}${{ parameters.configuration }}
    condition: succeeded()
    testSuite: 'PgoInstrumentationSuite'
    taefQuery: '@IsPgo=true'
    configuration: ${{ parameters.configuration }}
    platform: ${{ parameters.platform }}
    rerunPassesRequiredToAvoidFailure: ${{ parameters.rerunPassesRequiredToAvoidFailure }}
    
- template: helix-processtestresults-job.yml
  parameters:
    name: 'ProcessTestResults'
    pgoArtifact: 'PGO'
    dependsOn:
    - RunTestsInHelix
    condition: succeededOrFailed()
    rerunPassesRequiredToAvoidFailure: ${{ parameters.rerunPassesRequiredToAvoidFailure }}
    minimumExpectedTestsExecutedCount: ${{ parameters.minimumExpectedTestsExecutedCount }}

- template: pgo-merge-pgd-job.yml
  parameters:
    name: 'MergePGD'
    dependsOn:
    - ProcessTestResults
    pgoArtifact: 'PGO'
    platform: ${{ parameters.platform }}
