From 2db30dd0141ea5801424a5c77195d905b2c8e9f6 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Thu, 3 Dec 2020 12:01:06 -0800 Subject: [PATCH 01/10] Add PrepareRelease Script --- eng/common/scripts/Prepare-Release.ps1 | 296 +++++++++++++++++++++++++ 1 file changed, 296 insertions(+) create mode 100644 eng/common/scripts/Prepare-Release.ps1 diff --git a/eng/common/scripts/Prepare-Release.ps1 b/eng/common/scripts/Prepare-Release.ps1 new file mode 100644 index 000000000000..712f705b7153 --- /dev/null +++ b/eng/common/scripts/Prepare-Release.ps1 @@ -0,0 +1,296 @@ +#Requires -Version 6.0 + +[CmdletBinding()] +param( + [Parameter(Mandatory=$true)] + [string]$packageName, + [string]$serviceName, + [string]$ReleaseDate +) + +. ${PSScriptRoot}\common.ps1 + +function Get-LevenshteinDistance { + <# + .SYNOPSIS + Get the Levenshtein distance between two strings. + .DESCRIPTION + The Levenshtein Distance is a way of quantifying how dissimilar two strings (e.g., words) are to one another by counting the minimum number of operations required to transform one string into the other. + .EXAMPLE + Get-LevenshteinDistance 'kitten' 'sitting' + .LINK + http://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance#C.23 + http://en.wikipedia.org/wiki/Edit_distance + https://communary.wordpress.com/ + https://github.com/gravejester/Communary.PASM + .NOTES + Author: Øyvind Kallstad + Date: 07.11.2014 + Version: 1.0 + #> + [CmdletBinding()] + param( + [Parameter(Position = 0)] + [string]$String1, + + [Parameter(Position = 1)] + [string]$String2, + + # Makes matches case-sensitive. By default, matches are not case-sensitive. + [Parameter()] + [switch] $CaseSensitive, + + # A normalized output will fall in the range 0 (perfect match) to 1 (no match). + [Parameter()] + [switch] $NormalizeOutput + ) + + if (-not($CaseSensitive)) { + $String1 = $String1.ToLowerInvariant() + $String2 = $String2.ToLowerInvariant() + } + + $d = New-Object 'Int[,]' ($String1.Length + 1), ($String2.Length + 1) + for ($i = 0; $i -le $d.GetUpperBound(0); $i++) { + $d[$i,0] = $i + } + + for ($i = 0; $i -le $d.GetUpperBound(1); $i++) { + $d[0,$i] = $i + } + + for ($i = 1; $i -le $d.GetUpperBound(0); $i++) { + for ($j = 1; $j -le $d.GetUpperBound(1); $j++) { + $cost = [Convert]::ToInt32((-not($String1[$i-1] -ceq $String2[$j-1]))) + $min1 = $d[($i-1),$j] + 1 + $min2 = $d[$i,($j-1)] + 1 + $min3 = $d[($i-1),($j-1)] + $cost + $d[$i,$j] = [Math]::Min([Math]::Min($min1,$min2),$min3) + } + } + + $distance = ($d[$d.GetUpperBound(0),$d.GetUpperBound(1)]) + + if ($NormalizeOutput) { + return (1 - ($distance) / ([Math]::Max($String1.Length,$String2.Length))) + } + + else { + return $distance + } +} + +function Get-ReleaseDay($baseDate) +{ + # Find first friday + while ($baseDate.DayOfWeek -ne 5) + { + $baseDate = $baseDate.AddDays(1) + } + + # Go to Tuesday + $baseDate = $baseDate.AddDays(4) + + return $baseDate; +} + +$ErrorPreference = 'Stop' +$repoRoot = Resolve-Path "$PSScriptRoot/../.."; +$commonParameter = @("--organization", "https://dev.azure.com/azure-sdk", "-o", "json", "--only-show-errors") + +if (!(Get-Command az)) { + throw 'You must have the Azure CLI installed: https://aka.ms/azure-cli' +} + +az extension show -n azure-devops > $null + +if (!$?){ + throw 'You must have the azure-devops extension run `az extension add --name azure-devops`' +} + +$packageProperties = Get-PkgProperties -PackageName $package -ServiceDirectory $serviceName +$packageDirectory = Get-ChildItem "$repoRoot/sdk" -Directory -Recurse -Depth 2 -Filter $package +$serviceDirectory = $packageDirectory.Parent.Name + +Write-Host "Source directory $serviceDirectory" + +try +{ + $existing = Invoke-WebRequest "https://api.nuget.org/v3-flatcontainer/$($package.ToLower())/index.json" | ConvertFrom-Json; +} +catch +{ + $existing = @() +} + + +if (!$ReleaseDate) +{ + $currentDate = Get-Date + $thisMonthReleaseDate = Get-ReleaseDay((Get-Date -Day 1)); + $nextMonthReleaseDate = Get-ReleaseDay((Get-Date -Day 1).AddMonths(1)); + + if ($thisMonthReleaseDate -ge $currentDate) + { + # On track for this month release + $ParsedReleaseDate = $thisMonthReleaseDate + } + elseif ($currentDate.Day -lt 15) + { + # Catching up to this month release + $ParsedReleaseDate = $currentDate + } + else + { + # Next month release + $ParsedReleaseDate = $nextMonthReleaseDate + } +} +else +{ + $ParsedReleaseDate = [datetime]::ParseExact($ReleaseDate, 'yyyy-MM-dd', [Globalization.CultureInfo]::InvariantCulture) +} + +$releaseDateString = $ParsedReleaseDate.ToString("yyyy-MM-dd") +$month = $ParsedReleaseDate.ToString("MMMM") + +Write-Host +Write-Host "Assuming release is in $month with release date $releaseDateString" -ForegroundColor Green + +$isNew = "True"; +$libraryType = "Beta"; +$latestVersion = $null; +foreach ($existingVersion in $existing.versions) +{ + $isNew = "False" + $parsedVersion = [AzureEngSemanticVersion]::new($existingVersion) + if (!$parsedVersion.IsPrerelease) + { + $libraryType = "GA" + } + + $latestVersion = $existingVersion; +} + +$currentProjectVersion = ([xml](Get-Content "$packageDirectory/src/*.csproj")).Project.PropertyGroup.Version +$currentProjectVersion = "$currentProjectVersion".Trim() + +if ($latestVersion) +{ + Write-Host + Write-Host "Latest released version $latestVersion, library type $libraryType" -ForegroundColor Green +} +else +{ + Write-Host + Write-Host "No released version, library type $libraryType" -ForegroundColor Green +} + +$newVersion = Read-Host -Prompt "Input the new version, NA if you are not releasing, or press Enter to use use current project version '$currentProjectVersion'" +$releasing = $true + +if (!$newVersion) +{ + $newVersion = $currentProjectVersion; +} + +if ($newVersion -eq "NA") +{ + $releasing = $false +} + +if ($releasing) +{ + if ($latestVersion) + { + $releaseType = "None"; + $parsedNewVersion = [AzureEngSemanticVersion]::new($newVersion) + if ($parsedNewVersion.Major -ne $parsedVersion.Major) + { + $releaseType = "Major" + } + elseif ($parsedNewVersion.Minor -ne $parsedVersion.Minor) + { + $releaseType = "Minor" + } + elseif ($parsedNewVersion.Patch -ne $parsedVersion.Patch) + { + $releaseType = "Patch" + } + elseif ($parsedNewVersion.IsPrerelease) + { + $releaseType = "Patch" + } + } + else + { + $releaseType = "Major"; + } + + Write-Host + Write-Host "Detected released type $releaseType" -ForegroundColor Green + + Write-Host + Write-Host "Updating versions to $newVersion with date $releaseDateString" -ForegroundColor Green + + & "$repoRoot\eng\scripts\Update-PkgVersion.ps1" -ServiceDirectory $serviceDirectory -PackageName $package -NewVersionString $newVersion -ReleaseDate $releaseDateString + + $fields = @{ + "Permalink usetag"="https://github.com/Azure/azure-sdk-for-net/sdk/$serviceDirectory/$package/README.md" + "Package Registry Permalink"="https://nuget.org/packages/$package/$newVersion" + "Library Type"=$libraryType + "Release Type"=$releaseType + "Version Number"=$newVersion + "Planned Release Date"=$releaseDateString + "New Library Only"=$isNew + } + $state = "Active" +} +else +{ + $fields = @{} + $state = "Not In Release" +} + +$workItems = az boards query @commonParameter --project Release --wiql "SELECT [ID], [State], [Iteration Path], [Title] FROM WorkItems WHERE [State] <> 'Closed' AND [Iteration Path] under 'Release\2020\$month' AND [Title] contains '.NET'" | ConvertFrom-Json; + +Write-Host +Write-Host "The following work items exist:" +foreach ($item in $workItems) +{ + $id = $item.fields."System.ID"; + $title = $item.fields."System.Title"; + $path = $item.fields."System.IterationPath"; + Write-Host "$id - $path - $title" +} + +# Sort using fuzzy match +$workItems = $workItems | Sort-Object -property @{Expression = { Get-LevenshteinDistance $_.fields."System.Title" $package -NormalizeOutput }} +$mostProbable = $workItems | Select-Object -Last 1 + +$issueId = Read-Host -Prompt "Input the work item ID or press Enter to use '$($mostProbable.fields."System.ID") - $($mostProbable.fields."System.Title")' (fuzzy matched based on title)" + +if (!$issueId) +{ + $issueId = $mostProbable.fields."System.ID" +} + +Write-Host +Write-Host "Going to set the following fields:" -ForegroundColor Green +Write-Host " State = $state" + +foreach ($field in $fields.Keys) +{ + Write-Host " $field = $($fields[$field])" +} + +$decision = $Host.UI.PromptForChoice("Updating work item https://dev.azure.com/azure-sdk/Release/_workitems/edit/$issueId", 'Are you sure you want to proceed?', @('&Yes'; '&No'), 0) + +if ($decision -eq 0) +{ + az boards work-item update @commonParameter --id $issueId --state $state > $null + foreach ($field in $fields.Keys) + { + az boards work-item update @commonParameter --id $issueId -f "$field=$($fields[$field])" > $null + } +} From ebfddb6ed45a5aa60807a0b08208313dc862c56e Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Thu, 3 Dec 2020 13:07:21 -0800 Subject: [PATCH 02/10] Generalize Prepare-Release Script --- eng/common/scripts/Prepare-Release.ps1 | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/eng/common/scripts/Prepare-Release.ps1 b/eng/common/scripts/Prepare-Release.ps1 index 712f705b7153..36f09bd3fffa 100644 --- a/eng/common/scripts/Prepare-Release.ps1 +++ b/eng/common/scripts/Prepare-Release.ps1 @@ -4,7 +4,7 @@ param( [Parameter(Mandatory=$true)] [string]$packageName, - [string]$serviceName, + [string]$serviceDirectoryName, [string]$ReleaseDate ) @@ -108,22 +108,20 @@ if (!$?){ throw 'You must have the azure-devops extension run `az extension add --name azure-devops`' } -$packageProperties = Get-PkgProperties -PackageName $package -ServiceDirectory $serviceName -$packageDirectory = Get-ChildItem "$repoRoot/sdk" -Directory -Recurse -Depth 2 -Filter $package -$serviceDirectory = $packageDirectory.Parent.Name +$packageProperties = Get-PkgProperties -PackageName $packageName -ServiceDirectory $serviceDirectoryName -Write-Host "Source directory $serviceDirectory" +Write-Host "Source directory $serviceDirectoryName" -try +if ($GetExistingPackageVersions -and (Test-Path "Function:$GetExistingPackageVersions")) { - $existing = Invoke-WebRequest "https://api.nuget.org/v3-flatcontainer/$($package.ToLower())/index.json" | ConvertFrom-Json; + $existing = &$GetExistingPackageVersions -PackageName $packageProperties.Name -GroupId $packageProperties.Group + if ($null -eq $existing) { $existing = @() } } -catch +else { - $existing = @() + LogError "The function '$GetExistingPackageVersions' was not found." } - if (!$ReleaseDate) { $currentDate = Get-Date @@ -160,7 +158,7 @@ Write-Host "Assuming release is in $month with release date $releaseDateString" $isNew = "True"; $libraryType = "Beta"; $latestVersion = $null; -foreach ($existingVersion in $existing.versions) +foreach ($existingVersion in $existing) { $isNew = "False" $parsedVersion = [AzureEngSemanticVersion]::new($existingVersion) @@ -172,8 +170,7 @@ foreach ($existingVersion in $existing.versions) $latestVersion = $existingVersion; } -$currentProjectVersion = ([xml](Get-Content "$packageDirectory/src/*.csproj")).Project.PropertyGroup.Version -$currentProjectVersion = "$currentProjectVersion".Trim() +$currentProjectVersion = $packageProperties.Version if ($latestVersion) { From 4affd2bf82b38789a790a3076cf3e5778eff31d8 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Fri, 4 Dec 2020 00:18:24 -0800 Subject: [PATCH 03/10] Update Update-ChangeLog.ps1 --- eng/common/scripts/Prepare-Release.ps1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/eng/common/scripts/Prepare-Release.ps1 b/eng/common/scripts/Prepare-Release.ps1 index 36f09bd3fffa..6469ab69a931 100644 --- a/eng/common/scripts/Prepare-Release.ps1 +++ b/eng/common/scripts/Prepare-Release.ps1 @@ -5,7 +5,8 @@ param( [Parameter(Mandatory=$true)] [string]$packageName, [string]$serviceDirectoryName, - [string]$ReleaseDate + [string]$ReleaseDate, + [string]$BuildType # For Java ) . ${PSScriptRoot}\common.ps1 @@ -230,7 +231,8 @@ if ($releasing) Write-Host Write-Host "Updating versions to $newVersion with date $releaseDateString" -ForegroundColor Green - & "$repoRoot\eng\scripts\Update-PkgVersion.ps1" -ServiceDirectory $serviceDirectory -PackageName $package -NewVersionString $newVersion -ReleaseDate $releaseDateString + SetPackageVersion -PackageName $package -Version $newVersion -ServiceName $serviceDirectory -ReleaseDate $releaseDateString ` + -BuildType $BuildType $GroupName $packageProperties.Group $fields = @{ "Permalink usetag"="https://github.com/Azure/azure-sdk-for-net/sdk/$serviceDirectory/$package/README.md" From da0589cda6f7e454b22b74d9f8b458c422aba7c0 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Mon, 7 Dec 2020 13:00:01 -0800 Subject: [PATCH 04/10] Update Package-Properties.ps1 --- eng/common/scripts/Package-Properties.ps1 | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/eng/common/scripts/Package-Properties.ps1 b/eng/common/scripts/Package-Properties.ps1 index be1d3f5288dc..d3e78b58f1f6 100644 --- a/eng/common/scripts/Package-Properties.ps1 +++ b/eng/common/scripts/Package-Properties.ps1 @@ -84,7 +84,7 @@ function Get-PkgProperties if (!(Test-Path $serviceDirectoryPath)) { LogError "Service Directory $ServiceDirectory does not exist" - exit 1 + return $null } $directoriesPresent = Get-ChildItem $serviceDirectoryPath -Directory @@ -110,6 +110,7 @@ function Get-PkgProperties } } LogError "Failed to retrive Properties for $PackageName" + return $null } # Takes ServiceName and Repo Root Directory @@ -156,8 +157,12 @@ function Operate-OnPackages ($activePkgList, $ServiceDirectory, [Array]$pkgProps { foreach ($pkg in $activePkgList) { + Log-Debug "Operating on $($pkg["name"])" $pkgProps = Get-PkgProperties -PackageName $pkg["name"] -ServiceDirectory $ServiceDirectory - $pkgPropsResult += $pkgProps + if ($null -ne $pkgProps) + { + $pkgPropsResult += $pkgProps + } } return $pkgPropsResult } @@ -165,8 +170,16 @@ function Operate-OnPackages ($activePkgList, $ServiceDirectory, [Array]$pkgProps function Get-PkgListFromYml ($ciYmlPath) { $ProgressPreference = "SilentlyContinue" - Register-PSRepository -Default -ErrorAction:SilentlyContinue - Install-Module -Name powershell-yaml -RequiredVersion 0.4.1 -Force -Scope CurrentUser + if ((Get-PSRepository | ?{$_.Name -eq "PSGallery"}).Count -eq 0) + { + Register-PSRepository -Default -ErrorAction:SilentlyContinue + } + + if ((Get-Module -ListAvailable -Name powershell-yaml | ?{$_.Version -eq "0.4.2"}).Count -eq 0) + { + Install-Module -Name powershell-yaml -RequiredVersion 0.4.2 -Force -Scope CurrentUser + } + $ciYmlContent = Get-Content $ciYmlPath -Raw $ciYmlObj = ConvertFrom-Yaml $ciYmlContent -Ordered if ($ciYmlObj.Contains("stages")) From cf42e4a5d2e130718d873a6ebdea92d8485a86cd Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Mon, 7 Dec 2020 13:59:02 -0800 Subject: [PATCH 05/10] Update Collect-ChangeLog Script --- eng/common/scripts/Collect-ChangeLogs.ps1 | 45 +++++++++++++++++++++++ eng/common/scripts/Collect-Unreleased.ps1 | 36 ++++++++++++++++++ eng/common/scripts/Package-Properties.ps1 | 2 +- 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 eng/common/scripts/Collect-ChangeLogs.ps1 create mode 100644 eng/common/scripts/Collect-Unreleased.ps1 diff --git a/eng/common/scripts/Collect-ChangeLogs.ps1 b/eng/common/scripts/Collect-ChangeLogs.ps1 new file mode 100644 index 000000000000..4f36f99da5ac --- /dev/null +++ b/eng/common/scripts/Collect-ChangeLogs.ps1 @@ -0,0 +1,45 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory=$true)] + [ValidateRange(1, 12)] + [int] $Month +) + +. (Join-Path $PSScriptRoot common.ps1) + +$InstallNotes = ""; +$ReleaseNotes = ""; + +$date = Get-Date -Month $month -Format "yyyy-MM" +$date += "-\d\d" + +$allPackageProps = Get-AllPkgProperties + +foreach ($packageProp in $allPackageProps) { + $changeLogEntries = Get-ChangeLogEntries -ChangeLogLocation $packageProp.ChangeLogPath + $package = $packageProp.Name + $serviceDirectory = $packageProp.ServiceDirectory + + foreach ($changeLogEntry in $changeLogEntries.Values) { + if ($changeLogEntry.ReleaseStatus -notmatch $date) + { + continue; + } + + $version = $changeLogEntry.ReleaseVersion + $githubAnchor = $changeLogEntry.ReleaseTitle.Replace("## ", "").Replace(".", "").Replace("(", "").Replace(")", "").Replace(" ", "-") + $textInfo = (Get-Culture).TextInfo + $highlightTitle = $textInfo.ToTitleCase($package.Replace("-", " ").Replace("@azure/","")) + + $InstallNotes += GetPackageInstallNotes -Package $package -Version $version + $ReleaseNotes += "### $highlightTitle $version [Changelog](https://github.com/Azure/azure-sdk-for-$LanguageShort/blob/master/sdk/$serviceDirectory/$package/CHANGELOG.md#$githubAnchor)`n" + $changeLogEntry.ReleaseContent | %{ + + $ReleaseNotes += $_.Replace("###", "####") + $ReleaseNotes += "`n" + } + $ReleaseNotes += "`n" + } +} + +return $InstallNotes, $ReleaseNotes \ No newline at end of file diff --git a/eng/common/scripts/Collect-Unreleased.ps1 b/eng/common/scripts/Collect-Unreleased.ps1 new file mode 100644 index 000000000000..35a6541d0d16 --- /dev/null +++ b/eng/common/scripts/Collect-Unreleased.ps1 @@ -0,0 +1,36 @@ +[CmdletBinding()] +param() + +$repoRoot = Resolve-Path "$PSScriptRoot/../.."; +. ${repoRoot}\eng\common\scripts\SemVer.ps1 +. ${repoRoot}\eng\common\scripts\ChangeLog-Operations.ps1 + + +Get-ChildItem "$repoRoot/sdk" -Filter CHANGELOG.md -Recurse | Sort-Object -Property Name | % { + + $changeLogEntries = Get-ChangeLogEntries -ChangeLogLocation $_ + $package = $_.Directory.Name + $serviceDirectory = $_.Directory.Parent.Name + + foreach ($changeLogEntry in $changeLogEntries.Values) + { + if ($changeLogEntry.ReleaseStatus -eq "(Unreleased)") + { + $matters = "" + $changeLogEntry.ReleaseContent | %{ + if ($_ -notmatch "^((#+.*)|(\s*)|(.*N\/A.*))`$") + { + $matters += "$_`r`n" + } + } + + if ($matters.Length -gt 0) + { + Write-Host $package -Foreground Green + Write-Verbose $matters + + break; + } + } + } +} diff --git a/eng/common/scripts/Package-Properties.ps1 b/eng/common/scripts/Package-Properties.ps1 index d3e78b58f1f6..f8607bcf728b 100644 --- a/eng/common/scripts/Package-Properties.ps1 +++ b/eng/common/scripts/Package-Properties.ps1 @@ -157,7 +157,7 @@ function Operate-OnPackages ($activePkgList, $ServiceDirectory, [Array]$pkgProps { foreach ($pkg in $activePkgList) { - Log-Debug "Operating on $($pkg["name"])" + LogDebug "Operating on $($pkg["name"])" $pkgProps = Get-PkgProperties -PackageName $pkg["name"] -ServiceDirectory $ServiceDirectory if ($null -ne $pkgProps) { From f70c9592017639fc7ca38f702ce34f8155bd23e4 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Tue, 8 Dec 2020 11:33:25 -0800 Subject: [PATCH 06/10] Update Collect-ChangeLog.ps1 and Collect-Unreleased.ps1 --- eng/common/scripts/Collect-ChangeLogs.ps1 | 11 +- eng/common/scripts/Collect-Unreleased.ps1 | 14 +- eng/common/scripts/Prepare-Release.ps1 | 281 +++++++++++----------- 3 files changed, 161 insertions(+), 145 deletions(-) diff --git a/eng/common/scripts/Collect-ChangeLogs.ps1 b/eng/common/scripts/Collect-ChangeLogs.ps1 index 4f36f99da5ac..642d1274dd9d 100644 --- a/eng/common/scripts/Collect-ChangeLogs.ps1 +++ b/eng/common/scripts/Collect-ChangeLogs.ps1 @@ -31,7 +31,16 @@ foreach ($packageProp in $allPackageProps) { $textInfo = (Get-Culture).TextInfo $highlightTitle = $textInfo.ToTitleCase($package.Replace("-", " ").Replace("@azure/","")) - $InstallNotes += GetPackageInstallNotes -Package $package -Version $version + if (Test-Path "Function:GetPackageInstallNotes") + { + $InstallNotes += GetPackageInstallNotes -Package $package -Version $version + } + else + { + LogError "The function 'GetPackageInstallNotes' was not found." + return $null + } + $ReleaseNotes += "### $highlightTitle $version [Changelog](https://github.com/Azure/azure-sdk-for-$LanguageShort/blob/master/sdk/$serviceDirectory/$package/CHANGELOG.md#$githubAnchor)`n" $changeLogEntry.ReleaseContent | %{ diff --git a/eng/common/scripts/Collect-Unreleased.ps1 b/eng/common/scripts/Collect-Unreleased.ps1 index 35a6541d0d16..f011ab24ad29 100644 --- a/eng/common/scripts/Collect-Unreleased.ps1 +++ b/eng/common/scripts/Collect-Unreleased.ps1 @@ -1,16 +1,14 @@ [CmdletBinding()] param() -$repoRoot = Resolve-Path "$PSScriptRoot/../.."; -. ${repoRoot}\eng\common\scripts\SemVer.ps1 -. ${repoRoot}\eng\common\scripts\ChangeLog-Operations.ps1 +. (Join-Path $PSScriptRoot common.ps1) +$allPackageProps = Get-AllPkgProperties -Get-ChildItem "$repoRoot/sdk" -Filter CHANGELOG.md -Recurse | Sort-Object -Property Name | % { - - $changeLogEntries = Get-ChangeLogEntries -ChangeLogLocation $_ - $package = $_.Directory.Name - $serviceDirectory = $_.Directory.Parent.Name +foreach ($packageProp in $allPackageProps) { + $changeLogEntries = Get-ChangeLogEntries -ChangeLogLocation $packageProp.ChangeLogPath + $package = $packageProp.Name + $serviceDirectory = $packageProp.ServiceDirectory foreach ($changeLogEntry in $changeLogEntries.Values) { diff --git a/eng/common/scripts/Prepare-Release.ps1 b/eng/common/scripts/Prepare-Release.ps1 index 6469ab69a931..73fcf1b197ec 100644 --- a/eng/common/scripts/Prepare-Release.ps1 +++ b/eng/common/scripts/Prepare-Release.ps1 @@ -11,75 +11,75 @@ param( . ${PSScriptRoot}\common.ps1 -function Get-LevenshteinDistance { - <# - .SYNOPSIS - Get the Levenshtein distance between two strings. - .DESCRIPTION - The Levenshtein Distance is a way of quantifying how dissimilar two strings (e.g., words) are to one another by counting the minimum number of operations required to transform one string into the other. - .EXAMPLE - Get-LevenshteinDistance 'kitten' 'sitting' - .LINK - http://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance#C.23 - http://en.wikipedia.org/wiki/Edit_distance - https://communary.wordpress.com/ - https://github.com/gravejester/Communary.PASM - .NOTES - Author: Øyvind Kallstad - Date: 07.11.2014 - Version: 1.0 - #> - [CmdletBinding()] - param( - [Parameter(Position = 0)] - [string]$String1, - - [Parameter(Position = 1)] - [string]$String2, - - # Makes matches case-sensitive. By default, matches are not case-sensitive. - [Parameter()] - [switch] $CaseSensitive, - - # A normalized output will fall in the range 0 (perfect match) to 1 (no match). - [Parameter()] - [switch] $NormalizeOutput - ) - - if (-not($CaseSensitive)) { - $String1 = $String1.ToLowerInvariant() - $String2 = $String2.ToLowerInvariant() - } - - $d = New-Object 'Int[,]' ($String1.Length + 1), ($String2.Length + 1) - for ($i = 0; $i -le $d.GetUpperBound(0); $i++) { - $d[$i,0] = $i - } - - for ($i = 0; $i -le $d.GetUpperBound(1); $i++) { - $d[0,$i] = $i - } - - for ($i = 1; $i -le $d.GetUpperBound(0); $i++) { - for ($j = 1; $j -le $d.GetUpperBound(1); $j++) { - $cost = [Convert]::ToInt32((-not($String1[$i-1] -ceq $String2[$j-1]))) - $min1 = $d[($i-1),$j] + 1 - $min2 = $d[$i,($j-1)] + 1 - $min3 = $d[($i-1),($j-1)] + $cost - $d[$i,$j] = [Math]::Min([Math]::Min($min1,$min2),$min3) - } - } - - $distance = ($d[$d.GetUpperBound(0),$d.GetUpperBound(1)]) - - if ($NormalizeOutput) { - return (1 - ($distance) / ([Math]::Max($String1.Length,$String2.Length))) - } - - else { - return $distance - } -} +#function Get-LevenshteinDistance { +# <# +# .SYNOPSIS +# Get the Levenshtein distance between two strings. +# .DESCRIPTION +# The Levenshtein Distance is a way of quantifying how dissimilar two strings (e.g., words) are to one another by counting the minimum number of operations required to transform one string into the other. +# .EXAMPLE +# Get-LevenshteinDistance 'kitten' 'sitting' +# .LINK +# http://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance#C.23 +# http://en.wikipedia.org/wiki/Edit_distance +# https://communary.wordpress.com/ +# https://github.com/gravejester/Communary.PASM +# .NOTES +# Author: Øyvind Kallstad +# Date: 07.11.2014 +# Version: 1.0 +# #> +# [CmdletBinding()] +# param( +# [Parameter(Position = 0)] +# [string]$String1, +# +# [Parameter(Position = 1)] +# [string]$String2, +# +# # Makes matches case-sensitive. By default, matches are not case-sensitive. +# [Parameter()] +# [switch] $CaseSensitive, +# +# # A normalized output will fall in the range 0 (perfect match) to 1 (no match). +# [Parameter()] +# [switch] $NormalizeOutput +# ) +# +# if (-not($CaseSensitive)) { +# $String1 = $String1.ToLowerInvariant() +# $String2 = $String2.ToLowerInvariant() +# } +# +# $d = New-Object 'Int[,]' ($String1.Length + 1), ($String2.Length + 1) +# for ($i = 0; $i -le $d.GetUpperBound(0); $i++) { +# $d[$i,0] = $i +# } +# +# for ($i = 0; $i -le $d.GetUpperBound(1); $i++) { +# $d[0,$i] = $i +# } +# +# for ($i = 1; $i -le $d.GetUpperBound(0); $i++) { +# for ($j = 1; $j -le $d.GetUpperBound(1); $j++) { +# $cost = [Convert]::ToInt32((-not($String1[$i-1] -ceq $String2[$j-1]))) +# $min1 = $d[($i-1),$j] + 1 +# $min2 = $d[$i,($j-1)] + 1 +# $min3 = $d[($i-1),($j-1)] + $cost +# $d[$i,$j] = [Math]::Min([Math]::Min($min1,$min2),$min3) +# } +# } +# +# $distance = ($d[$d.GetUpperBound(0),$d.GetUpperBound(1)]) +# +# if ($NormalizeOutput) { +# return (1 - ($distance) / ([Math]::Max($String1.Length,$String2.Length))) +# } +# +# else { +# return $distance +# } +#} function Get-ReleaseDay($baseDate) { @@ -97,30 +97,31 @@ function Get-ReleaseDay($baseDate) $ErrorPreference = 'Stop' $repoRoot = Resolve-Path "$PSScriptRoot/../.."; -$commonParameter = @("--organization", "https://dev.azure.com/azure-sdk", "-o", "json", "--only-show-errors") - -if (!(Get-Command az)) { - throw 'You must have the Azure CLI installed: https://aka.ms/azure-cli' -} - -az extension show -n azure-devops > $null - -if (!$?){ - throw 'You must have the azure-devops extension run `az extension add --name azure-devops`' -} +#$commonParameter = @("--organization", "https://dev.azure.com/azure-sdk", "-o", "json", "--only-show-errors") + +#if (!(Get-Command az)) { +# throw 'You must have the Azure CLI installed: https://aka.ms/azure-cli' +#} +# +#az extension show -n azure-devops > $null +# +#if (!$?){ +# throw 'You must have the azure-devops extension run `az extension add --name azure-devops`' +#} $packageProperties = Get-PkgProperties -PackageName $packageName -ServiceDirectory $serviceDirectoryName Write-Host "Source directory $serviceDirectoryName" -if ($GetExistingPackageVersions -and (Test-Path "Function:$GetExistingPackageVersions")) +if (Test-Path "Function:GetExistingPackageVersions") { - $existing = &$GetExistingPackageVersions -PackageName $packageProperties.Name -GroupId $packageProperties.Group + $existing = GetExistingPackageVersions -PackageName $packageProperties.Name -GroupId $packageProperties.Group if ($null -eq $existing) { $existing = @() } } else { - LogError "The function '$GetExistingPackageVersions' was not found." + LogError "The function 'GetExistingPackageVersions' was not found." + return $null } if (!$ReleaseDate) @@ -231,65 +232,73 @@ if ($releasing) Write-Host Write-Host "Updating versions to $newVersion with date $releaseDateString" -ForegroundColor Green - SetPackageVersion -PackageName $package -Version $newVersion -ServiceName $serviceDirectory -ReleaseDate $releaseDateString ` - -BuildType $BuildType $GroupName $packageProperties.Group - - $fields = @{ - "Permalink usetag"="https://github.com/Azure/azure-sdk-for-net/sdk/$serviceDirectory/$package/README.md" - "Package Registry Permalink"="https://nuget.org/packages/$package/$newVersion" - "Library Type"=$libraryType - "Release Type"=$releaseType - "Version Number"=$newVersion - "Planned Release Date"=$releaseDateString - "New Library Only"=$isNew + if (Test-Path "Function:SetPackageVersion") + { + SetPackageVersion -PackageName $package -Version $newVersion -ServiceName $serviceDirectory -ReleaseDate $releaseDateString ` + -BuildType $BuildType $GroupName $packageProperties.Group + } + else + { + LogError "The function 'SetPackageVersion' was not found." + return $null } - $state = "Active" + +# $fields = @{ +# "Permalink usetag"="https://github.com/Azure/azure-sdk-for-net/sdk/$serviceDirectory/$package/README.md" +# "Package Registry Permalink"="https://nuget.org/packages/$package/$newVersion" +# "Library Type"=$libraryType +# "Release Type"=$releaseType +# "Version Number"=$newVersion +# "Planned Release Date"=$releaseDateString +# "New Library Only"=$isNew +# } +# $state = "Active" } else { - $fields = @{} - $state = "Not In Release" +# $fields = @{} +# $state = "Not In Release" } -$workItems = az boards query @commonParameter --project Release --wiql "SELECT [ID], [State], [Iteration Path], [Title] FROM WorkItems WHERE [State] <> 'Closed' AND [Iteration Path] under 'Release\2020\$month' AND [Title] contains '.NET'" | ConvertFrom-Json; +#$workItems = az boards query @commonParameter --project Release --wiql "SELECT [ID], [State], [Iteration Path], [Title] FROM WorkItems WHERE [State] <> 'Closed' AND [Iteration Path] under 'Release\2020\$month' AND [Title] contains '.NET'" | ConvertFrom-Json; -Write-Host -Write-Host "The following work items exist:" -foreach ($item in $workItems) -{ - $id = $item.fields."System.ID"; - $title = $item.fields."System.Title"; - $path = $item.fields."System.IterationPath"; - Write-Host "$id - $path - $title" -} +#Write-Host +#Write-Host "The following work items exist:" +#foreach ($item in $workItems) +#{ +# $id = $item.fields."System.ID"; +# $title = $item.fields."System.Title"; +# $path = $item.fields."System.IterationPath"; +# Write-Host "$id - $path - $title" +#} # Sort using fuzzy match -$workItems = $workItems | Sort-Object -property @{Expression = { Get-LevenshteinDistance $_.fields."System.Title" $package -NormalizeOutput }} -$mostProbable = $workItems | Select-Object -Last 1 - -$issueId = Read-Host -Prompt "Input the work item ID or press Enter to use '$($mostProbable.fields."System.ID") - $($mostProbable.fields."System.Title")' (fuzzy matched based on title)" - -if (!$issueId) -{ - $issueId = $mostProbable.fields."System.ID" -} - -Write-Host -Write-Host "Going to set the following fields:" -ForegroundColor Green -Write-Host " State = $state" - -foreach ($field in $fields.Keys) -{ - Write-Host " $field = $($fields[$field])" -} - -$decision = $Host.UI.PromptForChoice("Updating work item https://dev.azure.com/azure-sdk/Release/_workitems/edit/$issueId", 'Are you sure you want to proceed?', @('&Yes'; '&No'), 0) - -if ($decision -eq 0) -{ - az boards work-item update @commonParameter --id $issueId --state $state > $null - foreach ($field in $fields.Keys) - { - az boards work-item update @commonParameter --id $issueId -f "$field=$($fields[$field])" > $null - } -} +#$workItems = $workItems | Sort-Object -property @{Expression = { Get-LevenshteinDistance $_.fields."System.Title" $package -NormalizeOutput }} +#$mostProbable = $workItems | Select-Object -Last 1 + +#$issueId = Read-Host -Prompt "Input the work item ID or press Enter to use '$($mostProbable.fields."System.ID") - $($mostProbable.fields."System.Title")' (fuzzy matched based on title)" + +#if (!$issueId) +#{ +# $issueId = $mostProbable.fields."System.ID" +#} +# +#Write-Host +#Write-Host "Going to set the following fields:" -ForegroundColor Green +#Write-Host " State = $state" +# +#foreach ($field in $fields.Keys) +#{ +# Write-Host " $field = $($fields[$field])" +#} + +#$decision = $Host.UI.PromptForChoice("Updating work item https://dev.azure.com/azure-sdk/Release/_workitems/edit/$issueId", 'Are you sure you want to proceed?', @('&Yes'; '&No'), 0) + +#if ($decision -eq 0) +#{ +# az boards work-item update @commonParameter --id $issueId --state $state > $null +# foreach ($field in $fields.Keys) +# { +# az boards work-item update @commonParameter --id $issueId -f "$field=$($fields[$field])" > $null +# } +#} From 3c791d1371536f35df9ae99bfae6ccbd4cfb347b Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Thu, 10 Dec 2020 16:40:23 -0800 Subject: [PATCH 07/10] Update GeneralReleaseNotesParser.ps1 script --- eng/common/scripts/Collect-ChangeLogs.ps1 | 54 ----------------------- eng/common/scripts/Collect-Unreleased.ps1 | 34 -------------- 2 files changed, 88 deletions(-) delete mode 100644 eng/common/scripts/Collect-ChangeLogs.ps1 delete mode 100644 eng/common/scripts/Collect-Unreleased.ps1 diff --git a/eng/common/scripts/Collect-ChangeLogs.ps1 b/eng/common/scripts/Collect-ChangeLogs.ps1 deleted file mode 100644 index 642d1274dd9d..000000000000 --- a/eng/common/scripts/Collect-ChangeLogs.ps1 +++ /dev/null @@ -1,54 +0,0 @@ -[CmdletBinding()] -param( - [Parameter(Mandatory=$true)] - [ValidateRange(1, 12)] - [int] $Month -) - -. (Join-Path $PSScriptRoot common.ps1) - -$InstallNotes = ""; -$ReleaseNotes = ""; - -$date = Get-Date -Month $month -Format "yyyy-MM" -$date += "-\d\d" - -$allPackageProps = Get-AllPkgProperties - -foreach ($packageProp in $allPackageProps) { - $changeLogEntries = Get-ChangeLogEntries -ChangeLogLocation $packageProp.ChangeLogPath - $package = $packageProp.Name - $serviceDirectory = $packageProp.ServiceDirectory - - foreach ($changeLogEntry in $changeLogEntries.Values) { - if ($changeLogEntry.ReleaseStatus -notmatch $date) - { - continue; - } - - $version = $changeLogEntry.ReleaseVersion - $githubAnchor = $changeLogEntry.ReleaseTitle.Replace("## ", "").Replace(".", "").Replace("(", "").Replace(")", "").Replace(" ", "-") - $textInfo = (Get-Culture).TextInfo - $highlightTitle = $textInfo.ToTitleCase($package.Replace("-", " ").Replace("@azure/","")) - - if (Test-Path "Function:GetPackageInstallNotes") - { - $InstallNotes += GetPackageInstallNotes -Package $package -Version $version - } - else - { - LogError "The function 'GetPackageInstallNotes' was not found." - return $null - } - - $ReleaseNotes += "### $highlightTitle $version [Changelog](https://github.com/Azure/azure-sdk-for-$LanguageShort/blob/master/sdk/$serviceDirectory/$package/CHANGELOG.md#$githubAnchor)`n" - $changeLogEntry.ReleaseContent | %{ - - $ReleaseNotes += $_.Replace("###", "####") - $ReleaseNotes += "`n" - } - $ReleaseNotes += "`n" - } -} - -return $InstallNotes, $ReleaseNotes \ No newline at end of file diff --git a/eng/common/scripts/Collect-Unreleased.ps1 b/eng/common/scripts/Collect-Unreleased.ps1 deleted file mode 100644 index f011ab24ad29..000000000000 --- a/eng/common/scripts/Collect-Unreleased.ps1 +++ /dev/null @@ -1,34 +0,0 @@ -[CmdletBinding()] -param() - -. (Join-Path $PSScriptRoot common.ps1) - -$allPackageProps = Get-AllPkgProperties - -foreach ($packageProp in $allPackageProps) { - $changeLogEntries = Get-ChangeLogEntries -ChangeLogLocation $packageProp.ChangeLogPath - $package = $packageProp.Name - $serviceDirectory = $packageProp.ServiceDirectory - - foreach ($changeLogEntry in $changeLogEntries.Values) - { - if ($changeLogEntry.ReleaseStatus -eq "(Unreleased)") - { - $matters = "" - $changeLogEntry.ReleaseContent | %{ - if ($_ -notmatch "^((#+.*)|(\s*)|(.*N\/A.*))`$") - { - $matters += "$_`r`n" - } - } - - if ($matters.Length -gt 0) - { - Write-Host $package -Foreground Green - Write-Verbose $matters - - break; - } - } - } -} From d4a864e2e7bcaac05dd7f4f706ef931aed317d9e Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Mon, 11 Jan 2021 17:35:15 -0800 Subject: [PATCH 08/10] Update Prepare-Release Script to use recent DevOps Scripts --- eng/common/scripts/Prepare-Release.ps1 | 275 +++++-------------------- 1 file changed, 46 insertions(+), 229 deletions(-) diff --git a/eng/common/scripts/Prepare-Release.ps1 b/eng/common/scripts/Prepare-Release.ps1 index 73fcf1b197ec..582f9b536ae7 100644 --- a/eng/common/scripts/Prepare-Release.ps1 +++ b/eng/common/scripts/Prepare-Release.ps1 @@ -3,84 +3,21 @@ [CmdletBinding()] param( [Parameter(Mandatory=$true)] - [string]$packageName, - [string]$serviceDirectoryName, - [string]$ReleaseDate, + [string]$PackageName, + [string]$ServiceDirectory, + [string]$ReleaseDate, # Pass Date in the form MM/dd/yyyy" [string]$BuildType # For Java ) . ${PSScriptRoot}\common.ps1 - -#function Get-LevenshteinDistance { -# <# -# .SYNOPSIS -# Get the Levenshtein distance between two strings. -# .DESCRIPTION -# The Levenshtein Distance is a way of quantifying how dissimilar two strings (e.g., words) are to one another by counting the minimum number of operations required to transform one string into the other. -# .EXAMPLE -# Get-LevenshteinDistance 'kitten' 'sitting' -# .LINK -# http://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance#C.23 -# http://en.wikipedia.org/wiki/Edit_distance -# https://communary.wordpress.com/ -# https://github.com/gravejester/Communary.PASM -# .NOTES -# Author: Øyvind Kallstad -# Date: 07.11.2014 -# Version: 1.0 -# #> -# [CmdletBinding()] -# param( -# [Parameter(Position = 0)] -# [string]$String1, -# -# [Parameter(Position = 1)] -# [string]$String2, -# -# # Makes matches case-sensitive. By default, matches are not case-sensitive. -# [Parameter()] -# [switch] $CaseSensitive, -# -# # A normalized output will fall in the range 0 (perfect match) to 1 (no match). -# [Parameter()] -# [switch] $NormalizeOutput -# ) -# -# if (-not($CaseSensitive)) { -# $String1 = $String1.ToLowerInvariant() -# $String2 = $String2.ToLowerInvariant() -# } -# -# $d = New-Object 'Int[,]' ($String1.Length + 1), ($String2.Length + 1) -# for ($i = 0; $i -le $d.GetUpperBound(0); $i++) { -# $d[$i,0] = $i -# } -# -# for ($i = 0; $i -le $d.GetUpperBound(1); $i++) { -# $d[0,$i] = $i -# } -# -# for ($i = 1; $i -le $d.GetUpperBound(0); $i++) { -# for ($j = 1; $j -le $d.GetUpperBound(1); $j++) { -# $cost = [Convert]::ToInt32((-not($String1[$i-1] -ceq $String2[$j-1]))) -# $min1 = $d[($i-1),$j] + 1 -# $min2 = $d[$i,($j-1)] + 1 -# $min3 = $d[($i-1),($j-1)] + $cost -# $d[$i,$j] = [Math]::Min([Math]::Min($min1,$min2),$min3) -# } -# } -# -# $distance = ($d[$d.GetUpperBound(0),$d.GetUpperBound(1)]) -# -# if ($NormalizeOutput) { -# return (1 - ($distance) / ([Math]::Max($String1.Length,$String2.Length))) -# } -# -# else { -# return $distance -# } -#} - +function Get-LanguageName($lang) +{ + $pkgLang = $languageNameMapping[$lang] + if (!$pkgLang) { + $pkgLang = $lang + } + return $pkgLang +} function Get-ReleaseDay($baseDate) { # Find first friday @@ -95,41 +32,26 @@ function Get-ReleaseDay($baseDate) return $baseDate; } -$ErrorPreference = 'Stop' -$repoRoot = Resolve-Path "$PSScriptRoot/../.."; -#$commonParameter = @("--organization", "https://dev.azure.com/azure-sdk", "-o", "json", "--only-show-errors") - -#if (!(Get-Command az)) { -# throw 'You must have the Azure CLI installed: https://aka.ms/azure-cli' -#} -# -#az extension show -n azure-devops > $null -# -#if (!$?){ -# throw 'You must have the azure-devops extension run `az extension add --name azure-devops`' -#} +$languageNameMapping = @{ + cpp = "C++" + dotnet = ".NET" + java = "Java" + js = "JavaScript" + python = "Python" +} -$packageProperties = Get-PkgProperties -PackageName $packageName -ServiceDirectory $serviceDirectoryName +$ErrorPreference = 'Stop' -Write-Host "Source directory $serviceDirectoryName" +$packageProperties = Get-PkgProperties -PackageName $PackageName -ServiceDirectory $serviceDirectory -if (Test-Path "Function:GetExistingPackageVersions") -{ - $existing = GetExistingPackageVersions -PackageName $packageProperties.Name -GroupId $packageProperties.Group - if ($null -eq $existing) { $existing = @() } -} -else -{ - LogError "The function 'GetExistingPackageVersions' was not found." - return $null -} +Write-Host "Source directory [ $serviceDirectory ]" if (!$ReleaseDate) { $currentDate = Get-Date $thisMonthReleaseDate = Get-ReleaseDay((Get-Date -Day 1)); $nextMonthReleaseDate = Get-ReleaseDay((Get-Date -Day 1).AddMonths(1)); - + if ($thisMonthReleaseDate -ge $currentDate) { # On track for this month release @@ -148,157 +70,52 @@ if (!$ReleaseDate) } else { - $ParsedReleaseDate = [datetime]::ParseExact($ReleaseDate, 'yyyy-MM-dd', [Globalization.CultureInfo]::InvariantCulture) + $ParsedReleaseDate = ([datetime]$ReleaseDate, 'MM/dd/yyyy', [Globalization.CultureInfo]::InvariantCulture) } -$releaseDateString = $ParsedReleaseDate.ToString("yyyy-MM-dd") +$releaseDateString = $ParsedReleaseDate.ToString("MM/dd/yyyy") $month = $ParsedReleaseDate.ToString("MMMM") Write-Host Write-Host "Assuming release is in $month with release date $releaseDateString" -ForegroundColor Green -$isNew = "True"; -$libraryType = "Beta"; -$latestVersion = $null; -foreach ($existingVersion in $existing) -{ - $isNew = "False" - $parsedVersion = [AzureEngSemanticVersion]::new($existingVersion) - if (!$parsedVersion.IsPrerelease) - { - $libraryType = "GA" - } - - $latestVersion = $existingVersion; -} - $currentProjectVersion = $packageProperties.Version -if ($latestVersion) -{ - Write-Host - Write-Host "Latest released version $latestVersion, library type $libraryType" -ForegroundColor Green -} -else -{ - Write-Host - Write-Host "No released version, library type $libraryType" -ForegroundColor Green -} - -$newVersion = Read-Host -Prompt "Input the new version, NA if you are not releasing, or press Enter to use use current project version '$currentProjectVersion'" -$releasing = $true +$newVersion = Read-Host -Prompt "Input the new version, or press Enter to use use current project version '$currentProjectVersion'" if (!$newVersion) { $newVersion = $currentProjectVersion; } -if ($newVersion -eq "NA") +$newVersionParsed = [AzureEngSemanticVersion]::ParseVersionString($newVersion) +if ($null -eq $newVersionParsed) { - $releasing = $false + Write-Error "Invalid version $newVersion. Please try agaiin with a valid version." + exit 1 } -if ($releasing) -{ - if ($latestVersion) - { - $releaseType = "None"; - $parsedNewVersion = [AzureEngSemanticVersion]::new($newVersion) - if ($parsedNewVersion.Major -ne $parsedVersion.Major) - { - $releaseType = "Major" - } - elseif ($parsedNewVersion.Minor -ne $parsedVersion.Minor) - { - $releaseType = "Minor" - } - elseif ($parsedNewVersion.Patch -ne $parsedVersion.Patch) - { - $releaseType = "Patch" - } - elseif ($parsedNewVersion.IsPrerelease) - { - $releaseType = "Patch" - } - } - else - { - $releaseType = "Major"; - } - - Write-Host - Write-Host "Detected released type $releaseType" -ForegroundColor Green - - Write-Host - Write-Host "Updating versions to $newVersion with date $releaseDateString" -ForegroundColor Green +Write-Host +Write-Host "Detected released type [ $($newVersionParsed.VersionType) ]" -ForegroundColor Green - if (Test-Path "Function:SetPackageVersion") - { - SetPackageVersion -PackageName $package -Version $newVersion -ServiceName $serviceDirectory -ReleaseDate $releaseDateString ` - -BuildType $BuildType $GroupName $packageProperties.Group - } - else - { - LogError "The function 'SetPackageVersion' was not found." - return $null - } +Write-Host +Write-Host "Updating versions to [ $newVersion ] with date [ $releaseDateString ]" -ForegroundColor Green -# $fields = @{ -# "Permalink usetag"="https://github.com/Azure/azure-sdk-for-net/sdk/$serviceDirectory/$package/README.md" -# "Package Registry Permalink"="https://nuget.org/packages/$package/$newVersion" -# "Library Type"=$libraryType -# "Release Type"=$releaseType -# "Version Number"=$newVersion -# "Planned Release Date"=$releaseDateString -# "New Library Only"=$isNew -# } -# $state = "Active" +if (Test-Path "Function:SetPackageVersion") +{ + SetPackageVersion -PackageName $PackageName -Version $newVersion -ServiceDirectory $serviceDirectory -ReleaseDate $releaseDateString ` + -BuildType $BuildType -GroupId $packageProperties.Group } else { -# $fields = @{} -# $state = "Not In Release" + LogError "The function 'SetPackageVersion' was not found.` + Make sure it is present in eng/scripts/Language-Settings.ps1" + exit 1 } -#$workItems = az boards query @commonParameter --project Release --wiql "SELECT [ID], [State], [Iteration Path], [Title] FROM WorkItems WHERE [State] <> 'Closed' AND [Iteration Path] under 'Release\2020\$month' AND [Title] contains '.NET'" | ConvertFrom-Json; - -#Write-Host -#Write-Host "The following work items exist:" -#foreach ($item in $workItems) -#{ -# $id = $item.fields."System.ID"; -# $title = $item.fields."System.Title"; -# $path = $item.fields."System.IterationPath"; -# Write-Host "$id - $path - $title" -#} - -# Sort using fuzzy match -#$workItems = $workItems | Sort-Object -property @{Expression = { Get-LevenshteinDistance $_.fields."System.Title" $package -NormalizeOutput }} -#$mostProbable = $workItems | Select-Object -Last 1 - -#$issueId = Read-Host -Prompt "Input the work item ID or press Enter to use '$($mostProbable.fields."System.ID") - $($mostProbable.fields."System.Title")' (fuzzy matched based on title)" - -#if (!$issueId) -#{ -# $issueId = $mostProbable.fields."System.ID" -#} -# -#Write-Host -#Write-Host "Going to set the following fields:" -ForegroundColor Green -#Write-Host " State = $state" -# -#foreach ($field in $fields.Keys) -#{ -# Write-Host " $field = $($fields[$field])" -#} - -#$decision = $Host.UI.PromptForChoice("Updating work item https://dev.azure.com/azure-sdk/Release/_workitems/edit/$issueId", 'Are you sure you want to proceed?', @('&Yes'; '&No'), 0) - -#if ($decision -eq 0) -#{ -# az boards work-item update @commonParameter --id $issueId --state $state > $null -# foreach ($field in $fields.Keys) -# { -# az boards work-item update @commonParameter --id $issueId -f "$field=$($fields[$field])" > $null -# } -#} +&$EngCommonScriptsDir/Update-DevOps-Release-WorkItem.ps1 ` +-language (Get-LanguageName($Language)) ` +-packageName $packageProperties.Name ` +-version $newVersion ` +-plannedDate $releaseDateString ` +-packageRepoPath $serviceDirectory \ No newline at end of file From 9eda0fb55b124785fe2dcd11847a22de282dd83b Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Wed, 13 Jan 2021 17:02:50 -0800 Subject: [PATCH 09/10] Move Get-LanguageName to eng\common\scripts\Helpers\DevOps-WorkItem-Helpers.ps1, improve error message, add logic to detect changes made by prepare-release script --- .../Helpers/DevOps-WorkItem-Helpers.ps1 | 17 ++++++++ eng/common/scripts/Prepare-Release.ps1 | 40 +++++++------------ .../Update-DevOps-Release-WorkItem.ps1 | 1 + 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1 b/eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1 index 061134f90d9b..f6c959caf4b0 100644 --- a/eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1 +++ b/eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1 @@ -802,4 +802,21 @@ function UpdatePackageVersions($pkgWorkItem, $plannedVersions, $shippedVersions) $response = Invoke-RestMethod -Method PATCH ` -Uri "https://dev.azure.com/azure-sdk/_apis/wit/workitems/${id}?api-version=6.0" ` -Headers $headers -Body $body -ContentType "application/json-patch+json" +} + +function Get-LanguageName($lang) +{ + $pkgLang = $languageNameMapping[$lang] + if (!$pkgLang) { + $pkgLang = $lang + } + return $pkgLang +} + +$languageNameMapping = @{ + cpp = "C++" + dotnet = ".NET" + java = "Java" + js = "JavaScript" + python = "Python" } \ No newline at end of file diff --git a/eng/common/scripts/Prepare-Release.ps1 b/eng/common/scripts/Prepare-Release.ps1 index 582f9b536ae7..45a9662c9022 100644 --- a/eng/common/scripts/Prepare-Release.ps1 +++ b/eng/common/scripts/Prepare-Release.ps1 @@ -10,14 +10,7 @@ param( ) . ${PSScriptRoot}\common.ps1 -function Get-LanguageName($lang) -{ - $pkgLang = $languageNameMapping[$lang] - if (!$pkgLang) { - $pkgLang = $lang - } - return $pkgLang -} + function Get-ReleaseDay($baseDate) { # Find first friday @@ -32,14 +25,6 @@ function Get-ReleaseDay($baseDate) return $baseDate; } -$languageNameMapping = @{ - cpp = "C++" - dotnet = ".NET" - java = "Java" - js = "JavaScript" - python = "Python" -} - $ErrorPreference = 'Stop' $packageProperties = Get-PkgProperties -PackageName $PackageName -ServiceDirectory $serviceDirectory @@ -91,16 +76,10 @@ if (!$newVersion) $newVersionParsed = [AzureEngSemanticVersion]::ParseVersionString($newVersion) if ($null -eq $newVersionParsed) { - Write-Error "Invalid version $newVersion. Please try agaiin with a valid version." + Write-Error "Invalid version $newVersion. Version must follow standard SemVer rules, see https://aka.ms/azsdk/engsys/packageversioning" exit 1 } -Write-Host -Write-Host "Detected released type [ $($newVersionParsed.VersionType) ]" -ForegroundColor Green - -Write-Host -Write-Host "Updating versions to [ $newVersion ] with date [ $releaseDateString ]" -ForegroundColor Green - if (Test-Path "Function:SetPackageVersion") { SetPackageVersion -PackageName $PackageName -Version $newVersion -ServiceDirectory $serviceDirectory -ReleaseDate $releaseDateString ` @@ -109,13 +88,22 @@ if (Test-Path "Function:SetPackageVersion") else { LogError "The function 'SetPackageVersion' was not found.` - Make sure it is present in eng/scripts/Language-Settings.ps1" + Make sure it is present in eng/scripts/Language-Settings.ps1.` + See https://github.com/Azure/azure-sdk-tools/blob/master/doc/common/common_engsys.md#code-structure" exit 1 } &$EngCommonScriptsDir/Update-DevOps-Release-WorkItem.ps1 ` --language (Get-LanguageName($Language)) ` +-language $Language ` -packageName $packageProperties.Name ` -version $newVersion ` -plannedDate $releaseDateString ` --packageRepoPath $serviceDirectory \ No newline at end of file +-packageRepoPath $packageProperties.serviceDirectory + +git diff -s --exit-code $packageProperties.DirectoryPath +if ($LASTEXITCODE -ne 0) +{ + git status + Write-Host "Some changes were made to the repo source" -ForegroundColor Green + Write-Host "Submit a pull request with the necessary changes to the repo" -ForegroundColor Green +} \ No newline at end of file diff --git a/eng/common/scripts/Update-DevOps-Release-WorkItem.ps1 b/eng/common/scripts/Update-DevOps-Release-WorkItem.ps1 index 52fb9bd34299..b5489f2d436f 100644 --- a/eng/common/scripts/Update-DevOps-Release-WorkItem.ps1 +++ b/eng/common/scripts/Update-DevOps-Release-WorkItem.ps1 @@ -34,6 +34,7 @@ $parsedNewVersion = [AzureEngSemanticVersion]::new($version) $state = "In Release" $releaseType = $parsedNewVersion.VersionType $versionMajorMinor = "" + $parsedNewVersion.Major + "." + $parsedNewVersion.Minor +$language = Get-LanguageName -lang $language $packageInfo = [PSCustomObject][ordered]@{ Package = $packageName From de8f11a75a38beb0168ec23197f6cce133c524bb Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Tue, 19 Jan 2021 16:08:57 -0800 Subject: [PATCH 10/10] Use LanguageDisplayName, move Get-CSVMetadata to Package-Properties.ps1 --- eng/common/docgeneration/Generate-DocIndex.ps1 | 7 ------- .../scripts/Helpers/DevOps-WorkItem-Helpers.ps1 | 17 ----------------- eng/common/scripts/Package-Properties.ps1 | 10 +++++++++- eng/common/scripts/Prepare-Release.ps1 | 4 ++-- .../scripts/Update-DevOps-Release-WorkItem.ps1 | 1 - eng/common/scripts/common.ps1 | 6 ++++++ 6 files changed, 17 insertions(+), 28 deletions(-) diff --git a/eng/common/docgeneration/Generate-DocIndex.ps1 b/eng/common/docgeneration/Generate-DocIndex.ps1 index e01fe4fc057b..bfdae912e6b2 100644 --- a/eng/common/docgeneration/Generate-DocIndex.ps1 +++ b/eng/common/docgeneration/Generate-DocIndex.ps1 @@ -10,13 +10,6 @@ Param ( ) . "${PSScriptRoot}\..\scripts\common.ps1" -# Given the metadata url under https://github.com/Azure/azure-sdk/tree/master/_data/releases/latest, -# the function will return the csv metadata back as part of response. -function Get-CSVMetadata ([string]$MetadataUri) { - $metadataResponse = Invoke-RestMethod -Uri $MetadataUri -method "GET" -MaximumRetryCount 3 -RetryIntervalSec 10 | ConvertFrom-Csv - return $metadataResponse -} - # Given the github io blob storage url and language regex, # the helper function will return a list of artifact names. function Get-BlobStorage-Artifacts($blobStorageUrl, $blobDirectoryRegex, $blobArtifactsReplacement) { diff --git a/eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1 b/eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1 index f6c959caf4b0..061134f90d9b 100644 --- a/eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1 +++ b/eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1 @@ -802,21 +802,4 @@ function UpdatePackageVersions($pkgWorkItem, $plannedVersions, $shippedVersions) $response = Invoke-RestMethod -Method PATCH ` -Uri "https://dev.azure.com/azure-sdk/_apis/wit/workitems/${id}?api-version=6.0" ` -Headers $headers -Body $body -ContentType "application/json-patch+json" -} - -function Get-LanguageName($lang) -{ - $pkgLang = $languageNameMapping[$lang] - if (!$pkgLang) { - $pkgLang = $lang - } - return $pkgLang -} - -$languageNameMapping = @{ - cpp = "C++" - dotnet = ".NET" - java = "Java" - js = "JavaScript" - python = "Python" } \ No newline at end of file diff --git a/eng/common/scripts/Package-Properties.ps1 b/eng/common/scripts/Package-Properties.ps1 index f8607bcf728b..c1daf77b3b36 100644 --- a/eng/common/scripts/Package-Properties.ps1 +++ b/eng/common/scripts/Package-Properties.ps1 @@ -109,7 +109,7 @@ function Get-PkgProperties return $pkgProps } } - LogError "Failed to retrive Properties for $PackageName" + LogWarning "Failed to retrive Properties for $PackageName" return $null } @@ -153,6 +153,14 @@ function Get-AllPkgProperties ([string]$ServiceDirectory = $null) return $pkgPropsResult } +# Given the metadata url under https://github.com/Azure/azure-sdk/tree/master/_data/releases/latest, +# the function will return the csv metadata back as part of response. +function Get-CSVMetadata ([string]$MetadataUri=$MetadataUri) +{ + $metadataResponse = Invoke-RestMethod -Uri $MetadataUri -method "GET" -MaximumRetryCount 3 -RetryIntervalSec 10 | ConvertFrom-Csv + return $metadataResponse +} + function Operate-OnPackages ($activePkgList, $ServiceDirectory, [Array]$pkgPropsResult) { foreach ($pkg in $activePkgList) diff --git a/eng/common/scripts/Prepare-Release.ps1 b/eng/common/scripts/Prepare-Release.ps1 index 45a9662c9022..dbe6438c28a7 100644 --- a/eng/common/scripts/Prepare-Release.ps1 +++ b/eng/common/scripts/Prepare-Release.ps1 @@ -82,7 +82,7 @@ if ($null -eq $newVersionParsed) if (Test-Path "Function:SetPackageVersion") { - SetPackageVersion -PackageName $PackageName -Version $newVersion -ServiceDirectory $serviceDirectory -ReleaseDate $releaseDateString ` + SetPackageVersion -PackageName $packageProperties.Name -Version $newVersion -ServiceDirectory $serviceDirectory -ReleaseDate $releaseDateString ` -BuildType $BuildType -GroupId $packageProperties.Group } else @@ -94,7 +94,7 @@ else } &$EngCommonScriptsDir/Update-DevOps-Release-WorkItem.ps1 ` --language $Language ` +-language $LanguageDisplayName ` -packageName $packageProperties.Name ` -version $newVersion ` -plannedDate $releaseDateString ` diff --git a/eng/common/scripts/Update-DevOps-Release-WorkItem.ps1 b/eng/common/scripts/Update-DevOps-Release-WorkItem.ps1 index b5489f2d436f..52fb9bd34299 100644 --- a/eng/common/scripts/Update-DevOps-Release-WorkItem.ps1 +++ b/eng/common/scripts/Update-DevOps-Release-WorkItem.ps1 @@ -34,7 +34,6 @@ $parsedNewVersion = [AzureEngSemanticVersion]::new($version) $state = "In Release" $releaseType = $parsedNewVersion.VersionType $versionMajorMinor = "" + $parsedNewVersion.Major + "." + $parsedNewVersion.Minor -$language = Get-LanguageName -lang $language $packageInfo = [PSCustomObject][ordered]@{ Package = $packageName diff --git a/eng/common/scripts/common.ps1 b/eng/common/scripts/common.ps1 index e83b9a32e4fe..8ccf27b0ba4f 100644 --- a/eng/common/scripts/common.ps1 +++ b/eng/common/scripts/common.ps1 @@ -24,11 +24,17 @@ $EngScriptsLanguageSettings = Join-path $EngScriptsDir "Language-Settings.ps1" if (Test-Path $EngScriptsLanguageSettings) { . $EngScriptsLanguageSettings } + if (-not $LanguageShort) { $LangaugeShort = $Language } +if (-not $LanguageDisplayName) +{ + $LanguageDisplayName = $Language +} + # Transformed Functions $GetPackageInfoFromRepoFn = "Get-${Language}-PackageInfoFromRepo" $GetPackageInfoFromPackageFileFn = "Get-${Language}-PackageInfoFromPackageFile"