parameters:
  - name: CondaArtifacts
    type: object
    default: []
  - name: ArtifactPrefix
    type: string
    default: ''
  - name: Arguments
    type: string
    default: ''

steps:
  - task: UsePythonVersion@0
    displayName: 'Use Python $(PythonVersion)'
    inputs:
      versionSpec: $(PythonVersion)

  - pwsh: |
      $ErrorActionPreference = 'Stop'
      $PSNativeCommandUseErrorActionPreference = $true
      python -m pip install "tools/azure-sdk-tools[build,conda]"
      python -m pip install disutils
      python -m pip install typing-extensions==4.12.2
    displayName: Install build script requirements

  - pwsh: |
      $argContent = @'
      ${{ convertToJson(parameters.CondaArtifacts) }}
      '@
      $argFile = "$(Agent.TempDirectory)/conda-args.json"
      Set-Content -Path $argFile -Value $argContent
      cat $argFile
      sdk_build_conda -f "$argFile"
    displayName: Assemble Conda Packages

  - template: /eng/common/pipelines/templates/steps/publish-1es-artifact.yml
    parameters:
      ArtifactPath: '$(Build.SourcesDirectory)/conda/assembled'
      ArtifactName: '${{ parameters.ArtifactPrefix }}distributions'

  - ${{if eq(variables['System.TeamProject'], 'internal') }}:
    - task: AzureArtifacts.manifest-generator-task.manifest-generator-task.ManifestGeneratorTask@0
      displayName: 'Upload Conda SBOM'
      condition: succeededOrFailed()
      inputs:
        BuildDropPath: '$(Build.SourcesDirectory)/conda/output'

  - template: /eng/common/pipelines/templates/steps/publish-1es-artifact.yml
    parameters:
      ArtifactPath: '$(Build.SourcesDirectory)/conda/output'
      ArtifactName: '${{ parameters.ArtifactPrefix }}conda'

  - template: /eng/common/pipelines/templates/steps/publish-1es-artifact.yml
    parameters:
      ArtifactPath: '$(Build.SourcesDirectory)/conda/broken'
      ArtifactName: '${{ parameters.ArtifactPrefix }}broken'
