From 2de4f3c6d1cc4cace9880ac3ee5fabac80b518d5 Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Mon, 24 May 2021 17:18:56 -0400 Subject: [PATCH 01/14] Add Tag and addtional tag automatically --- .../templates/stages/archetype-js-release.yml | 6 + eng/tools/get-npm-tags.ps1 | 114 ++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 eng/tools/get-npm-tags.ps1 diff --git a/eng/pipelines/templates/stages/archetype-js-release.yml b/eng/pipelines/templates/stages/archetype-js-release.yml index 151a23619015..190deb7c65d5 100644 --- a/eng/pipelines/templates/stages/archetype-js-release.yml +++ b/eng/pipelines/templates/stages/archetype-js-release.yml @@ -81,6 +81,12 @@ stages: echo "##vso[task.setvariable variable=Package.Archive]$DETECTED_PACKAGE_NAME" displayName: Detecting package archive + - pwsh: | + $result = .\get-npm-tags.ps1 -packageArtifact $pkgArtifact -workingDirectory $(System.DefaultWorkingDirectory) + echo "##vso[task.setvariable variable=Tag]$result.Tag" + echo "##vso[task.setvariable variable=AdditionalTag]$result.AdditionalTag" + displayName: 'Set Tag and Additional Tag' + - task: PowerShell@2 displayName: 'Publish to npmjs.org' inputs: diff --git a/eng/tools/get-npm-tags.ps1 b/eng/tools/get-npm-tags.ps1 new file mode 100644 index 000000000000..979e99c73db7 --- /dev/null +++ b/eng/tools/get-npm-tags.ps1 @@ -0,0 +1,114 @@ +param ( + [Parameter(mandatory = $true)] + $packageArtifact, + [Parameter(mandatory = $true)] + $workingDirectory +) + +$EngPath = Resolve-Path "${PSScriptRoot}/.." +$Engcommon = Join-Path $EngPath "common" +$EngCommonScriptsPath = Join-Path $Engcommon "scripts" +. (Join-Path $EngCommonScriptsPath common.ps1) + +Write-Host "Find latest and next versions in npm registry for package" +<# +1. Get latest GA and latest preview from npm +2. Check new version to be published to find is it GA or preview +3. If new Version is GA: + a. If higher than current latest, or first GA then set LATEST tag +4. If new version is preview and higher than current higher version in npm: + a. Set LATEST if package has never GA released + b. Set NEXT tag +#> +$packageName = $null +$packageVersion = $null +if ($GetPackageInfoFromPackageFileFn -and (Test-Path "Function:$GetPackageInfoFromPackageFileFn")) +{ + $pkgProps = &$GetPackageInfoFromPackageFileFn -pkg $packageArtifact -workingDirectory $workingDirectory + $packageName = $pkgProps.PackageId + $packageVersion = $pkgProps.PackageVersion +} +else +{ + Write-Error "The function for '$GetPackageInfoFromPackageFileFn' was not found.` + Make sure it is present in eng/scripts/Language-Settings.ps1 and referenced in eng/common/scripts/common.ps1.` + See https://github.com/Azure/azure-sdk-tools/blob/master/doc/common/common_engsys.md#code-structure" +} + + +$latestGAVersion = npm show $packageName@latest version +$latestPreviewVersion = npm show $packageName@next version +Write-Host "Latest GA version: $latestGAVersion" +Write-Host "Latest preview version: $latestPreviewVersion" +if ( $latestPreviewVersion -eq $null) +{ + Write-Host "'Next' tag is not present in npm registry for package $packageName" +} +else +{ + $latestPreviewVersion = [AzureEngSemanticVersion]::ParseVersionString($latestPreviewVersion) +} + +if ( $latestGAVersion -eq $null) +{ + Write-Host "GA version is not present in npm registry for package $packageName" +} +else +{ + $latestGAVersion = [AzureEngSemanticVersion]::ParseVersionString($latestGAVersion) +} + +$newVersion = [AzureEngSemanticVersion]::ParseVersionString($packageVersion) + +$setLatest = $false +$setNext = $false + +# Set Latest tag if new version is higher than current GA or if package has never GA released before +if ((-not $newVersion.IsPreRelease) -and ($latestGAVersion -eq $null -or $newVersion.CompareTo($latestGAVersion) -eq 1)) +{ + $setLatest = $true +} + +if ($newVersion.PrereleaseLabel -eq "preview") +{ + # Set next tag if new preview is higher than both GA and current preview + $highestNpmVersion = $latestPreviewVersion + if (($highestNpmVersion -eq $null) -or ($latestGAVersion -ne $null -and $latestGAVersion.CompareTo($highestNpmVersion) -eq 1)) { + $highestNpmVersion = $latestGAVersion + } + + # New version is preview and if package is getting released first time or higher than currently available + if ($highestNpmVersion -eq $null -or $newVersion.CompareTo($highestNpmVersion) -eq 1) + { + $setNext = $true + # Set latest tag if package was never GA released + if ($latestGAVersion -eq $null) { + $setLatest = $true + } + } +} + +$tag = "" +$additionalTag = "" +if ($setLatest) +{ + Write-Host "Setting Tag to latest" + $tag = "latest" + if ($result.setNext) + { + Write-Host "Setting AdditionalTag to next" + $additionalTag = "next" + } +} +elseif ($result.setNext) +{ + Write-Host "Setting Tag to next" + $tag = "next" +} + +$result = New-Object PSObject -Property @{ + Tag = $tag + AdditionalTag = $additionalTag +} +write-Host $result +return $result From e3730d64a1b719c4de83bcd931c65f3337f099fc Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Tue, 25 May 2021 14:33:49 -0400 Subject: [PATCH 02/14] Added script to remove npm tag after package is published --- eng/tools/get-npm-tags.ps1 | 119 ++++++++++++------------------ eng/tools/npm-helpers.ps1 | 76 +++++++++++++++++++ eng/tools/remove-npm-next-tag.ps1 | 55 ++++++++++++++ 3 files changed, 177 insertions(+), 73 deletions(-) create mode 100644 eng/tools/npm-helpers.ps1 create mode 100644 eng/tools/remove-npm-next-tag.ps1 diff --git a/eng/tools/get-npm-tags.ps1 b/eng/tools/get-npm-tags.ps1 index 979e99c73db7..65bd4104b69c 100644 --- a/eng/tools/get-npm-tags.ps1 +++ b/eng/tools/get-npm-tags.ps1 @@ -5,12 +5,20 @@ param ( $workingDirectory ) -$EngPath = Resolve-Path "${PSScriptRoot}/.." -$Engcommon = Join-Path $EngPath "common" -$EngCommonScriptsPath = Join-Path $Engcommon "scripts" -. (Join-Path $EngCommonScriptsPath common.ps1) - +. (Join-Path $PSScriptRoot npm-helpers.ps1) +$pkgProps = Get-PackageProperties -packageArtifact $packageArtifact -workingDirectory $workingDirectory +if ($pkgProps -eq $null) +{ + Write-Error "Failed to parse package artifact $packageArtifact to get package name" + exit 1 +} +$packageName = $pkgProps.PackageId +$packageVersion = $pkgProps.PackageVersion +$newVersion = [AzureEngSemanticVersion]::ParseVersionString($packageVersion) +Write-Host "Package name: $packageName" +Write-Host "Package version: $packageVersion" Write-Host "Find latest and next versions in npm registry for package" + <# 1. Get latest GA and latest preview from npm 2. Check new version to be published to find is it GA or preview @@ -20,95 +28,60 @@ Write-Host "Find latest and next versions in npm registry for package" a. Set LATEST if package has never GA released b. Set NEXT tag #> -$packageName = $null -$packageVersion = $null -if ($GetPackageInfoFromPackageFileFn -and (Test-Path "Function:$GetPackageInfoFromPackageFileFn")) -{ - $pkgProps = &$GetPackageInfoFromPackageFileFn -pkg $packageArtifact -workingDirectory $workingDirectory - $packageName = $pkgProps.PackageId - $packageVersion = $pkgProps.PackageVersion -} -else -{ - Write-Error "The function for '$GetPackageInfoFromPackageFileFn' was not found.` - Make sure it is present in eng/scripts/Language-Settings.ps1 and referenced in eng/common/scripts/common.ps1.` - See https://github.com/Azure/azure-sdk-tools/blob/master/doc/common/common_engsys.md#code-structure" -} - - -$latestGAVersion = npm show $packageName@latest version -$latestPreviewVersion = npm show $packageName@next version -Write-Host "Latest GA version: $latestGAVersion" -Write-Host "Latest preview version: $latestPreviewVersion" -if ( $latestPreviewVersion -eq $null) -{ - Write-Host "'Next' tag is not present in npm registry for package $packageName" -} -else -{ - $latestPreviewVersion = [AzureEngSemanticVersion]::ParseVersionString($latestPreviewVersion) -} - -if ( $latestGAVersion -eq $null) -{ - Write-Host "GA version is not present in npm registry for package $packageName" -} -else +$npmVersionInfo = Get-LatestVersionInfoFromNpm -packageName $packageName +if ($npmVersionInfo -eq $null) { - $latestGAVersion = [AzureEngSemanticVersion]::ParseVersionString($latestGAVersion) + # Version info object should not be null even if package is not present in npm + Write-Error "Failed to get version info from NPM registry." + exit 1 } - -$newVersion = [AzureEngSemanticVersion]::ParseVersionString($packageVersion) +$latestVersion = $npmVersionInfo.Latest +$nextVersion = $npmVersionInfo.Next $setLatest = $false $setNext = $false - # Set Latest tag if new version is higher than current GA or if package has never GA released before -if ((-not $newVersion.IsPreRelease) -and ($latestGAVersion -eq $null -or $newVersion.CompareTo($latestGAVersion) -eq 1)) -{ - $setLatest = $true +if ((!$newVersion.IsPreRelease) -and ($latestVersion -eq $null -or $newVersion.CompareTo($latestVersion) -eq 1)) { + $setLatest = $true } -if ($newVersion.PrereleaseLabel -eq "preview") +if ($newVersion.PrereleaseLabel -eq "preview" -or $newVersion.PrereleaseLabel -eq "beta") { - # Set next tag if new preview is higher than both GA and current preview - $highestNpmVersion = $latestPreviewVersion - if (($highestNpmVersion -eq $null) -or ($latestGAVersion -ne $null -and $latestGAVersion.CompareTo($highestNpmVersion) -eq 1)) { - $highestNpmVersion = $latestGAVersion + Write-Host "Checking for next version tag" + # Set next tag if new preview is higher than both GA and current preview + $highestNpmVersion = Find-RecentPackageVersion -packageName $packageName + # New version is preview and if package is getting released first time or higher than currently available + if ($highestNpmVersion -eq $null -or $newVersion.CompareTo($highestNpmVersion) -eq 1) + { + $setNext = $true + # Set latest tag if package was never GA released + if ($latestVersion -eq $null) { + $setLatest = $true } - - # New version is preview and if package is getting released first time or higher than currently available - if ($highestNpmVersion -eq $null -or $newVersion.CompareTo($highestNpmVersion) -eq 1) - { - $setNext = $true - # Set latest tag if package was never GA released - if ($latestGAVersion -eq $null) { - $setLatest = $true - } - } + } } $tag = "" $additionalTag = "" if ($setLatest) { - Write-Host "Setting Tag to latest" - $tag = "latest" - if ($result.setNext) - { - Write-Host "Setting AdditionalTag to next" - $additionalTag = "next" - } + Write-Host "Setting Tag to latest" + $tag = "latest" + if ($setNext) + { + Write-Host "Setting AdditionalTag to next" + $additionalTag = "next" + } } -elseif ($result.setNext) +elseif ($setNext) { - Write-Host "Setting Tag to next" - $tag = "next" + Write-Host "Setting Tag to next" + $tag = "next" } $result = New-Object PSObject -Property @{ - Tag = $tag - AdditionalTag = $additionalTag + Tag = $tag + AdditionalTag = $additionalTag } write-Host $result return $result diff --git a/eng/tools/npm-helpers.ps1 b/eng/tools/npm-helpers.ps1 new file mode 100644 index 000000000000..699fa4d47626 --- /dev/null +++ b/eng/tools/npm-helpers.ps1 @@ -0,0 +1,76 @@ +$EngPath = Resolve-Path "${PSScriptRoot}/.." +$Engcommon = Join-Path $EngPath "common" +$EngCommonScriptsPath = Join-Path $Engcommon "scripts" +. (Join-Path $EngCommonScriptsPath common.ps1) + +function Get-PackageProperties($pkgArtifact, $workingDirectory) +{ + if ($GetPackageInfoFromPackageFileFn -and (Test-Path "Function:$GetPackageInfoFromPackageFileFn")) + { + return &$GetPackageInfoFromPackageFileFn -pkg $packageArtifact -workingDirectory $workingDirectory + } + else + { + Write-Error "The function for '$GetPackageInfoFromPackageFileFn' was not found.` + Make sure it is present in eng/scripts/Language-Settings.ps1 and referenced in eng/common/scripts/common.ps1.` + See https://github.com/Azure/azure-sdk-tools/blob/master/doc/common/common_engsys.md#code-structure" + return $null + } +} + +function Get-LatestVersionInfoFromNpm($packageName) +{ + $latestVersion = npm show $packageName@latest version + $nextVersion = npm show $packageName@next version + Write-Host "Latest version: $latestVersion" + Write-Host "Next version: $nextVersion" + if ( $nextVersion -eq $null) { + Write-Host "'Next' tag is not present in npm registry for package $packageName" + } + else { + $nextVersion = [AzureEngSemanticVersion]::ParseVersionString($nextVersion) + } + + if ( $latestVersion -eq $null) { + Write-Host "'latest' tag is not present in npm registry for package $packageName" + } + else { + $latestVersion = [AzureEngSemanticVersion]::ParseVersionString($latestVersion) + } + + $result = New-Object PSObject -Property @{ + Latest = $latestVersion + Next = $nextVersion + } + return $result +} + +function Find-RecentPackageVersion($packageName) +{ + $npmVersionInfo = Get-LatestVersionInfoFromNpm -packageName $packageName + if ($npmVersionInfo -ne $null) + { + $latestVersion = $npmVersionInfo.Latest + $nextVersion = $npmVersionInfo.Next + if (($nextVersion -ne $null) -and ($latestVersion -ne $null)) + { + if ($latestVersion.CompareTo($nextVersion) -eq 1) { + $highestNpmVersion = $latestVersion + } + else { + $highestNpmVersion = $nextVersion + } + } + else + { + if ($nextVersion -ne $null) { + $highestNpmVersion = $nextVersion + } + else { + $highestNpmVersion = $latestVersion + } + } + } + Write-Host "Recent version uploaded to NPM: $highestNpmVersion" + return $highestNpmVersion +} diff --git a/eng/tools/remove-npm-next-tag.ps1 b/eng/tools/remove-npm-next-tag.ps1 new file mode 100644 index 000000000000..5be4779c8cdc --- /dev/null +++ b/eng/tools/remove-npm-next-tag.ps1 @@ -0,0 +1,55 @@ +param ( + [Parameter(mandatory = $true)] + $packageArtifact, + [Parameter(mandatory = $true)] + $workingDirectory, + [Parameter(mandatory = $true)] + $npmToken +) + +. (Join-Path $PSScriptRoot npm-helpers.ps1) +$pkgProps = Get-PackageProperties -packageArtifact $packageArtifact -workingDirectory $workingDirectory +if ($pkgProps -eq $null) +{ + Write-Error "Failed to parse package artifact $packageArtifact to get package name" + exit 1 +} +$packageName = $pkgProps.PackageId +Write-Host "Package name: $packageName" +Write-Host "Find latest and next versions in npm registry for package" + +<# +1. Get latest GA and latest preview from npm +2. Check if latest GA is higher than next +3. Remove next tag from preview version if latest is higher than preview version +#> + +$npmVersionInfo = Get-LatestVersionInfoFromNpm -packageName $packageName +if ($npmVersionInfo -eq $null) +{ + # Version info object should not be null even if package is not present in npm + Write-Error "Failed to get version info from NPM registry." + exit 1 +} +$latestVersion = $npmVersionInfo.Latest +$nextVersion = $npmVersionInfo.Next + +if ( ($latestVersion -ne $null) -and ($nextVersion -ne $null) -and (!$latestVersion.IsPreRelease)) +{ + if ($latestVersion.CompareTo($nextVersion) -eq 1) + { + Write-Host "Latest Version $latestVersion is higher than next tagged version $nextVersion." + Write-Host "Removing next tag from $nextVersion." + $scriptsPath = Join-Path $EngPath "scripts" + . (Join-Path $scriptsPath npm-admin-tasks.ps1) -taskType "RemoveTag" -packageName $packageName -pkgVersion $nextVersion.ToString() -tagName "next" -npmToken $npmToken + } + else + { + Write-Host "Latest tagged version is higher than or same as next tagged version." + Write-Host "Skipping remove 'next' tag task." + } +} +else +{ + Write-Host "Latest or next tag is missing on npm or latest version is not GA release to compare versions." +} From 93ffa4939a978f4ba198728fd07b530ad7a43a12 Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Tue, 25 May 2021 14:43:29 -0400 Subject: [PATCH 03/14] Add step in release pipeline to remove next tag --- eng/pipelines/templates/stages/archetype-js-release.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/eng/pipelines/templates/stages/archetype-js-release.yml b/eng/pipelines/templates/stages/archetype-js-release.yml index 190deb7c65d5..b887d13cc0d2 100644 --- a/eng/pipelines/templates/stages/archetype-js-release.yml +++ b/eng/pipelines/templates/stages/archetype-js-release.yml @@ -85,6 +85,7 @@ stages: $result = .\get-npm-tags.ps1 -packageArtifact $pkgArtifact -workingDirectory $(System.DefaultWorkingDirectory) echo "##vso[task.setvariable variable=Tag]$result.Tag" echo "##vso[task.setvariable variable=AdditionalTag]$result.AdditionalTag" + condition: and(succeeded(), ne(variables['Skip.AutoAddTag'], 'true')) displayName: 'Set Tag and Additional Tag' - task: PowerShell@2 @@ -95,6 +96,12 @@ stages: arguments: '-pathToArtifacts $(Package.Archive) -accessLevel "public" -tag $(Tag) -additionalTag "$(AdditionalTag)" -registry ${{parameters.Registry}} -npmToken $(azure-sdk-npm-token)' pwsh: true + - pwsh: | + $result = .\get-npm-tags.ps1 -packageArtifact $pkgArtifact -workingDirectory $(System.DefaultWorkingDirectory) -npmToken $(azure-sdk-npm-token) + displayName: 'Remove Old Next Tag' + condition: and(succeeded(), ne(variables['Skip.RemoveOldTag'], 'true')) + + - ${{if ne(artifact.skipPublishDocMs, 'true')}}: - deployment: PublishDocs displayName: Docs.MS Release From 433a971c705b1341c8379f00b6a079beaa0055e7 Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Tue, 25 May 2021 17:10:04 -0400 Subject: [PATCH 04/14] Fix path to scripts --- eng/pipelines/templates/stages/archetype-js-release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/pipelines/templates/stages/archetype-js-release.yml b/eng/pipelines/templates/stages/archetype-js-release.yml index b887d13cc0d2..3bb74e338c93 100644 --- a/eng/pipelines/templates/stages/archetype-js-release.yml +++ b/eng/pipelines/templates/stages/archetype-js-release.yml @@ -82,7 +82,7 @@ stages: displayName: Detecting package archive - pwsh: | - $result = .\get-npm-tags.ps1 -packageArtifact $pkgArtifact -workingDirectory $(System.DefaultWorkingDirectory) + $result = /eng/scripts/tools/get-npm-tags.ps1 -packageArtifact $pkgArtifact -workingDirectory $(System.DefaultWorkingDirectory) echo "##vso[task.setvariable variable=Tag]$result.Tag" echo "##vso[task.setvariable variable=AdditionalTag]$result.AdditionalTag" condition: and(succeeded(), ne(variables['Skip.AutoAddTag'], 'true')) @@ -97,7 +97,7 @@ stages: pwsh: true - pwsh: | - $result = .\get-npm-tags.ps1 -packageArtifact $pkgArtifact -workingDirectory $(System.DefaultWorkingDirectory) -npmToken $(azure-sdk-npm-token) + $result = /eng/scripts/tools/remove-npm-next-tag.ps1 -packageArtifact $pkgArtifact -workingDirectory $(System.DefaultWorkingDirectory) -npmToken $(azure-sdk-npm-token) displayName: 'Remove Old Next Tag' condition: and(succeeded(), ne(variables['Skip.RemoveOldTag'], 'true')) From e1908159a16837bff6794a1e27d47969f7cf3817 Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Tue, 25 May 2021 17:50:09 -0400 Subject: [PATCH 05/14] Incorrect path --- eng/pipelines/templates/stages/archetype-js-release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/pipelines/templates/stages/archetype-js-release.yml b/eng/pipelines/templates/stages/archetype-js-release.yml index 3bb74e338c93..caa52da9c436 100644 --- a/eng/pipelines/templates/stages/archetype-js-release.yml +++ b/eng/pipelines/templates/stages/archetype-js-release.yml @@ -82,7 +82,7 @@ stages: displayName: Detecting package archive - pwsh: | - $result = /eng/scripts/tools/get-npm-tags.ps1 -packageArtifact $pkgArtifact -workingDirectory $(System.DefaultWorkingDirectory) + $result = eng/scripts/tools/get-npm-tags.ps1 -packageArtifact $pkgArtifact -workingDirectory $(System.DefaultWorkingDirectory) echo "##vso[task.setvariable variable=Tag]$result.Tag" echo "##vso[task.setvariable variable=AdditionalTag]$result.AdditionalTag" condition: and(succeeded(), ne(variables['Skip.AutoAddTag'], 'true')) @@ -97,7 +97,7 @@ stages: pwsh: true - pwsh: | - $result = /eng/scripts/tools/remove-npm-next-tag.ps1 -packageArtifact $pkgArtifact -workingDirectory $(System.DefaultWorkingDirectory) -npmToken $(azure-sdk-npm-token) + $result = eng/scripts/tools/remove-npm-next-tag.ps1 -packageArtifact $pkgArtifact -workingDirectory $(System.DefaultWorkingDirectory) -npmToken $(azure-sdk-npm-token) displayName: 'Remove Old Next Tag' condition: and(succeeded(), ne(variables['Skip.RemoveOldTag'], 'true')) From 6ee3fa546c9cc3db7510c2a8c3a5aaac0c27fb85 Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Tue, 25 May 2021 18:09:23 -0400 Subject: [PATCH 06/14] Changes as per review comments to use JS pacakge parser fn --- .../templates/stages/archetype-js-release.yml | 2 +- eng/tools/get-npm-tags.ps1 | 2 +- eng/tools/npm-helpers.ps1 | 15 --------------- eng/tools/remove-npm-next-tag.ps1 | 2 +- 4 files changed, 3 insertions(+), 18 deletions(-) diff --git a/eng/pipelines/templates/stages/archetype-js-release.yml b/eng/pipelines/templates/stages/archetype-js-release.yml index caa52da9c436..f84769aa08e7 100644 --- a/eng/pipelines/templates/stages/archetype-js-release.yml +++ b/eng/pipelines/templates/stages/archetype-js-release.yml @@ -97,7 +97,7 @@ stages: pwsh: true - pwsh: | - $result = eng/scripts/tools/remove-npm-next-tag.ps1 -packageArtifact $pkgArtifact -workingDirectory $(System.DefaultWorkingDirectory) -npmToken $(azure-sdk-npm-token) + eng/scripts/tools/remove-npm-next-tag.ps1 -packageArtifact $pkgArtifact -workingDirectory $(System.DefaultWorkingDirectory) -npmToken $(azure-sdk-npm-token) displayName: 'Remove Old Next Tag' condition: and(succeeded(), ne(variables['Skip.RemoveOldTag'], 'true')) diff --git a/eng/tools/get-npm-tags.ps1 b/eng/tools/get-npm-tags.ps1 index 65bd4104b69c..343eb69e100d 100644 --- a/eng/tools/get-npm-tags.ps1 +++ b/eng/tools/get-npm-tags.ps1 @@ -6,7 +6,7 @@ param ( ) . (Join-Path $PSScriptRoot npm-helpers.ps1) -$pkgProps = Get-PackageProperties -packageArtifact $packageArtifact -workingDirectory $workingDirectory +$pkgProps = Get-javascript-PackageInfoFromPackageFile -pkg $packageArtifact -workingDirectory $workingDirectory if ($pkgProps -eq $null) { Write-Error "Failed to parse package artifact $packageArtifact to get package name" diff --git a/eng/tools/npm-helpers.ps1 b/eng/tools/npm-helpers.ps1 index 699fa4d47626..968f96d07002 100644 --- a/eng/tools/npm-helpers.ps1 +++ b/eng/tools/npm-helpers.ps1 @@ -3,21 +3,6 @@ $Engcommon = Join-Path $EngPath "common" $EngCommonScriptsPath = Join-Path $Engcommon "scripts" . (Join-Path $EngCommonScriptsPath common.ps1) -function Get-PackageProperties($pkgArtifact, $workingDirectory) -{ - if ($GetPackageInfoFromPackageFileFn -and (Test-Path "Function:$GetPackageInfoFromPackageFileFn")) - { - return &$GetPackageInfoFromPackageFileFn -pkg $packageArtifact -workingDirectory $workingDirectory - } - else - { - Write-Error "The function for '$GetPackageInfoFromPackageFileFn' was not found.` - Make sure it is present in eng/scripts/Language-Settings.ps1 and referenced in eng/common/scripts/common.ps1.` - See https://github.com/Azure/azure-sdk-tools/blob/master/doc/common/common_engsys.md#code-structure" - return $null - } -} - function Get-LatestVersionInfoFromNpm($packageName) { $latestVersion = npm show $packageName@latest version diff --git a/eng/tools/remove-npm-next-tag.ps1 b/eng/tools/remove-npm-next-tag.ps1 index 5be4779c8cdc..625ec76f957e 100644 --- a/eng/tools/remove-npm-next-tag.ps1 +++ b/eng/tools/remove-npm-next-tag.ps1 @@ -8,7 +8,7 @@ param ( ) . (Join-Path $PSScriptRoot npm-helpers.ps1) -$pkgProps = Get-PackageProperties -packageArtifact $packageArtifact -workingDirectory $workingDirectory +$pkgProps = Get-javascript-PackageInfoFromPackageFile -pkg $packageArtifact -workingDirectory $workingDirectory if ($pkgProps -eq $null) { Write-Error "Failed to parse package artifact $packageArtifact to get package name" From 1a2a2daba9db261e2056ced12fa3d442f35b6630 Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Wed, 26 May 2021 12:36:51 -0400 Subject: [PATCH 07/14] Changes from npm commands to REST --- eng/tools/get-npm-tags.ps1 | 20 +++---- eng/tools/npm-helpers.ps1 | 88 +++++++++++++++---------------- eng/tools/remove-npm-next-tag.ps1 | 14 ++--- 3 files changed, 58 insertions(+), 64 deletions(-) diff --git a/eng/tools/get-npm-tags.ps1 b/eng/tools/get-npm-tags.ps1 index 343eb69e100d..b806bea99d44 100644 --- a/eng/tools/get-npm-tags.ps1 +++ b/eng/tools/get-npm-tags.ps1 @@ -28,16 +28,14 @@ Write-Host "Find latest and next versions in npm registry for package" a. Set LATEST if package has never GA released b. Set NEXT tag #> -$npmVersionInfo = Get-LatestVersionInfoFromNpm -packageName $packageName +$npmVersionInfo = GetNpmTagVersions -packageName $packageName if ($npmVersionInfo -eq $null) { # Version info object should not be null even if package is not present in npm Write-Error "Failed to get version info from NPM registry." exit 1 } -$latestVersion = $npmVersionInfo.Latest -$nextVersion = $npmVersionInfo.Next - +$latestVersion = [AzureEngSemanticVersion]::ParseVersionString($npmVersionInfo.latest) $setLatest = $false $setNext = $false # Set Latest tag if new version is higher than current GA or if package has never GA released before @@ -48,8 +46,9 @@ if ((!$newVersion.IsPreRelease) -and ($latestVersion -eq $null -or $newVersion.C if ($newVersion.PrereleaseLabel -eq "preview" -or $newVersion.PrereleaseLabel -eq "beta") { Write-Host "Checking for next version tag" - # Set next tag if new preview is higher than both GA and current preview - $highestNpmVersion = Find-RecentPackageVersion -packageName $packageName + # Set next tag if new preview is higher than highest present on npm + $highestNpmVersion = FindRecentPackageVersion -packageName $packageName + $highestNpmVersion = [AzureEngSemanticVersion]::ParseVersionString($highestNpmVersion) # New version is preview and if package is getting released first time or higher than currently available if ($highestNpmVersion -eq $null -or $newVersion.CompareTo($highestNpmVersion) -eq 1) { @@ -65,17 +64,12 @@ $tag = "" $additionalTag = "" if ($setLatest) { - Write-Host "Setting Tag to latest" $tag = "latest" - if ($setNext) - { - Write-Host "Setting AdditionalTag to next" + if ($setNext) { $additionalTag = "next" } } -elseif ($setNext) -{ - Write-Host "Setting Tag to next" +elseif ($setNext) { $tag = "next" } diff --git a/eng/tools/npm-helpers.ps1 b/eng/tools/npm-helpers.ps1 index 968f96d07002..461fa9b077f7 100644 --- a/eng/tools/npm-helpers.ps1 +++ b/eng/tools/npm-helpers.ps1 @@ -3,59 +3,59 @@ $Engcommon = Join-Path $EngPath "common" $EngCommonScriptsPath = Join-Path $Engcommon "scripts" . (Join-Path $EngCommonScriptsPath common.ps1) -function Get-LatestVersionInfoFromNpm($packageName) +function GetNpmTagVersions($packageName) { - $latestVersion = npm show $packageName@latest version - $nextVersion = npm show $packageName@next version - Write-Host "Latest version: $latestVersion" - Write-Host "Next version: $nextVersion" - if ( $nextVersion -eq $null) { - Write-Host "'Next' tag is not present in npm registry for package $packageName" - } - else { - $nextVersion = [AzureEngSemanticVersion]::ParseVersionString($nextVersion) - } + try + { + $existingVersion = Invoke-RestMethod -Method GET -Uri "http://registry.npmjs.com/${PackageName}" + $latest = ($existingVersion."dist-tags").latest + $next = ($existingVersion."dist-tags").next + Write-Host "Latest version: $latest" + Write-Host "Next version: $next" + if ($latest -eq $null) { + Write-Host "'latest' tag is not present in npm registry for package $packageName" + } + if ($next -eq $null) { + Write-Host "'Next' tag is not present in npm registry for package $packageName" + } - if ( $latestVersion -eq $null) { - Write-Host "'latest' tag is not present in npm registry for package $packageName" + return New-Object PSObject -Property @{ + latest = $latest + next = $next + } } - else { - $latestVersion = [AzureEngSemanticVersion]::ParseVersionString($latestVersion) + catch + { + LogError "Failed to retrieve package versions. `n$_" + return $null } +} - $result = New-Object PSObject -Property @{ - Latest = $latestVersion - Next = $nextVersion +function GetNpmPackageVersions ($packageName) +{ + try + { + Write-Host "Checking versions present on npm for package $packageName" + $existingVersion = Invoke-RestMethod -Method GET -Uri "http://registry.npmjs.com/${packageName}" + return ($existingVersion.versions | Get-Member -MemberType NoteProperty).Name + } + catch + { + LogError "Failed to retrieve package versions. `n$_" + return $null } - return $result } -function Find-RecentPackageVersion($packageName) +function FindRecentPackageVersion($packageName) { - $npmVersionInfo = Get-LatestVersionInfoFromNpm -packageName $packageName - if ($npmVersionInfo -ne $null) + $versions = (GetNpmPackageVersions -packageName $packageName) | ? {$_ -NotMatch "alpha|dev"} + if ($versions -ne $null -and $versions.Count -gt 0) { - $latestVersion = $npmVersionInfo.Latest - $nextVersion = $npmVersionInfo.Next - if (($nextVersion -ne $null) -and ($latestVersion -ne $null)) - { - if ($latestVersion.CompareTo($nextVersion) -eq 1) { - $highestNpmVersion = $latestVersion - } - else { - $highestNpmVersion = $nextVersion - } - } - else - { - if ($nextVersion -ne $null) { - $highestNpmVersion = $nextVersion - } - else { - $highestNpmVersion = $latestVersion - } - } + $versions = [AzureEngSemanticVersion]::SortVersionStrings($versions) + $highestNpmVersion = $versions[0] + Write-Host "Recent version uploaded to NPM: $highestNpmVersion" + return $highestNpmVersion } - Write-Host "Recent version uploaded to NPM: $highestNpmVersion" - return $highestNpmVersion + + return $null } diff --git a/eng/tools/remove-npm-next-tag.ps1 b/eng/tools/remove-npm-next-tag.ps1 index 625ec76f957e..1ad09c1d9f77 100644 --- a/eng/tools/remove-npm-next-tag.ps1 +++ b/eng/tools/remove-npm-next-tag.ps1 @@ -24,15 +24,15 @@ Write-Host "Find latest and next versions in npm registry for package" 3. Remove next tag from preview version if latest is higher than preview version #> -$npmVersionInfo = Get-LatestVersionInfoFromNpm -packageName $packageName +$npmVersionInfo = GetNpmTagVersions -packageName $packageName if ($npmVersionInfo -eq $null) { - # Version info object should not be null even if package is not present in npm - Write-Error "Failed to get version info from NPM registry." - exit 1 + # Version info object should not be null even if package is not present in npm + Write-Error "Failed to get version info from NPM registry." + exit 1 } -$latestVersion = $npmVersionInfo.Latest -$nextVersion = $npmVersionInfo.Next +$nextVersion = [AzureEngSemanticVersion]::ParseVersionString($npmVersionInfo.next) +$latestVersion = [AzureEngSemanticVersion]::ParseVersionString($npmVersionInfo.latest) if ( ($latestVersion -ne $null) -and ($nextVersion -ne $null) -and (!$latestVersion.IsPreRelease)) { @@ -45,7 +45,7 @@ if ( ($latestVersion -ne $null) -and ($nextVersion -ne $null) -and (!$latestVers } else { - Write-Host "Latest tagged version is higher than or same as next tagged version." + Write-Host "Latest tagged version is lower than or same as next tagged version." Write-Host "Skipping remove 'next' tag task." } } From 33b6ceb20418383efadf5538bb2f6b88b2720931 Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Wed, 26 May 2021 22:59:36 -0400 Subject: [PATCH 08/14] Added test cases for tags --- eng/tools/get-npm-tags.ps1 | 66 +---------------------- eng/tools/npm-helpers.ps1 | 105 ++++++++++++++++++++++++++++++++++++- 2 files changed, 105 insertions(+), 66 deletions(-) diff --git a/eng/tools/get-npm-tags.ps1 b/eng/tools/get-npm-tags.ps1 index b806bea99d44..84812da354d2 100644 --- a/eng/tools/get-npm-tags.ps1 +++ b/eng/tools/get-npm-tags.ps1 @@ -6,6 +6,7 @@ param ( ) . (Join-Path $PSScriptRoot npm-helpers.ps1) + $pkgProps = Get-javascript-PackageInfoFromPackageFile -pkg $packageArtifact -workingDirectory $workingDirectory if ($pkgProps -eq $null) { @@ -14,68 +15,5 @@ if ($pkgProps -eq $null) } $packageName = $pkgProps.PackageId $packageVersion = $pkgProps.PackageVersion -$newVersion = [AzureEngSemanticVersion]::ParseVersionString($packageVersion) -Write-Host "Package name: $packageName" -Write-Host "Package version: $packageVersion" -Write-Host "Find latest and next versions in npm registry for package" - -<# -1. Get latest GA and latest preview from npm -2. Check new version to be published to find is it GA or preview -3. If new Version is GA: - a. If higher than current latest, or first GA then set LATEST tag -4. If new version is preview and higher than current higher version in npm: - a. Set LATEST if package has never GA released - b. Set NEXT tag -#> -$npmVersionInfo = GetNpmTagVersions -packageName $packageName -if ($npmVersionInfo -eq $null) -{ - # Version info object should not be null even if package is not present in npm - Write-Error "Failed to get version info from NPM registry." - exit 1 -} -$latestVersion = [AzureEngSemanticVersion]::ParseVersionString($npmVersionInfo.latest) -$setLatest = $false -$setNext = $false -# Set Latest tag if new version is higher than current GA or if package has never GA released before -if ((!$newVersion.IsPreRelease) -and ($latestVersion -eq $null -or $newVersion.CompareTo($latestVersion) -eq 1)) { - $setLatest = $true -} - -if ($newVersion.PrereleaseLabel -eq "preview" -or $newVersion.PrereleaseLabel -eq "beta") -{ - Write-Host "Checking for next version tag" - # Set next tag if new preview is higher than highest present on npm - $highestNpmVersion = FindRecentPackageVersion -packageName $packageName - $highestNpmVersion = [AzureEngSemanticVersion]::ParseVersionString($highestNpmVersion) - # New version is preview and if package is getting released first time or higher than currently available - if ($highestNpmVersion -eq $null -or $newVersion.CompareTo($highestNpmVersion) -eq 1) - { - $setNext = $true - # Set latest tag if package was never GA released - if ($latestVersion -eq $null) { - $setLatest = $true - } - } -} - -$tag = "" -$additionalTag = "" -if ($setLatest) -{ - $tag = "latest" - if ($setNext) { - $additionalTag = "next" - } -} -elseif ($setNext) { - $tag = "next" -} - -$result = New-Object PSObject -Property @{ - Tag = $tag - AdditionalTag = $additionalTag -} -write-Host $result +$result = GetNewNpmTags -packageName $packageName -packageVersion $packageVersion return $result diff --git a/eng/tools/npm-helpers.ps1 b/eng/tools/npm-helpers.ps1 index 461fa9b077f7..fc734966caf4 100644 --- a/eng/tools/npm-helpers.ps1 +++ b/eng/tools/npm-helpers.ps1 @@ -26,7 +26,6 @@ function GetNpmTagVersions($packageName) } catch { - LogError "Failed to retrieve package versions. `n$_" return $null } } @@ -41,7 +40,6 @@ function GetNpmPackageVersions ($packageName) } catch { - LogError "Failed to retrieve package versions. `n$_" return $null } } @@ -59,3 +57,106 @@ function FindRecentPackageVersion($packageName) return $null } + +function GetNewNpmTags($packageName, $packageVersion) +{ + $newVersion = [AzureEngSemanticVersion]::ParseVersionString($packageVersion) + Write-Host "Package name: $packageName" + Write-Host "Package version: $packageVersion" + Write-Host "Find latest and next versions in npm registry for package" + + <# + 1. Get latest GA and latest preview from npm + 2. Check new version to be published to find is it GA or preview + 3. If new Version is GA: + a. If higher than current latest, or first GA then set LATEST tag + 4. If new version is preview and higher than current higher version in npm: + a. Set LATEST if package has never GA released + b. Set NEXT tag + #> + $npmVersionInfo = GetNpmTagVersions -packageName $packageName + if ($npmVersionInfo -eq $null) + { + # Version info object should not be null even if package is not present in npm + Write-Error "Failed to get version info from NPM registry." + } + $latestVersion = [AzureEngSemanticVersion]::ParseVersionString($npmVersionInfo.latest) + $setLatest = $false + $setNext = $false + # Set Latest tag if new version is higher than current GA or if package has never GA released before + if ((!$newVersion.IsPreRelease) -and ($latestVersion -eq $null -or $newVersion.CompareTo($latestVersion) -eq 1)) { + $setLatest = $true + } + + if ($newVersion.PrereleaseLabel -eq "preview" -or $newVersion.PrereleaseLabel -eq "beta") + { + Write-Host "Checking for next version tag" + # Set next tag if new preview is higher than highest present on npm + $highestNpmVersion = FindRecentPackageVersion -packageName $packageName + $highestNpmVersion = [AzureEngSemanticVersion]::ParseVersionString($highestNpmVersion) + # New version is preview and if package is getting released first time or higher than currently available + if ($highestNpmVersion -eq $null -or $newVersion.CompareTo($highestNpmVersion) -eq 1) + { + $setNext = $true + # Set latest tag if package was never GA released + if ($latestVersion -eq $null -or $latestVersion.IsPreRelease) { + $setLatest = $true + } + } + } + + $tag = "" + $additionalTag = "" + if ($setLatest) + { + $tag = "latest" + if ($setNext) { + $additionalTag = "next" + } + } + elseif ($setNext) { + $tag = "next" + } + + $result = New-Object PSObject -Property @{ + Tag = $tag + AdditionalTag = $additionalTag + } + write-Host $result + return $result +} + +function CreateTestCase($packageName, $packageVersion, $eTag, $eAdditional) +{ + $r = GetNewNpmTags -packageName $packageName -packageVersion $packageVersion + if ($r.Tag -ne $eTag -or $r.AdditionalTag -ne $eAdditional) + { + Write-Error "Failed test case." + Write-Host "Extected tag: '$($eTag)'' Actual tag: '$($r.Tag)'" + Write-Host "Extected tag: '$($eAdditional)' Actual tag: '$($r.AdditionalTag)'" + } + else{ + Write-Host "Succeeded test case for $packageName version $packageVersion" + } +} + +function TestNewTags() +{ + # test cases are based on currently available package version on npm + CreateTestCase -packageVersion "1.1.0" -eTag "latest" -eAdditional "" -packageName "@azure/template" + CreateTestCase -packageName "@azure/template" -packageVersion "1.1.0-preview.1" -eTag "latest" -eAdditional "next" + CreateTestCase -packageName "@azure/template" -packageVersion "1.0.9" -eTag "latest" -eAdditional "" + CreateTestCase -packageName "@azure/template" -packageVersion "1.0.8" -eTag "" -eAdditional "" + CreateTestCase -packageName "@azure/core-http" -packageVersion "1.2.5" -eTag "latest" -eAdditional "" + CreateTestCase -packageName "@azure/core-http" -packageVersion "1.3.0-preview.1" -eTag "next" -eAdditional "" + CreateTestCase -packageName "@azure/core-http" -packageVersion "1.2.2" -eTag "" -eAdditional "" + CreateTestCase -packageName "@azure/core-http" -packageVersion "1.2.5-preview.1" -eTag "next" -eAdditional "" + CreateTestCase -packageName "@azure/storage-blob" -packageVersion "12.5.1" -eTag "latest" -eAdditional "" + CreateTestCase -packageName "@azure/storage-blob" -packageVersion "12.6.0-beta.2" -eTag "next" -eAdditional "" + CreateTestCase -packageName "@azure/storage-blob" -packageVersion "12.6.0" -eTag "latest" -eAdditional "" + CreateTestCase -packageName "@azure/storage-blob" -packageVersion "12.6.0-alpha.20210525.2" -eTag "" -eAdditional "" + CreateTestCase -packageName "@azure/storage-blob" -packageVersion "12.4.1" -eTag "" -eAdditional "" + CreateTestCase -packageName "@azure/storage-blob" -packageVersion "12.4.1-preview.1" -eTag "" -eAdditional "" + CreateTestCase -packageName "@azure/dummy-new-package" -packageVersion "1.0.0" -eTag "latest" -eAdditional "" + CreateTestCase -packageName "@azure/dummy-new-package" -packageVersion "1.0.0-preview.1" -eTag "latest" -eAdditional "next" +} From d59f3d8ead2866079a322dd8db6cc17b570938c2 Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Tue, 1 Jun 2021 12:51:28 -0400 Subject: [PATCH 09/14] Updated as per review comments --- eng/tools/npm-helpers.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/tools/npm-helpers.ps1 b/eng/tools/npm-helpers.ps1 index fc734966caf4..edcfff5e25d7 100644 --- a/eng/tools/npm-helpers.ps1 +++ b/eng/tools/npm-helpers.ps1 @@ -7,7 +7,7 @@ function GetNpmTagVersions($packageName) { try { - $existingVersion = Invoke-RestMethod -Method GET -Uri "http://registry.npmjs.com/${PackageName}" + $existingVersion = Invoke-RestMethod -Method GET -Uri "https://registry.npmjs.com/${PackageName}" $latest = ($existingVersion."dist-tags").latest $next = ($existingVersion."dist-tags").next Write-Host "Latest version: $latest" @@ -35,7 +35,7 @@ function GetNpmPackageVersions ($packageName) try { Write-Host "Checking versions present on npm for package $packageName" - $existingVersion = Invoke-RestMethod -Method GET -Uri "http://registry.npmjs.com/${packageName}" + $existingVersion = Invoke-RestMethod -Method GET -Uri "https://registry.npmjs.com/${packageName}" return ($existingVersion.versions | Get-Member -MemberType NoteProperty).Name } catch From 59c3766673b8978b0dfc66ea81e4927816eeb0be Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Tue, 1 Jun 2021 13:12:30 -0400 Subject: [PATCH 10/14] Updated as per review comments --- eng/tools/npm-helpers.ps1 | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/eng/tools/npm-helpers.ps1 b/eng/tools/npm-helpers.ps1 index edcfff5e25d7..968188c19090 100644 --- a/eng/tools/npm-helpers.ps1 +++ b/eng/tools/npm-helpers.ps1 @@ -46,8 +46,8 @@ function GetNpmPackageVersions ($packageName) function FindRecentPackageVersion($packageName) { - $versions = (GetNpmPackageVersions -packageName $packageName) | ? {$_ -NotMatch "alpha|dev"} - if ($versions -ne $null -and $versions.Count -gt 0) + $versions = (GetNpmPackageVersions -packageName $packageName).Where({$_ -notmatch "alpha|dev"}) + if ($versions.Count -gt 0) { $versions = [AzureEngSemanticVersion]::SortVersionStrings($versions) $highestNpmVersion = $versions[0] @@ -75,11 +75,6 @@ function GetNewNpmTags($packageName, $packageVersion) b. Set NEXT tag #> $npmVersionInfo = GetNpmTagVersions -packageName $packageName - if ($npmVersionInfo -eq $null) - { - # Version info object should not be null even if package is not present in npm - Write-Error "Failed to get version info from NPM registry." - } $latestVersion = [AzureEngSemanticVersion]::ParseVersionString($npmVersionInfo.latest) $setLatest = $false $setNext = $false From 95dc27e00a7b05135a6e461d7fa43e9544a91bfa Mon Sep 17 00:00:00 2001 From: Praveen Kuttappan Date: Tue, 8 Jun 2021 13:58:11 -0400 Subject: [PATCH 11/14] Update tag cleanup step name --- eng/pipelines/templates/stages/archetype-js-release.yml | 6 +++--- .../cleanup-npm-next-tag.ps1} | 4 +++- eng/{tools => scripts}/get-npm-tags.ps1 | 3 ++- eng/{tools => scripts/helpers}/npm-helpers.ps1 | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) rename eng/{tools/remove-npm-next-tag.ps1 => scripts/cleanup-npm-next-tag.ps1} (95%) rename eng/{tools => scripts}/get-npm-tags.ps1 (85%) rename eng/{tools => scripts/helpers}/npm-helpers.ps1 (99%) diff --git a/eng/pipelines/templates/stages/archetype-js-release.yml b/eng/pipelines/templates/stages/archetype-js-release.yml index f84769aa08e7..b6646c399f1d 100644 --- a/eng/pipelines/templates/stages/archetype-js-release.yml +++ b/eng/pipelines/templates/stages/archetype-js-release.yml @@ -82,7 +82,7 @@ stages: displayName: Detecting package archive - pwsh: | - $result = eng/scripts/tools/get-npm-tags.ps1 -packageArtifact $pkgArtifact -workingDirectory $(System.DefaultWorkingDirectory) + $result = eng/scripts/get-npm-tags.ps1 -packageArtifact $pkgArtifact -workingDirectory $(System.DefaultWorkingDirectory) echo "##vso[task.setvariable variable=Tag]$result.Tag" echo "##vso[task.setvariable variable=AdditionalTag]$result.AdditionalTag" condition: and(succeeded(), ne(variables['Skip.AutoAddTag'], 'true')) @@ -97,8 +97,8 @@ stages: pwsh: true - pwsh: | - eng/scripts/tools/remove-npm-next-tag.ps1 -packageArtifact $pkgArtifact -workingDirectory $(System.DefaultWorkingDirectory) -npmToken $(azure-sdk-npm-token) - displayName: 'Remove Old Next Tag' + eng/scripts/cleanup-npm-next-tag.ps1 -packageArtifact $pkgArtifact -workingDirectory $(System.DefaultWorkingDirectory) -npmToken $(azure-sdk-npm-token) + displayName: 'Cleanup Npm Next Tag' condition: and(succeeded(), ne(variables['Skip.RemoveOldTag'], 'true')) diff --git a/eng/tools/remove-npm-next-tag.ps1 b/eng/scripts/cleanup-npm-next-tag.ps1 similarity index 95% rename from eng/tools/remove-npm-next-tag.ps1 rename to eng/scripts/cleanup-npm-next-tag.ps1 index 1ad09c1d9f77..c8d34f1fad54 100644 --- a/eng/tools/remove-npm-next-tag.ps1 +++ b/eng/scripts/cleanup-npm-next-tag.ps1 @@ -7,7 +7,9 @@ param ( $npmToken ) -. (Join-Path $PSScriptRoot npm-helpers.ps1) +$HelpersPath = Join-Path $PSScriptRoot "helpers" +. (Join-Path $HelpersPath npm-helpers.ps1) + $pkgProps = Get-javascript-PackageInfoFromPackageFile -pkg $packageArtifact -workingDirectory $workingDirectory if ($pkgProps -eq $null) { diff --git a/eng/tools/get-npm-tags.ps1 b/eng/scripts/get-npm-tags.ps1 similarity index 85% rename from eng/tools/get-npm-tags.ps1 rename to eng/scripts/get-npm-tags.ps1 index 84812da354d2..7a7113be54b7 100644 --- a/eng/tools/get-npm-tags.ps1 +++ b/eng/scripts/get-npm-tags.ps1 @@ -5,7 +5,8 @@ param ( $workingDirectory ) -. (Join-Path $PSScriptRoot npm-helpers.ps1) +$HelpersPath = Join-Path $PSScriptRoot "helpers" +. (Join-Path $HelpersPath npm-helpers.ps1) $pkgProps = Get-javascript-PackageInfoFromPackageFile -pkg $packageArtifact -workingDirectory $workingDirectory if ($pkgProps -eq $null) diff --git a/eng/tools/npm-helpers.ps1 b/eng/scripts/helpers/npm-helpers.ps1 similarity index 99% rename from eng/tools/npm-helpers.ps1 rename to eng/scripts/helpers/npm-helpers.ps1 index 968188c19090..11bc265b8ae5 100644 --- a/eng/tools/npm-helpers.ps1 +++ b/eng/scripts/helpers/npm-helpers.ps1 @@ -1,4 +1,4 @@ -$EngPath = Resolve-Path "${PSScriptRoot}/.." +$EngPath = Resolve-Path "${PSScriptRoot}/../.." $Engcommon = Join-Path $EngPath "common" $EngCommonScriptsPath = Join-Path $Engcommon "scripts" . (Join-Path $EngCommonScriptsPath common.ps1) From 85a575767848813b0ffd180995599342abf9841d Mon Sep 17 00:00:00 2001 From: Praveen Kuttappan Date: Mon, 14 Jun 2021 16:38:54 -0400 Subject: [PATCH 12/14] SEt path to package artifact --- eng/pipelines/templates/stages/archetype-js-release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/pipelines/templates/stages/archetype-js-release.yml b/eng/pipelines/templates/stages/archetype-js-release.yml index b6646c399f1d..d27220953bf3 100644 --- a/eng/pipelines/templates/stages/archetype-js-release.yml +++ b/eng/pipelines/templates/stages/archetype-js-release.yml @@ -82,7 +82,7 @@ stages: displayName: Detecting package archive - pwsh: | - $result = eng/scripts/get-npm-tags.ps1 -packageArtifact $pkgArtifact -workingDirectory $(System.DefaultWorkingDirectory) + $result = eng/scripts/get-npm-tags.ps1 -packageArtifact $(Package.Archive) -workingDirectory $(System.DefaultWorkingDirectory) echo "##vso[task.setvariable variable=Tag]$result.Tag" echo "##vso[task.setvariable variable=AdditionalTag]$result.AdditionalTag" condition: and(succeeded(), ne(variables['Skip.AutoAddTag'], 'true')) @@ -97,7 +97,7 @@ stages: pwsh: true - pwsh: | - eng/scripts/cleanup-npm-next-tag.ps1 -packageArtifact $pkgArtifact -workingDirectory $(System.DefaultWorkingDirectory) -npmToken $(azure-sdk-npm-token) + eng/scripts/cleanup-npm-next-tag.ps1 -packageArtifact $(Package.Archive) -workingDirectory $(System.DefaultWorkingDirectory) -npmToken $(azure-sdk-npm-token) displayName: 'Cleanup Npm Next Tag' condition: and(succeeded(), ne(variables['Skip.RemoveOldTag'], 'true')) From 7b7bdb034e1853123659bb6aed314ee9db916aae Mon Sep 17 00:00:00 2001 From: Praveen Kuttappan Date: Mon, 14 Jun 2021 17:54:10 -0400 Subject: [PATCH 13/14] add debug line --- eng/pipelines/templates/stages/archetype-js-release.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eng/pipelines/templates/stages/archetype-js-release.yml b/eng/pipelines/templates/stages/archetype-js-release.yml index d27220953bf3..0a60393fa8b6 100644 --- a/eng/pipelines/templates/stages/archetype-js-release.yml +++ b/eng/pipelines/templates/stages/archetype-js-release.yml @@ -82,7 +82,8 @@ stages: displayName: Detecting package archive - pwsh: | - $result = eng/scripts/get-npm-tags.ps1 -packageArtifact $(Package.Archive) -workingDirectory $(System.DefaultWorkingDirectory) + write-host "$(Package.Archive)" + $result = eng/scripts/get-npm-tags.ps1 -packageArtifact $(Package.Archive) -workingDirectory $(System.DefaultWorkingDirectory)/temp echo "##vso[task.setvariable variable=Tag]$result.Tag" echo "##vso[task.setvariable variable=AdditionalTag]$result.AdditionalTag" condition: and(succeeded(), ne(variables['Skip.AutoAddTag'], 'true')) From 6f1d515595ae9a8f7ac7e62cb3c2fdfbc4311ae4 Mon Sep 17 00:00:00 2001 From: Praveen Kuttappan Date: Mon, 14 Jun 2021 18:14:59 -0400 Subject: [PATCH 14/14] Log tag values --- eng/pipelines/templates/stages/archetype-js-release.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/eng/pipelines/templates/stages/archetype-js-release.yml b/eng/pipelines/templates/stages/archetype-js-release.yml index 0a60393fa8b6..0e7aca235ca4 100644 --- a/eng/pipelines/templates/stages/archetype-js-release.yml +++ b/eng/pipelines/templates/stages/archetype-js-release.yml @@ -84,8 +84,10 @@ stages: - pwsh: | write-host "$(Package.Archive)" $result = eng/scripts/get-npm-tags.ps1 -packageArtifact $(Package.Archive) -workingDirectory $(System.DefaultWorkingDirectory)/temp - echo "##vso[task.setvariable variable=Tag]$result.Tag" - echo "##vso[task.setvariable variable=AdditionalTag]$result.AdditionalTag" + write-host "Tag: $($result.Tag)" + write-host "Tag: $($result.AdditionalTag)" + echo "##vso[task.setvariable variable=Tag]$($result.Tag)" + echo "##vso[task.setvariable variable=AdditionalTag]$($result.AdditionalTag)" condition: and(succeeded(), ne(variables['Skip.AutoAddTag'], 'true')) displayName: 'Set Tag and Additional Tag'