From d47dbcc10f992e71754ba5404aea9e77890757cb Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Fri, 22 Jan 2021 16:45:24 -0800 Subject: [PATCH] Update semver and Changelog logic --- eng/common/scripts/ChangeLog-Operations.ps1 | 33 +++++++-------------- eng/common/scripts/SemVer.ps1 | 2 +- eng/common/scripts/Update-ChangeLog.ps1 | 14 ++++----- 3 files changed, 17 insertions(+), 32 deletions(-) diff --git a/eng/common/scripts/ChangeLog-Operations.ps1 b/eng/common/scripts/ChangeLog-Operations.ps1 index 26ea694cb502..316369d9090d 100644 --- a/eng/common/scripts/ChangeLog-Operations.ps1 +++ b/eng/common/scripts/ChangeLog-Operations.ps1 @@ -57,7 +57,7 @@ function Get-ChangeLogEntry { ) $changeLogEntries = Get-ChangeLogEntries -ChangeLogLocation $ChangeLogLocation - if ($changeLogEntries -and $changeLogEntries.ContainsKey($VersionString)) { + if ($changeLogEntries -and $changeLogEntries.Contains($VersionString)) { return $changeLogEntries[$VersionString] } return $null @@ -191,7 +191,16 @@ function Set-ChangeLogContent { $changeLogContent += "# Release History" $changeLogContent += "" - foreach ($version in $ChangeLogEntries.Keys) { + try + { + $VersionsSorted = [AzureEngSemanticVersion]::SortVersionStrings($ChangeLogEntries.Keys) + } + catch { + LogError "Problem sorting version in ChangeLogEntries" + return + } + + foreach ($version in $VersionsSorted) { $changeLogEntry = $ChangeLogEntries[$version] $changeLogContent += $changeLogEntry.ReleaseTitle if ($changeLogEntry.ReleaseContent.Count -eq 0) { @@ -203,24 +212,4 @@ function Set-ChangeLogContent { } Set-Content -Path $ChangeLogLocation -Value $changeLogContent -} - -function Add-ChangelogEntry { - param ( - [Parameter(Mandatory = $true)] - $ChangeLogEntries, - [Parameter(Mandatory = $true)] - $NewChangeLogEntry, - [Parameter(Mandatory = $true)] - $Version - ) - - $results = [Ordered]@{} - $results.Add($Version, $NewChangeLogEntry) - - foreach ($entryVersion in $ChangeLogEntries.Keys) { - $results.Add($entryVersion, $ChangeLogEntries[$entryVersion]) - } - - return $results } \ No newline at end of file diff --git a/eng/common/scripts/SemVer.ps1 b/eng/common/scripts/SemVer.ps1 index 4e804e765e8d..11af926010ea 100644 --- a/eng/common/scripts/SemVer.ps1 +++ b/eng/common/scripts/SemVer.ps1 @@ -181,7 +181,7 @@ class AzureEngSemanticVersion { { $versions = $versionStrings | ForEach-Object { [AzureEngSemanticVersion]::ParseVersionString($_) } $sortedVersions = [AzureEngSemanticVersion]::SortVersions($versions) - return ($sortedVersions | ForEach-Object { $_.ToString() }) + return ($sortedVersions | ForEach-Object { $_.RawVersion }) } static [AzureEngSemanticVersion[]] SortVersions([AzureEngSemanticVersion[]] $versions) diff --git a/eng/common/scripts/Update-ChangeLog.ps1 b/eng/common/scripts/Update-ChangeLog.ps1 index d7dedfd41a6a..75628a7449ff 100644 --- a/eng/common/scripts/Update-ChangeLog.ps1 +++ b/eng/common/scripts/Update-ChangeLog.ps1 @@ -82,14 +82,14 @@ if ($ChangeLogEntries.Contains($Version)) } } -$LatestVersion = $ChangeLogEntries[0].ReleaseVersion +$PresentVersionsSorted = [AzureEngSemanticVersion]::SortVersionStrings($ChangeLogEntries.Keys) +$LatestVersion = $PresentVersionsSorted[0] LogDebug "The latest release note entry in the changelog is for version [$($LatestVersion)]" $LatestsSorted = [AzureEngSemanticVersion]::SortVersionStrings(@($LatestVersion, $Version)) if ($LatestsSorted[0] -ne $Version) { - LogWarning "Version [$Version] is older than the latestversion [$LatestVersion] in the changelog. Please use a more recent version." - exit(0) + LogWarning "Version [$Version] is older than the latestversion [$LatestVersion] in the changelog. Consider using a more recent version." } if ($ReplaceLatestEntryTitle) @@ -98,9 +98,7 @@ if ($ReplaceLatestEntryTitle) LogDebug "Resetting latest entry title to [$($newChangeLogEntry.ReleaseTitle)]" $ChangeLogEntries.Remove($LatestVersion) if ($newChangeLogEntry) { - $ChangeLogEntries = Add-ChangelogEntry -ChangeLogEntries $ChangeLogEntries ` - -NewChangeLogEntry $newChangeLogEntry ` - -Version $Version + $ChangeLogEntries.Insert(0, $Version, $newChangeLogEntry) } else { LogError "Failed to create new changelog entry" @@ -118,9 +116,7 @@ else LogDebug "Adding new ChangeLog entry for Version [$Version]" $newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus if ($newChangeLogEntry) { - $ChangeLogEntries = Add-ChangelogEntry -ChangeLogEntries $ChangeLogEntries ` - -NewChangeLogEntry $newChangeLogEntry ` - -Version $Version + $ChangeLogEntries.Insert(0, $Version, $newChangeLogEntry) } else { LogError "Failed to create new changelog entry"