Skip to content

Commit

Permalink
Merge ab8e657 into e4886c7
Browse files Browse the repository at this point in the history
  • Loading branch information
ckairen authored Nov 5, 2024
2 parents e4886c7 + ab8e657 commit 4b43b2e
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 5 deletions.
2 changes: 0 additions & 2 deletions eng/pipelines/templates/stages/archetype-js-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ stages:
condition: succeeded()
- template: /eng/pipelines/templates/steps/npm-release-task.yml
parameters:
ArtifactName: ${{parameters.ArtifactName}}
Artifact: ${{artifact}}
Registry: ${{parameters.Registry}}
PathToArtifacts: $(Pipeline.Workspace)/${{parameters.ArtifactName}}/${{artifact.name}}
Expand Down Expand Up @@ -258,7 +257,6 @@ stages:
displayName: Detecting package archive_${{artifact.name}}
- template: /eng/pipelines/templates/steps/npm-release-task.yml
parameters:
ArtifactName: ${{parameters.ArtifactName}}
Artifact: ${{artifact}}
Registry: ${{parameters.Registry}}
PathToArtifacts: $(Pipeline.Workspace)/${{parameters.ArtifactName}}/${{artifact.name}}
Expand Down
2 changes: 1 addition & 1 deletion eng/pipelines/templates/stages/archetype-sdk-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ extends:
Artifacts: ${{ parameters.Artifacts }}
${{ if eq(parameters.ServiceDirectory, 'template') }}:
TestPipeline: true
RunUnitTests: ${{ parameters.RunUnitTests }}
RunUnitTests: false
MatrixConfigs:
- ${{ each config in parameters.MatrixConfigs }}:
- ${{ config }}
Expand Down
1 change: 0 additions & 1 deletion eng/pipelines/templates/stages/partner-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ extends:

- template: /eng/pipelines/templates/steps/npm-release-task.yml
parameters:
ArtifactName: Partner Drop
Artifact:
name: Partner Drop
path: $(Artifacts)
Expand Down
25 changes: 24 additions & 1 deletion eng/pipelines/templates/steps/npm-release-task.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
parameters:
ArtifactName: ''
Artifact: {}
Registry: ''
PathToArtifacts: ''
Expand All @@ -10,6 +9,22 @@ steps:
- template: /eng/common/pipelines/templates/steps/set-default-branch.yml

- ${{ if eq(parameters.Registry, 'https://registry.npmjs.org/') }}:
- pwsh: |
Set-PSDebug -Trace 1
$tarFile = (Get-ChildItem -Path "${{parameters.PathToArtifacts}}/*.tgz").FullName
$tempDir = "$(System.DefaultWorkingDirectory)/temp_decompress"
New-Item -ItemType Directory -Force -Path $tempDir
tar -xzf $tarFile -C $tempDir
$pkg = Get-Content -Raw "$tempDir\package\package.json" | ConvertFrom-Json
$packageName = $pkg.Name
$packageVersion = $pkg.Version
$packageProps = npm view $packageName -json | ConvertFrom-Json
$originalTags = $packageProps.'dist-tags' | ConvertTo-Json -Compress
echo "##vso[task.setvariable variable=OriginalTags]$originalTags
echo "##vso[task.setvariable variable=IntendedTagVersion]$packageVersion
Remove-Item -Force -Recurse $tempDir
displayName: Get original tags
- task: EsrpRelease@7
inputs:
displayName: 'Publish ${{parameters.Artifact.name}} to ESRP'
Expand All @@ -28,6 +43,14 @@ steps:
DomainTenantId: '72f988bf-86f1-41af-91ab-2d7cd011db47'
productstate: ${{parameters.Tag}}

- task: Powershell@2
displayName: Verify package tags
inputs:
targetType: filePath
filePath: eng/scripts/verify-npm-tags.ps1
arguments: -pathToArtifacts ${{parameters.PathToArtifacts}} -originalDistTags $(OriginalTags) -intendedTag ${{parameters.Tag}} -intendedTagVersion $(IntendedTagVersion)
pwsh: true

- ${{ if ne(parameters.AdditionalTag, '') }}:
- task: PowerShell@2
displayName: Add Additional Tag
Expand Down
49 changes: 49 additions & 0 deletions eng/scripts/verify-npm-tags.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
param (
[Parameter(mandatory = $true)]
$pathToArtifacts,
[Parameter(mandatory = $true)]
$originalDistTags,
[Parameter(mandatory = $true)]
$intendedTag,
[Parameter(mandatory = $true)]
$intendedTagVersion
)

# TODO: delete testing comments below
#'@azure/eventhubs-checkpointstore-table' alpha, no beta, no GA
#'@azure/openai' alpha, beta, no GA
#'@azure/video-indexer-widgets' no alpha, no beta, GA
#'@azure/template' alpha, beta, GA
#$pkgProps.PackageId

$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true

$tarFile = (Get-ChildItem -Path "$pathToArtifacts/*.tgz")?.Name
$tempDir = "temp_decompress"
New-Item -ItemType Directory -Force -Path $tempDir
tar -xzf $tarFile -C $tempDir
$pkg = Get-Content -Raw "$tempDir\package\package.json" | ConvertFrom-Json
$packageName = $pkg.Name
Remove-Item -Force -Recurse $tempDir

Write-Host "Verify npm tag versions for package $packageName"

$parsedOriginalDistTags = $originalDistTags | ConvertFrom-Json

$npmPkgProp = npm view $packageName --json | ConvertFrom-Json
$packageDistTags = $npmPkgProp."dist-tags"
Write-Host "Current dist-tag: $packageDistTags"

if ($packageDistTags."$intendedTag" -ne $intendedTagVersion) {
Write-Host "Tag not correctly set, current $intendedTag tag is version $packageDistTags.'$intendedTag' instead of $intendedTagVersion."
$correctDistTags = $parsedOriginalDistTags
$correctDistTags."$intendedTag" = $intendedTagVersion
foreach($tag in $correctDistTags.PSObject.Properties) {
Write-Host "npm dist-tag add $packageName@$tag.value $tag.Name"
npm dist-tag add $packageName@$tag.value $tag.Name
}
$npmPkgProp = npm view $packageName --json | ConvertFrom-Json
$packageDistTags = $npmPkgProp."dist-tags"
Write-Host "Corrected dist tags to: $packageDistTags"
}

0 comments on commit 4b43b2e

Please sign in to comment.