parameters:
  - name: parentJobs
    type: jobList

jobs:
- job: generateNotice
  variables:
  - name: runCodesignValidationInjection
    value : false
  - name: NugetSecurityAnalysisWarningLevel
    value: none

  displayName: Generate Notice
  dependsOn:
    ${{ parameters.parentJobs }}
  pool:
    name: PowerShell1ES
    demands:
    - ImageOverride -equals MMS2019

  # APIScan can take a long time
  timeoutInMinutes: 15

  steps:
  - checkout: self
    clean: true

  - pwsh: |
      Get-Content ./assets/additionalAttributions.txt | Out-File '$(System.ArtifactsDirectory)\additionalAttributions.txt' -Encoding utf8NoBOM -Force
      Get-Content -Raw -Path  '$(System.ArtifactsDirectory)\additionalAttributions.txt'
    displayName: Get Additional Attributions

  - pwsh: |
      Import-Module ./tools/ComponentGovernance
      $pat = ConvertTo-SecureString -String "$(CgPat)" -AsPlainText -Force
      Set-CgCredentials -Pat $pat -Organization $(CgOrganization) -Project $(CgProject)
      $repo = Get-CgPsRepository
      $typeId = (Get-CgSnapshotType -CgRepository $repo | where-object {$_.isTracked -eq 'True' -and $_.buildDisplayType -eq 'Coordinated Packages'}).typeId
      $notice = Get-CgNotice -CgRepository $repo -SnapshotTypeId $typeId
      $notice | Out-File '$(System.ArtifactsDirectory)\ThirdPartyNotices.txt' -Encoding utf8NoBOM -Force
      Get-Content '$(System.ArtifactsDirectory)\additionalAttributions.txt' | Out-File '$(System.ArtifactsDirectory)\ThirdPartyNotices.txt' -Encoding utf8NoBOM -Force -Append
    displayName: Get Notice

  - task: AzureFileCopy@4
    displayName: 'upload Notice'
    inputs:
      SourcePath: $(System.ArtifactsDirectory)\ThirdPartyNotices.txt
      azureSubscription: '$(AzureFileCopySubscription)'
      Destination: AzureBlob
      storage: '$(StorageAccount)'
      ContainerName: 'tpn'
      resourceGroup: '$(StorageResourceGroup)'

  - task: PublishPipelineArtifact@1
    inputs:
      targetPath: $(System.ArtifactsDirectory)
      artifactName: notice
    displayName: Publish notice artifacts

  - task: ms.vss-governance-buildtask.governance-build-task-component-detection.ComponentGovernanceComponentDetection@0
    displayName: 'Component Detection'
    inputs:
      sourceScanPath: '$(Build.SourcesDirectory)'
      snapshotForceEnabled: true
