Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion eng/common/scripts/ChangeLog-Operations.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
. "${PSScriptRoot}\SemVer.ps1"

$RELEASE_TITLE_REGEX = "(?<releaseNoteTitle>^\#+\s+(?<version>$([AzureEngSemanticVersion]::SEMVER_REGEX))(\s+(?<releaseStatus>\(.+\))))"
$SECTIONS_HEADER_REGEX = "^###\s(?<sectionName>.*)"
$CHANGELOG_UNRELEASED_STATUS = "(Unreleased)"
$CHANGELOG_DATE_FORMAT = "yyyy-MM-dd"
$RecommendedSectionHeaders = @("Features Added", "Breaking Changes", "Bugs Fixed", "Other Changes")
Expand Down Expand Up @@ -56,7 +57,7 @@ function Get-ChangeLogEntriesFromContent {
}
else {
if ($changeLogEntry) {
if ($line.Trim() -match "^###\s(?<sectionName>.*)")
if ($line.Trim() -match $SECTIONS_HEADER_REGEX)
{
$sectionName = $matches["sectionName"].Trim()
$changeLogEntry.Sections[$sectionName] = @()
Expand Down Expand Up @@ -289,3 +290,42 @@ function Set-ChangeLogContent {

Set-Content -Path $ChangeLogLocation -Value $changeLogContent
}

function Remove-EmptySections {
param (
[Parameter(Mandatory = $true)]
$ChangeLogEntry
)

$releaseContent = $ChangeLogEntry.ReleaseContent
$sectionsToRemove = @()

if ($releaseContent.Count -gt 0)
{
$parsedSections = $ChangeLogEntry.Sections
$sanitizedReleaseContent = New-Object System.Collections.ArrayList(,$releaseContent)

foreach ($key in @($parsedSections.Key))
{
if ([System.String]::IsNullOrWhiteSpace($parsedSections[$key]))
{
for ($i = 0; $i -lt $sanitizedReleaseContent.Count; $i++)
{
$line = $sanitizedReleaseContent[$i]
if ($line -match $SECTIONS_HEADER_REGEX -and $matches["sectionName"].Trim() -eq $key)
{
$sanitizedReleaseContent.RemoveAt($i)
while($i -lt $sanitizedReleaseContent.Count -and [System.String]::IsNullOrWhiteSpace($sanitizedReleaseContent[$i]))
{
$sanitizedReleaseContent.RemoveAt($i)
}
$ChangeLogEntry.Sections.Remove($key)
break
}
}
}
}
$ChangeLogEntry.ReleaseContent = $sanitizedReleaseContent.ToArray()
}
return $changeLogEntry
}
51 changes: 11 additions & 40 deletions eng/common/scripts/Update-ChangeLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Version : Version to add or replace in change log
# Unreleased: Default is true. If it is set to false, then today's date will be set in verion title. If it is True then title will show "Unreleased"
# ReplaceLatestEntryTitle: Replaces the latest changelog entry title.
# SanitizeEntry: Removes all empty section in the entry that is updated

param (
[Parameter(Mandatory = $true)]
Expand All @@ -13,7 +14,8 @@ param (
[Boolean]$Unreleased = $true,
[Boolean]$ReplaceLatestEntryTitle = $false,
[String]$ChangelogPath,
[String]$ReleaseDate
[String]$ReleaseDate,
[Boolean]$SanitizeEntry = $false
)
Set-StrictMode -Version 3

Expand Down Expand Up @@ -106,47 +108,12 @@ if ($LatestsSorted[0] -ne $Version) {

if ($ReplaceLatestEntryTitle)
{
# Remove empty sections from content
$sanitizedContent = @()
$sectionContent = @()
$sectionContentCount = 0
$latesVersionContent = $ChangeLogEntries[$LatestVersion].ReleaseContent

foreach ($line in $latesVersionContent)
{
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)
$entryToBeUpdated = $ChangeLogEntries[$LatestVersion]
if ($SanitizeEntry)
{
$sanitizedContent += $sectionContent
$entryToBeUpdated = Remove-EmptySections -ChangeLogEntry $entryToBeUpdated
}

$newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus -Content $sanitizedContent
$newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus -Content $entryToBeUpdated
LogDebug "Resetting latest entry title to [$($newChangeLogEntry.ReleaseTitle)]"
$ChangeLogEntries.Remove($LatestVersion)
if ($newChangeLogEntry) {
Expand All @@ -162,6 +129,10 @@ elseif ($ChangeLogEntries.Contains($Version))
LogDebug "Updating ReleaseStatus for Version [$Version] to [$($ReleaseStatus)]"
$ChangeLogEntries[$Version].ReleaseStatus = $ReleaseStatus
$ChangeLogEntries[$Version].ReleaseTitle = "## $Version $ReleaseStatus"
if ($SanitizeEntry)
{
$ChangeLogEntries[$Version] = Remove-EmptySections -ChangeLogEntry $ChangeLogEntries[$Version]
}
}
else
{
Expand Down