-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
231 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
param ( | ||
[Parameter(mandatory = $true)] | ||
$packageArtifact, | ||
[Parameter(mandatory = $true)] | ||
$workingDirectory | ||
) | ||
|
||
. (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 | ||
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 = 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 | ||
|
||
$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 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 | ||
} | ||
} | ||
} | ||
|
||
$tag = "" | ||
$additionalTag = "" | ||
if ($setLatest) | ||
{ | ||
Write-Host "Setting Tag to latest" | ||
$tag = "latest" | ||
if ($setNext) | ||
{ | ||
Write-Host "Setting AdditionalTag to next" | ||
$additionalTag = "next" | ||
} | ||
} | ||
elseif ($setNext) | ||
{ | ||
Write-Host "Setting Tag to next" | ||
$tag = "next" | ||
} | ||
|
||
$result = New-Object PSObject -Property @{ | ||
Tag = $tag | ||
AdditionalTag = $additionalTag | ||
} | ||
write-Host $result | ||
return $result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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." | ||
} |