From 4c9ef0f9bb346fa8522ae48171d46ddbb0586e7d Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Wed, 25 Aug 2021 16:23:58 -0700 Subject: [PATCH] Stip empty changelog sections before release --- eng/common/scripts/Update-ChangeLog.ps1 | 43 ++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/eng/common/scripts/Update-ChangeLog.ps1 b/eng/common/scripts/Update-ChangeLog.ps1 index b4c07d597629..0d8c62cfa334 100644 --- a/eng/common/scripts/Update-ChangeLog.ps1 +++ b/eng/common/scripts/Update-ChangeLog.ps1 @@ -106,7 +106,48 @@ if ($LatestsSorted[0] -ne $Version) { if ($ReplaceLatestEntryTitle) { - $newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus -Content $ChangeLogEntries[$LatestVersion].ReleaseContent + # Remove empty sections from content + $sanitizedContent = @() + $sectionContent = @() + $sectionContentCount = 0 + $latesVersionContent = $ChangeLogEntries[$LatestVersion].ReleaseContent + + for ($i = 0; $i -lt $latesVersionContent.Count; $i++) + { + $line = $latesVersionContent[$i] + if ($line.StartsWith("### ") -or $sectionContentCount -gt 0) + { + if ($line.StartsWith("#") -and $sectionContentCount -gt 1) + { + $sanitizedContent += $sectionContent + $sectionContent = @() + $sectionContentCount = 0 + } + + if ($line.StartsWith("#") -and $sectionContentCount -eq 1) + { + $sectionContent = @() + $sectionContentCount = 0 + } + + $sectionContent += $line + if (-not [System.String]::IsNullOrWhiteSpace($line)) + { + $sectionContentCount++ + } + } + elseif ($sectionContent.Count -eq 0) + { + $sanitizedContent += $line + } + } + + if ($sectionContentCount -gt 1) + { + $sanitizedContent += $sectionContent + } + + $newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus -Content $sanitizedContent LogDebug "Resetting latest entry title to [$($newChangeLogEntry.ReleaseTitle)]" $ChangeLogEntries.Remove($LatestVersion) if ($newChangeLogEntry) {