parameters:
  StageLabel: ''
  JobLabel: ''
  CustomSensitiveDataList: ''
  # A default - in case value from eng/common/templates/post-build/common-variables.yml is not passed
  BinlogToolVersion: '1.0.11'

steps:
- task: Powershell@2
  displayName: Prepare Binlogs to Upload
  inputs:
    targetType: inline
    script: |
      New-Item -ItemType Directory $(Build.SourcesDirectory)/PostBuildLogs/${{parameters.StageLabel}}/${{parameters.JobLabel}}/
      Move-Item -Path $(Build.SourcesDirectory)/artifacts/log/Debug/* $(Build.SourcesDirectory)/PostBuildLogs/${{parameters.StageLabel}}/${{parameters.JobLabel}}/
  continueOnError: true
  condition: always()
    
- task: PowerShell@2
  displayName: Redact Logs
  inputs:
    filePath: $(Build.SourcesDirectory)/eng/common/post-build/redact-logs.ps1
    # For now this needs to have explicit list of all sensitive data. Taken from eng/publishing/v3/publish.yml
    # Sensitive data can as well be added to $(Build.SourcesDirectory)/eng/BinlogSecretsRedactionFile.txt'
    #  If the file exists - sensitive data for redaction will be sourced from it
    #  (single entry per line, lines starting with '# ' are considered comments and skipped)
    arguments: -InputPath '$(Build.SourcesDirectory)/PostBuildLogs' 
      -BinlogToolVersion ${{parameters.BinlogToolVersion}}
      -TokensFilePath '$(Build.SourcesDirectory)/eng/BinlogSecretsRedactionFile.txt'
      '$(publishing-dnceng-devdiv-code-r-build-re)'
      '$(MaestroAccessToken)'
      '$(dn-bot-all-orgs-artifact-feeds-rw)'
      '$(akams-client-id)'
      '$(akams-client-secret)'
      '$(microsoft-symbol-server-pat)'
      '$(symweb-symbol-server-pat)'
      '$(dn-bot-all-orgs-build-rw-code-rw)'
      ${{parameters.CustomSensitiveDataList}}
  continueOnError: true
  condition: always()
      
- task: PublishBuildArtifacts@1
  displayName: Publish Logs
  inputs:
    PathtoPublish: '$(Build.SourcesDirectory)/PostBuildLogs'
    PublishLocation: Container
    ArtifactName: PostBuildLogs
  continueOnError: true
  condition: always()
