diff --git a/eng/pipelines/templates/stages/archetype-js-release.yml b/eng/pipelines/templates/stages/archetype-js-release.yml index a357ec660dda..aa9c27b22ba8 100644 --- a/eng/pipelines/templates/stages/archetype-js-release.yml +++ b/eng/pipelines/templates/stages/archetype-js-release.yml @@ -98,14 +98,9 @@ stages: npm install $(Package.Archive) displayName: Validating package can be installed condition: succeeded() - - task: PowerShell@2 - displayName: Publish to npmjs.org - inputs: - targetType: filePath - filePath: eng/tools/publish-to-npm.ps1 - arguments: -pathToArtifacts $(Package.Archive) -accessLevel "public" -tag "$(Tag)" -additionalTag "$(AdditionalTag)" -registry ${{parameters.Registry}} -npmToken $(azure-sdk-npm-token) - pwsh: true - condition: succeeded() + - template: /eng/pipelines/templates/steps/npm-release-task.yml + parameters: + Registry: ${{parameters.Registry}} - pwsh: > write-host "$(Package.Archive)" @@ -246,12 +241,10 @@ stages: echo "##vso[task.setvariable variable=NpmToken]$npmToken" echo "##vso[task.setvariable variable=Registry]$registry" displayName: Detecting package archive_${{artifact.name}} - - task: PowerShell@2 - displayName: Publish_${{artifact.name}} to dev feed - inputs: - targetType: filePath - filePath: eng/tools/publish-to-npm.ps1 - arguments: -pathToArtifacts $(Package.Archive) -accessLevel "public" -tag "dev" -registry "$(Registry)" -npmToken "$(NpmToken)" + - template: /eng/pipelines/templates/steps/npm-release-task.yml + parameters: + Registry: ${{parameters.Registry}} + - job: PublishDocsToNightlyBranch condition: or(eq(variables['SetDevVersion'], 'true'), and(eq(variables['Build.Reason'],'Schedule'), eq(variables['System.TeamProject'], 'internal'), ne(variables['Skip.PublishDocs'], 'true'))) dependsOn: PublishPackages diff --git a/eng/pipelines/templates/steps/npm-release-task.yml b/eng/pipelines/templates/steps/npm-release-task.yml new file mode 100644 index 000000000000..9445887f9cdc --- /dev/null +++ b/eng/pipelines/templates/steps/npm-release-task.yml @@ -0,0 +1,55 @@ +parameters: + Registry: '' + +steps: + - template: /eng/common/pipelines/templates/steps/set-default-branch.yml + - ${{if eq(parameters.Registry, 'https://registry.npmjs.org/')}}: + - task: PowerShell@2 + displayName: Get package list + inputs: + targetType: filePath + filePath: eng/tools/publish-to-npm.ps1 + arguments: -pathToArtifacts $(Package.Archive) -accessLevel "public" -tag "$(Tag)" -additionalTag "$(AdditionalTag)" -registry ${{parameters.Registry}} -npmToken $(azure-sdk-npm-token) + pwsh: true + condition: succeeded() + - ${{ each package in split(variables.NpmPublishList, ',') }}: + - task: EsrpRelease@6 + inputs: + displayName: 'Publish ${{package}} to ESRP' + ConnectedServiceName: 'ESRP Release Service' + Intent: 'PackageDistribution' + ContentType: 'npm' + FolderLocation: ${{package}} + Owners: $(Build.RequestedForEmail) + Approvers: 'wesh@microsoft.com' + ServiceEndpointUrl: 'https://api.esrp.microsoft.com' + MainPublisher: 'ESRPRELPACMANTEST' + DomainTenantId: '72f988bf-86f1-41af-91ab-2d7cd011db47' + ProductStateField: $(Tag) + + - pwsh: > + $regAuth=$registry.replace("https:","") + $filterPackageList= $filterArg -split "," | % { return $_.trim() } + $packageList = @() + foreach ($p in $(dir $pathToArtifacts -r -i *.tgz)) { + foreach($filterItem in $filterPackageList) { + if($p.BaseName.contains($filterItem)) { + $packageList += extractPackage $p + } + } + } + foreach ($p in $packageList) { + if($p.Publish) { + $(Build.SourcesDirectory)/eng/scripts/npm-admin-tasks.ps1 -taskType AddTag -packageName $p.Project.name -pkgVersion $p.Project.version -tagName "$(AdditionalTag)" -npmToken "$(azure-sdk-npm-token)" + } + } + + - ${{ else }}: + - task: PowerShell@2 + displayName: Publish to dev feed + inputs: + targetType: filePath + filePath: eng/tools/publish-to-npm.ps1 + arguments: -pathToArtifacts $(Package.Archive) -accessLevel "public" -tag "$(Tag)" -additionalTag "$(AdditionalTag)" -registry ${{parameters.Registry}} -npmToken $(azure-sdk-npm-token) + pwsh: true + condition: succeeded() diff --git a/eng/tools/publish-to-npm.ps1 b/eng/tools/publish-to-npm.ps1 index 21baddeb899a..f0e5bde69109 100644 --- a/eng/tools/publish-to-npm.ps1 +++ b/eng/tools/publish-to-npm.ps1 @@ -98,11 +98,10 @@ try { } } + $publishToNpm = $false if(!$basicDeployment) { if($registry -eq 'https://registry.npmjs.org/'){ - Write-Host "Choosing AuthToken Deployment" - $env:NPM_TOKEN=$npmToken - npm config set $regAuth`:_authToken=`$`{NPM_TOKEN`} + $publishToNpm = $true } else{ Write-Host "Choosing Private Devops Feed Deployment" @@ -123,16 +122,18 @@ try { npm config set $regAuth`:email=not_set } + $publishList = @() foreach ($p in $packageList) { - if($p.Publish) { + if($p.Publish -and !$publishToNpm) { + # Publishing to private feed if ($tag) { - Write-Host "npm publish $($p.TarGz) --access=$accessLevel --registry=$registry --always-auth=true --tag=$tag" - npm publish $p.TarGz --access=$accessLevel --registry=$registry --always-auth=true --tag=$tag + Write-Host "npm publish $($p.TarGz) --access=$accessLevel --registry=$registry --always-auth=true --tag=$tag" + npm publish $p.TarGz --access=$accessLevel --registry=$registry --always-auth=true --tag=$tag } else { - Write-Host "Tag is empty" - Write-Host "npm publish $($p.TarGz) --access=$accessLevel --registry=$registry --always-auth=true" - npm publish $p.TarGz --access=$accessLevel --registry=$registry --always-auth=true + Write-Host "Tag is empty" + Write-Host "npm publish $($p.TarGz) --access=$accessLevel --registry=$registry --always-auth=true" + npm publish $p.TarGz --access=$accessLevel --registry=$registry --always-auth=true } if ($LastExitCode -ne 0) { @@ -151,10 +152,16 @@ try { exit 1 } } + elseif ($p.Publish -and $publishToNpm) { + $publishList += $p.TarGz + } else{ Write-Host "Skipping package publish $($p.TarGz)" } } + if ($publishToNpm) { + Write-Host "##vso[task.setvariable variable=NpmPublishList;]$($publishList)" + } } finally {