| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 
 | parameters:
  - name: BeforePublishSteps
    type: object
    default: []
  - name: TestPipeline
    type: boolean
    default: false
  - name: ServiceDirectory
    type: string
    default: ''
  - name: Artifacts
    type: object
    default: []
  - name: DevFeedName
    type: string
    default: 'public/azure-sdk-for-python'
  - name: BuildDocs
    type: boolean
    default: true
  - name: RunApiStubGen
    type: boolean
    default: true
# Please use `$(TargetingString)` to refer to the python packages glob string. This variable is set from resolve-package-targeting.yml.
steps:
  - task: UsePythonVersion@0
    displayName: 'Use Python 3.13'
    inputs:
      versionSpec: '3.13'
  - template: /eng/pipelines/templates/steps/use-venv.yml
  - pwsh: |
      if ("${{ parameters.ServiceDirectory }}" -ne "auto")
      {
        Write-Host "##vso[task.setvariable variable=ComponentDetection.SourcePath]$(Build.SourcesDirectory)/sdk/${{ parameters.ServiceDirectory }}"
      }
    displayName: Set Component Governance Path
  - ${{if eq(variables['System.TeamProject'], 'internal') }}:
    - template: auth-dev-feed.yml
      parameters:
        DevFeedName: ${{ parameters.DevFeedName }}
  - template: /eng/common/pipelines/templates/steps/set-test-pipeline-version.yml
    parameters:
      PackageName: "azure-template"
      ServiceDirectory: "template"
      TestPipeline: ${{ parameters.TestPipeline }}
  - template: /eng/common/pipelines/templates/steps/set-default-branch.yml
  - script: |
      echo "##vso[build.addbuildtag]Scheduled"
    displayName: 'Tag scheduled builds'
    condition: and(eq(variables['Build.SourceBranchName'], variables['DefaultBranch']), eq(variables['Build.Reason'],'Schedule'))
  - script: |
      which python
      $(PIP_EXE) install -r eng/ci_tools.txt
    displayName: 'Prep Environment'
  - template: set-dev-build.yml
  - ${{ if eq(parameters.BuildDocs, 'true') }}:
    - task: PythonScript@0
      displayName: 'Generate Docs'
      condition: and(succeededOrFailed(), ${{parameters.BuildDocs}})
      inputs:
        scriptPath: 'scripts/devops_tasks/dispatch_tox.py'
        arguments: >-
          "$(TargetingString)"
          --service="${{ parameters.ServiceDirectory }}"
          --toxenv=sphinx
          --wheel_dir="$(Build.ArtifactStagingDirectory)"
  - ${{ if eq(parameters.RunApiStubGen, 'true') }}:
    - template: /eng/pipelines/templates/steps/run_apistub.yml
      parameters:
        ServiceDirectory: ${{ parameters.ServiceDirectory }}
        AdditionalTestArgs: '--wheel_dir="$(Build.ArtifactStagingDirectory)"'
  - ${{ parameters.BeforePublishSteps }}
  - ${{ if eq(parameters.RunApiStubGen, 'true') }}:
    - task: Powershell@2
      inputs:
        filePath: $(Build.SourcesDirectory)/eng/scripts/Save-Package-Namespaces-Property.ps1
        arguments: >
          -ArtifactStagingDirectory "$(Build.ArtifactStagingDirectory)"
        pwsh: true
        workingDirectory: $(Pipeline.Workspace)
      displayName: Update package properties with namespaces
    # Component governance collates discovered dependencies from a combination of
    # manifest files, splatted json output from CG detections, setup.py files, and other sources.
    # At this point in the job, we have downloadeded package artifacts from 3 previous platform-specific build jobs,
    # so the directory that will be published as packages_extended _already contains_ a collated set of dependencies by
    # json file. When we attempt to publish the packages_extended artifact, CG re-collates data from the current job, but ALSO
    # includes all the data from json files left behind by the previous jobs. While this doesn't result in double counting,
    # we've been running into some nasty timeout issues of the CG running on this job specifically.
    #
    # Given that we've ALREADY RUN CG on the previous jobs, we can clean up these artifacts to avoid
    # incurring an increased CG runtime. What's present within IS accurate.
  - pwsh: |
      Get-ChildItem -Path "$(Build.ArtifactStagingDirectory)" -Filter GovCompDisc* | % { Write-Host "Removing $($_.FullName)"; Remove-Item $_ }
      Get-ChildItem -Path "$(Build.ArtifactStagingDirectory)" -Filter ScanTelemetry* | % { Write-Host "Removing $($_.FullName)"; Remove-Item $_ }
      if (Test-Path -Path "$(Build.ArtifactStagingDirectory)/bcde-output") {
        Remove-Item -Recurse -Force -Path "$(Build.ArtifactStagingDirectory)/bcde-output"
      }
      if (Test-Path -Path "$(Build.ArtifactStagingDirectory)/_manifest") {
        Remove-Item -Recurse -Force -Path "$(Build.ArtifactStagingDirectory)/_manifest"
      }
    displayName: Clean up Artifact Directory
  - ${{ if ne(parameters.BuildDocs, 'true') }}:
    - template: /eng/common/pipelines/templates/steps/publish-1es-artifact.yml
      parameters:
        ArtifactPath: '$(Build.ArtifactStagingDirectory)'
        ArtifactName: 'packages_extended'
  - ${{ if eq(parameters.BuildDocs, 'true') }}:
    - pwsh: |
        $directoryExists = Test-Path -Path "$(Build.SourcesDirectory)/_docs"
        Write-Output "##vso[task.setvariable variable=DirectoryExists]$directoryExists"
      displayName: Check if docs directory exists
    - template: /eng/common/pipelines/templates/steps/publish-1es-artifact.yml
      parameters:
        ArtifactPath: '$(Build.SourcesDirectory)/_docs'
        CustomCondition: eq(variables['DirectoryExists'], 'True')
        ArtifactName: 'documentation'
 |