Skip to content
Draft
11 changes: 3 additions & 8 deletions eng/emitters/pipelines/templates/stages/emitter-stages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,9 @@ stages:
- template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml

# publish to devops feed
- pwsh: |
$packageFiles = Get-ChildItem -Path . -Filter '*.tgz'
foreach ($file in $packageFiles.Name) {
Write-Host "npm publish $file --verbose --access public"
npm publish $file --verbose --access public
}
displayName: Publish to DevOps feed
workingDirectory: $(buildArtifactsPath)/packages
- template: /eng/emitters/pipelines/templates/steps/publish-to-devops-feed.yml
parameters:
PackagesPath: $(buildArtifactsPath)/packages

# If publishing publicly, also publish to npmjs.org
- ${{ if eq(parameters.Publish, 'public') }}:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
parameters:
# Directory containing the packed *.tgz npm packages to publish.
- name: PackagesPath
type: string

# Condition guarding the publish step.
- name: Condition
type: string
default: succeeded()

# Publishes all packed *.tgz npm packages found in PackagesPath to the internal
# Azure Artifacts (DevOps) feed. Callers are responsible for authenticating the
# active npm registry beforehand (for example via
# /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml).
steps:
- pwsh: |
$packageFiles = Get-ChildItem -Path . -Filter '*.tgz'
foreach ($file in $packageFiles.Name) {
Write-Host "npm publish $file --verbose --access public"
npm publish $file --verbose --access public
}
displayName: Publish to DevOps feed
workingDirectory: ${{ parameters.PackagesPath }}
condition: ${{ parameters.Condition }}
73 changes: 72 additions & 1 deletion packages/http-client-csharp/eng/pipeline/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ extends:
TMPDIR: $(Agent.TempDirectory)
NUGET_PACKAGES: $(Agent.TempDirectory)/nuget
npm_config_cache: $(Agent.TempDirectory)/npm-cache
# Shared on-disk state for the discrete Prepare / Publish generators / Regenerate steps.
AzureSdkForNetCheckout: $(Agent.TempDirectory)/azure-sdk-for-net
GeneratorPackagesFolder: $(Agent.TempDirectory)/generator-packages
steps:
- checkout: self

Expand Down Expand Up @@ -232,14 +235,82 @@ extends:
TokenOwners:
- Azure

# The azure-sdk-for-net PR is produced by discrete, independently-failing steps that
# share a single on-disk checkout ($(AzureSdkForNetCheckout)) and generator package folder
# ($(GeneratorPackagesFolder)):
# 1. Prepare - clone azure-sdk-for-net and regenerate the unbranded emitter artifacts.
# 2. Build generators - build and pack the Azure (and mgmt) generator from the published
# unbranded generator artifact, stamping the next available feed
# version and pinning the emitter artifacts to it. Only runs when a
# regen was requested, and fails the pipeline on any build error.
# 3. Publish generators - publish the packed generator packages to the ADO feed via the shared
# publish template (/eng/emitters/pipelines/templates/steps/publish-to-devops-feed.yml).
# 4. Regenerate & PR - regenerate the SDK libraries and open the azure-sdk-for-net PR.
- task: AzureCLI@2
displayName: Generate emitter-package.json files & create PR in azure-sdk-for-net
displayName: "Prepare azure-sdk-for-net checkout & regenerate unbranded emitter"
inputs:
azureSubscription: "AzureSDKEngKeyVault Secrets"
scriptType: pscore
scriptLocation: scriptPath
scriptPath: $(Build.SourcesDirectory)/packages/http-client-csharp/eng/scripts/Submit-AzureSdkForNetPr.ps1
arguments: >
-Phase 'Prepare'
-WorkingDirectory '$(AzureSdkForNetCheckout)'
-DebugFolder '$(GeneratorPackagesFolder)'
-PackageVersion '$(PackageVersion)'
-TypeSpecCommitUrl '$(TypeSpecCommitUrl)'
-AuthToken '$(GH_TOKEN)'
-TypeSpecSourcePackageJsonPath '$(Build.SourcesDirectory)/packages/http-client-csharp/package.json'
-PipelineRunUrl '$(PipelineRunUrl)'
${{ replace(replace('True', eq(variables['Build.SourceBranchName'], 'main'), ''), 'True', '-Internal') }}
${{ replace(replace('True', eq(parameters.RegenerateAzureLibraries, false), ''), 'True', '-RegenerateAzureLibraries') }}
${{ replace(replace('True', eq(parameters.RegenerateMgmtLibraries, false), ''), 'True', '-RegenerateMgmtLibraries') }}
-BuildArtifactsPath '$(Pipeline.Workspace)/build_artifacts_csharp/packages'
-UseTypeSpecNext:$${{ parameters.UseTypeSpecNext }}

- task: AzureCLI@2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot publishing should be done via the shared publish template job/stage /eng/emitters/pipelines/templates/stages/emitter-stages.yml

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Publishing no longer happens inside the ps1 scripts. I extracted the DevOps-feed publish steps out of emitter-stages.yml into a shared reusable template /eng/emitters/pipelines/templates/steps/publish-to-devops-feed.yml, refactored emitter-stages.yml to consume it (no behavior change), and publish.yml now uses that same shared template to publish the Azure/mgmt generator packages to the ADO feed.

The step that previously did "Build & publish generators" is now split: Submit-AzureSdkForNetPr.ps1 -Phase PublishGenerators only builds/packs the generators and stamps the next available feed version (pinning the emitter artifacts to it), and the publish is done by the shared template step immediately after. Publish-GeneratorPackage (the npm publish in RegenPreview.psm1) has been removed entirely.

displayName: "Build Azure/mgmt generators"
condition: and(succeeded(), or(${{ parameters.RegenerateAzureLibraries }}, ${{ parameters.RegenerateMgmtLibraries }}))
inputs:
azureSubscription: "AzureSDKEngKeyVault Secrets"
scriptType: pscore
scriptLocation: scriptPath
scriptPath: $(Build.SourcesDirectory)/packages/http-client-csharp/eng/scripts/Submit-AzureSdkForNetPr.ps1
arguments: >
-Phase 'BuildGenerators'
-WorkingDirectory '$(AzureSdkForNetCheckout)'
-DebugFolder '$(GeneratorPackagesFolder)'
-PackageVersion '$(PackageVersion)'
-TypeSpecCommitUrl '$(TypeSpecCommitUrl)'
-AuthToken '$(GH_TOKEN)'
-TypeSpecSourcePackageJsonPath '$(Build.SourcesDirectory)/packages/http-client-csharp/package.json'
-PipelineRunUrl '$(PipelineRunUrl)'
${{ replace(replace('True', eq(variables['Build.SourceBranchName'], 'main'), ''), 'True', '-Internal') }}
${{ replace(replace('True', eq(parameters.RegenerateAzureLibraries, false), ''), 'True', '-RegenerateAzureLibraries') }}
${{ replace(replace('True', eq(parameters.RegenerateMgmtLibraries, false), ''), 'True', '-RegenerateMgmtLibraries') }}
-BuildArtifactsPath '$(Pipeline.Workspace)/build_artifacts_csharp/packages'
-UseTypeSpecNext:$${{ parameters.UseTypeSpecNext }}

# Publish the packed Azure/mgmt generator packages to the ADO feed using the shared publish
# template. The active npm registry was already authenticated for the ADO feed by the
# create-authenticated-npmrc step above, so CI on the resulting azure-sdk-for-net PR can
# restore the emitter dependencies from the feed.
- template: /eng/emitters/pipelines/templates/steps/publish-to-devops-feed.yml
parameters:
PackagesPath: $(GeneratorPackagesFolder)
Condition: and(succeeded(), or(${{ parameters.RegenerateAzureLibraries }}, ${{ parameters.RegenerateMgmtLibraries }}))

- task: AzureCLI@2
displayName: "Regenerate SDK libraries & create PR in azure-sdk-for-net"
inputs:
azureSubscription: "AzureSDKEngKeyVault Secrets"
scriptType: pscore
scriptLocation: scriptPath
scriptPath: $(Build.SourcesDirectory)/packages/http-client-csharp/eng/scripts/Submit-AzureSdkForNetPr.ps1
arguments: >
-Phase 'Regenerate'
-WorkingDirectory '$(AzureSdkForNetCheckout)'
-DebugFolder '$(GeneratorPackagesFolder)'
-PackageVersion '$(PackageVersion)'
-TypeSpecCommitUrl '$(TypeSpecCommitUrl)'
-AuthToken '$(GH_TOKEN)'
Expand Down
Loading