# BuildDropPath - The root folder of the drop directory for which the manifest file will be generated.
# PackageName - The name of the package this SBOM represents.
# PackageVersion - The version of the package this SBOM represents. 
# ManifestDirPath - The path of the directory where the generated manifest files will be placed
# IgnoreDirectories - Directories to ignore for SBOM generation. This will be passed through to the CG component detector.

parameters:
  PackageVersion: 7.0.0
  BuildDropPath: '$(Build.SourcesDirectory)/artifacts'
  PackageName: '.NET'
  ManifestDirPath: $(Build.ArtifactStagingDirectory)/sbom
  IgnoreDirectories: ''
  sbomContinueOnError: true

steps:
- task: PowerShell@2 
  displayName: Prep for SBOM generation in (Non-linux)
  condition: or(eq(variables['Agent.Os'], 'Windows_NT'), eq(variables['Agent.Os'], 'Darwin'))
  inputs: 
    filePath: ./eng/common/generate-sbom-prep.ps1
    arguments: ${{parameters.manifestDirPath}}

# Chmodding is a workaround for https://github.com/dotnet/arcade/issues/8461
- script: |
    chmod +x ./eng/common/generate-sbom-prep.sh
    ./eng/common/generate-sbom-prep.sh ${{parameters.manifestDirPath}}
  displayName: Prep for SBOM generation in (Linux)
  condition: eq(variables['Agent.Os'], 'Linux')
  continueOnError: ${{ parameters.sbomContinueOnError }}

- task: AzureArtifacts.manifest-generator-task.manifest-generator-task.ManifestGeneratorTask@0
  displayName: 'Generate SBOM manifest'
  continueOnError: ${{ parameters.sbomContinueOnError }}
  inputs:
      PackageName: ${{ parameters.packageName }}
      BuildDropPath: ${{ parameters.buildDropPath }}
      PackageVersion: ${{ parameters.packageVersion }}
      ManifestDirPath: ${{ parameters.manifestDirPath }}
      ${{ if ne(parameters.IgnoreDirectories, '') }}:
        AdditionalComponentDetectorArgs: '--IgnoreDirectories ${{ parameters.IgnoreDirectories }}'

- task: 1ES.PublishPipelineArtifact@1
  displayName: Publish SBOM manifest
  continueOnError: ${{parameters.sbomContinueOnError}}
  inputs:
    targetPath: '${{parameters.manifestDirPath}}'
    artifactName: $(ARTIFACT_NAME)

