From bf60d749e5bcb6c447b19a5958682f57a72af3ad Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Thu, 21 Jan 2021 18:42:01 -0800 Subject: [PATCH] Update changelog logic to use ordered hashtable --- eng/common/scripts/ChangeLog-Operations.ps1 | 33 ++++++++++++++------- eng/common/scripts/Update-ChangeLog.ps1 | 11 ++++--- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/eng/common/scripts/ChangeLog-Operations.ps1 b/eng/common/scripts/ChangeLog-Operations.ps1 index 8bb3e4be205c..26ea694cb502 100644 --- a/eng/common/scripts/ChangeLog-Operations.ps1 +++ b/eng/common/scripts/ChangeLog-Operations.ps1 @@ -13,7 +13,7 @@ function Get-ChangeLogEntries { [String]$ChangeLogLocation ) - $changeLogEntries = @{} + $changeLogEntries = [Ordered]@{} if (!(Test-Path $ChangeLogLocation)) { LogError "ChangeLog[${ChangeLogLocation}] does not exist" return $null @@ -191,16 +191,7 @@ function Set-ChangeLogContent { $changeLogContent += "# Release History" $changeLogContent += "" - try - { - $VersionsSorted = [AzureEngSemanticVersion]::SortVersionStrings($ChangeLogEntries.Keys) - } - catch { - LogError "Problem sorting version in ChangeLogEntries" - return - } - - foreach ($version in $VersionsSorted) { + foreach ($version in $ChangeLogEntries.Keys) { $changeLogEntry = $ChangeLogEntries[$version] $changeLogContent += $changeLogEntry.ReleaseTitle if ($changeLogEntry.ReleaseContent.Count -eq 0) { @@ -212,4 +203,24 @@ 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/Update-ChangeLog.ps1 b/eng/common/scripts/Update-ChangeLog.ps1 index 8f7c88e51cd2..d7dedfd41a6a 100644 --- a/eng/common/scripts/Update-ChangeLog.ps1 +++ b/eng/common/scripts/Update-ChangeLog.ps1 @@ -82,8 +82,7 @@ if ($ChangeLogEntries.Contains($Version)) } } -$PresentVersionsSorted = [AzureEngSemanticVersion]::SortVersionStrings($ChangeLogEntries.Keys) -$LatestVersion = $PresentVersionsSorted[0] +$LatestVersion = $ChangeLogEntries[0].ReleaseVersion LogDebug "The latest release note entry in the changelog is for version [$($LatestVersion)]" @@ -99,7 +98,9 @@ if ($ReplaceLatestEntryTitle) LogDebug "Resetting latest entry title to [$($newChangeLogEntry.ReleaseTitle)]" $ChangeLogEntries.Remove($LatestVersion) if ($newChangeLogEntry) { - $ChangeLogEntries[$Version] = $newChangeLogEntry + $ChangeLogEntries = Add-ChangelogEntry -ChangeLogEntries $ChangeLogEntries ` + -NewChangeLogEntry $newChangeLogEntry ` + -Version $Version } else { LogError "Failed to create new changelog entry" @@ -117,7 +118,9 @@ else LogDebug "Adding new ChangeLog entry for Version [$Version]" $newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus if ($newChangeLogEntry) { - $ChangeLogEntries[$Version] = $newChangeLogEntry + $ChangeLogEntries = Add-ChangelogEntry -ChangeLogEntries $ChangeLogEntries ` + -NewChangeLogEntry $newChangeLogEntry ` + -Version $Version } else { LogError "Failed to create new changelog entry"