Skip to content

Commit

Permalink
Update changelog logic to use ordered hashtable
Browse files Browse the repository at this point in the history
  • Loading branch information
chidozieononiwu authored and azure-sdk committed Jan 25, 2021
1 parent 2b8314a commit bf60d74
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
33 changes: 22 additions & 11 deletions eng/common/scripts/ChangeLog-Operations.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function Get-ChangeLogEntries {
[String]$ChangeLogLocation
)

$changeLogEntries = @{}
$changeLogEntries = [Ordered]@{}
if (!(Test-Path $ChangeLogLocation)) {
LogError "ChangeLog[${ChangeLogLocation}] does not exist"
return $null
Expand Down Expand Up @@ -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) {
Expand All @@ -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
}
11 changes: 7 additions & 4 deletions eng/common/scripts/Update-ChangeLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)]"

Expand All @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit bf60d74

Please sign in to comment.