Skip to content

Commit

Permalink
[bug fix] esrp safety net for initial packages (#31878)
Browse files Browse the repository at this point in the history
closes #31879
  • Loading branch information
ckairen authored Nov 26, 2024
1 parent f0093c3 commit 9b00b0c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
16 changes: 13 additions & 3 deletions eng/pipelines/templates/steps/npm-release-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 5 additions & 4 deletions eng/scripts/verify-npm-tags.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}

0 comments on commit 9b00b0c

Please sign in to comment.