diff --git a/eng/pipelines/templates/steps/npm-release-task.yml b/eng/pipelines/templates/steps/npm-release-task.yml index 5ccb53797719..233052fdd15d 100644 --- a/eng/pipelines/templates/steps/npm-release-task.yml +++ b/eng/pipelines/templates/steps/npm-release-task.yml @@ -14,12 +14,22 @@ steps: $tempDir = "$(System.DefaultWorkingDirectory)/temp_decompress" New-Item -ItemType Directory -Force -Path $tempDir tar -xzf $tarFile -C $tempDir - $packageJsonDir = "$tempDir\package\package.json" + $packageJsonDir = "$tempDir/package/package.json" $pkg = Get-Content -Raw "$packageJsonDir" | ConvertFrom-Json $packageName = $pkg.Name $packageVersion = $pkg.Version - $packageProps = npm view $packageName -json | ConvertFrom-Json - $originalTags = $packageProps.'dist-tags' | ConvertTo-Json -Compress + $packageProps = npm view $packageName -json -silent | ConvertFrom-Json + $originalTags = "{}" + if ($packageProps.error) { + $LASTEXITCODE = 0 + if ($packageProps.error.code -ne "E404") { + Write-Error $packageProps.error + exit 1 + } + } + else { + $originalTags = $packageProps.'dist-tags' | ConvertTo-Json -Compress + } echo "##vso[task.setvariable variable=PackageName]$packageName" echo "##vso[task.setvariable variable=OriginalTags]$originalTags" echo "##vso[task.setvariable variable=IntendedTagVersion]$packageVersion" diff --git a/eng/scripts/verify-npm-tags.ps1 b/eng/scripts/verify-npm-tags.ps1 index 69cd60fcca58..3a0906d9db20 100644 --- a/eng/scripts/verify-npm-tags.ps1 +++ b/eng/scripts/verify-npm-tags.ps1 @@ -28,20 +28,21 @@ Write-Host "Intend to add tag $intendedTag to version $intendedTagVersion" if ($packageDistTags."$intendedTag" -ne $intendedTagVersion) { Write-Warning "Tag not correctly set, current $intendedTag tag is version $($packageDistTags."$intendedTag") instead of $intendedTagVersion." $correctDistTags = $parsedOriginalDistTags - $correctDistTags."$intendedTag" = $intendedTagVersion + $correctDistTags | Add-Member -MemberType NoteProperty -Name $intendedTag -Value $intendedTagVersion -Force Write-Host "Setting AuthToken Deployment" $regAuth = "//registry.npmjs.org/" - $env:NPM_TOKEN=$npmToken + $env:NPM_TOKEN = $npmToken npm config set $regAuth`:_authToken=`$`{NPM_TOKEN`} - foreach($tag in $correctDistTags.PSObject.Properties) { + 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" -} else { +} +else { Write-Host "Tag verified." }