Skip to content

Commit

Permalink
Update SECTIONS_HEADER_REGEX to accomodate various header levels
Browse files Browse the repository at this point in the history
  • Loading branch information
chidozieononiwu authored and azure-sdk committed Sep 17, 2021
1 parent 1910dd0 commit 5c32b8a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
23 changes: 13 additions & 10 deletions eng/common/scripts/ChangeLog-Operations.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
. "${PSScriptRoot}\SemVer.ps1"

$RELEASE_TITLE_REGEX = "(?<releaseNoteTitle>^\#+\s+(?<version>$([AzureEngSemanticVersion]::SEMVER_REGEX))(\s+(?<releaseStatus>\(.+\))))"
$SECTIONS_HEADER_REGEX = "^###+\s(?<sectionName>.*)"
$SECTION_HEADER_REGEX_SUFFIX = "##\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 @@ -49,6 +49,7 @@ function Get-ChangeLogEntriesFromContent {
$initialAtxHeader = $matches["HeaderLevel"]
}

$sectionHeaderRegex = "^${initialAtxHeader}${SECTION_HEADER_REGEX_SUFFIX}"
$changeLogEntries | Add-Member -NotePropertyName "InitialAtxHeader" -NotePropertyValue $initialAtxHeader
$releaseTitleAtxHeader = $initialAtxHeader + "#"

Expand All @@ -67,7 +68,7 @@ function Get-ChangeLogEntriesFromContent {
}
else {
if ($changeLogEntry) {
if ($line.Trim() -match $SECTIONS_HEADER_REGEX)
if ($line.Trim() -match $sectionHeaderRegex)
{
$sectionName = $matches["sectionName"].Trim()
$changeLogEntry.Sections[$sectionName] = @()
Expand Down Expand Up @@ -143,17 +144,17 @@ function Confirm-ChangeLogEntry {
$changeLogEntries = Get-ChangeLogEntries -ChangeLogLocation $ChangeLogLocation
$changeLogEntry = $changeLogEntries[$VersionString]

if ($SantizeEntry)
{
Remove-EmptySections -ChangeLogEntry $changeLogEntry
Set-ChangeLogContent -ChangeLogLocation $ChangeLogLocation -ChangeLogEntries $changeLogEntries
}

if (!$changeLogEntry) {
LogError "ChangeLog[${ChangeLogLocation}] does not have an entry for version ${VersionString}."
return $false
}

if ($SantizeEntry)
{
Remove-EmptySections -ChangeLogEntry $changeLogEntry -InitialAtxHeader $changeLogEntries.InitialAtxHeader
Set-ChangeLogContent -ChangeLogLocation $ChangeLogLocation -ChangeLogEntries $changeLogEntries
}

Write-Host "Found the following change log entry for version '${VersionString}' in [${ChangeLogLocation}]."
Write-Host "-----"
Write-Host (ChangeLogEntryAsString $changeLogEntry)
Expand Down Expand Up @@ -316,9 +317,11 @@ function Set-ChangeLogContent {
function Remove-EmptySections {
param (
[Parameter(Mandatory = $true)]
$ChangeLogEntry
$ChangeLogEntry,
$InitialAtxHeader = "#"
)

$sectionHeaderRegex = "^${InitialAtxHeader}${SECTION_HEADER_REGEX_SUFFIX}"
$releaseContent = $ChangeLogEntry.ReleaseContent

if ($releaseContent.Count -gt 0)
Expand All @@ -333,7 +336,7 @@ function Remove-EmptySections {
for ($i = 0; $i -lt $sanitizedReleaseContent.Count; $i++)
{
$line = $sanitizedReleaseContent[$i]
if ($line -match $SECTIONS_HEADER_REGEX -and $matches["sectionName"].Trim() -eq $key)
if ($line -match $sectionHeaderRegex -and $matches["sectionName"].Trim() -eq $key)
{
$sanitizedReleaseContent.RemoveAt($i)
while($i -lt $sanitizedReleaseContent.Count -and [System.String]::IsNullOrWhiteSpace($sanitizedReleaseContent[$i]))
Expand Down
3 changes: 1 addition & 2 deletions eng/common/scripts/Prepare-Release.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ else
exit 1
}

Sanitize-ChangeLogEntry -ChangeLogLocation $packageProperties.ChangeLogPath -VersionString $newVersion
$changelogIsValid = Confirm-ChangeLogEntry -ChangeLogLocation $packageProperties.ChangeLogPath -VersionString $newVersion -ForRelease $true
$changelogIsValid = Confirm-ChangeLogEntry -ChangeLogLocation $packageProperties.ChangeLogPath -VersionString $newVersion -ForRelease $true -SantizeEntry

if (!$changelogIsValid)
{
Expand Down
2 changes: 1 addition & 1 deletion eng/common/scripts/Update-ChangeLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ if ($LatestsSorted[0] -ne $Version) {

if ($ReplaceLatestEntryTitle)
{
$newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus -InitialAtxHeader $ChangeLogEntries.InitialAtxHeader -Content $ChangeLogEntries[$LatestVersion]
$newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus -InitialAtxHeader $ChangeLogEntries.InitialAtxHeader -Content $ChangeLogEntries[$LatestVersion].ReleaseContent
LogDebug "Resetting latest entry title to [$($newChangeLogEntry.ReleaseTitle)]"
$ChangeLogEntries.Remove($LatestVersion)
if ($newChangeLogEntry) {
Expand Down

0 comments on commit 5c32b8a

Please sign in to comment.