Skip to content

Commit 150a03e

Browse files
azure-sdkchidozieononiwu
authored andcommitted
Stip empty changelog sections before release (#20437)
Co-authored-by: Chidozie Ononiwu <[email protected]>
1 parent 774da67 commit 150a03e

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

eng/common/scripts/Prepare-Release.ps1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ else
184184
exit 1
185185
}
186186

187+
$changelogIsValid = Confirm-ChangeLogEntry -ChangeLogLocation $packageProperties.ChangeLogPath -VersionString $newVersion -ForRelease $true
188+
189+
if (!$changelogIsValid)
190+
{
191+
Write-Host "The changelog [$($packageProperties.ChangeLogPath)] is not valid for release. Please make sure it is valid before queuing release build." -ForegroundColor Red
192+
}
193+
187194
git diff -s --exit-code $packageProperties.DirectoryPath
188195
if ($LASTEXITCODE -ne 0)
189196
{

eng/common/scripts/Update-ChangeLog.ps1

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,47 @@ if ($LatestsSorted[0] -ne $Version) {
106106

107107
if ($ReplaceLatestEntryTitle)
108108
{
109-
$newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus -Content $ChangeLogEntries[$LatestVersion].ReleaseContent
109+
# Remove empty sections from content
110+
$sanitizedContent = @()
111+
$sectionContent = @()
112+
$sectionContentCount = 0
113+
$latesVersionContent = $ChangeLogEntries[$LatestVersion].ReleaseContent
114+
115+
foreach ($line in $latesVersionContent)
116+
{
117+
if ($line.StartsWith("### ") -or $sectionContentCount -gt 0)
118+
{
119+
if ($line.StartsWith("#") -and $sectionContentCount -gt 1)
120+
{
121+
$sanitizedContent += $sectionContent
122+
$sectionContent = @()
123+
$sectionContentCount = 0
124+
}
125+
126+
if ($line.StartsWith("#") -and $sectionContentCount -eq 1)
127+
{
128+
$sectionContent = @()
129+
$sectionContentCount = 0
130+
}
131+
132+
$sectionContent += $line
133+
if (-not [System.String]::IsNullOrWhiteSpace($line))
134+
{
135+
$sectionContentCount++
136+
}
137+
}
138+
elseif ($sectionContent.Count -eq 0)
139+
{
140+
$sanitizedContent += $line
141+
}
142+
}
143+
144+
if ($sectionContentCount -gt 1)
145+
{
146+
$sanitizedContent += $sectionContent
147+
}
148+
149+
$newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus -Content $sanitizedContent
110150
LogDebug "Resetting latest entry title to [$($newChangeLogEntry.ReleaseTitle)]"
111151
$ChangeLogEntries.Remove($LatestVersion)
112152
if ($newChangeLogEntry) {

0 commit comments

Comments
 (0)