From 6a06b0e5a2376da73a8849fcb393d241aff55c7b Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Tue, 14 Sep 2021 16:56:19 -0700 Subject: [PATCH] Add for multiple levels of Atx Headers in the CHANGELOG.md (#20694) Co-authored-by: Chidozie Ononiwu --- eng/common/scripts/ChangeLog-Operations.ps1 | 25 ++++++++++++++++----- eng/common/scripts/Prepare-Release.ps1 | 2 +- eng/common/scripts/Update-ChangeLog.ps1 | 6 ++--- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/eng/common/scripts/ChangeLog-Operations.ps1 b/eng/common/scripts/ChangeLog-Operations.ps1 index 2de780150145..af71628442de 100644 --- a/eng/common/scripts/ChangeLog-Operations.ps1 +++ b/eng/common/scripts/ChangeLog-Operations.ps1 @@ -3,7 +3,7 @@ . "${PSScriptRoot}\SemVer.ps1" $RELEASE_TITLE_REGEX = "(?^\#+\s+(?$([AzureEngSemanticVersion]::SEMVER_REGEX))(\s+(?\(.+\))))" -$SECTIONS_HEADER_REGEX = "^###\s(?.*)" +$SECTIONS_HEADER_REGEX = "^###+\s(?.*)" $CHANGELOG_UNRELEASED_STATUS = "(Unreleased)" $CHANGELOG_DATE_FORMAT = "yyyy-MM-dd" $RecommendedSectionHeaders = @("Features Added", "Breaking Changes", "Bugs Fixed", "Other Changes") @@ -42,6 +42,16 @@ function Get-ChangeLogEntriesFromContent { $changelogEntry = $null $sectionName = $null $changeLogEntries = [Ordered]@{} + $initialAtxHeader= "#" + + if ($changeLogContent[0] -match "(?^#+)\s.*") + { + $initialAtxHeader = $matches["HeaderLevel"] + } + + $changeLogEntries | Add-Member -NotePropertyName "InitialAtxHeader" -NotePropertyValue $initialAtxHeader + $releaseTitleAtxHeader = $initialAtxHeader + "#" + try { # walk the document, finding where the version specifiers are and creating lists foreach ($line in $changeLogContent) { @@ -49,7 +59,7 @@ function Get-ChangeLogEntriesFromContent { $changeLogEntry = [pscustomobject]@{ ReleaseVersion = $matches["version"] ReleaseStatus = $matches["releaseStatus"] - ReleaseTitle = "## {0} {1}" -f $matches["version"], $matches["releaseStatus"] + ReleaseTitle = "$releaseTitleAtxHeader {0} {1}" -f $matches["version"], $matches["releaseStatus"] ReleaseContent = @() Sections = @{} } @@ -210,6 +220,7 @@ function New-ChangeLogEntry { [ValidateNotNullOrEmpty()] [String]$Version, [String]$Status=$CHANGELOG_UNRELEASED_STATUS, + [String]$InitialAtxHeader="#", [String[]]$Content ) @@ -239,17 +250,20 @@ function New-ChangeLogEntry { $Content = @() $Content += "" + $sectionsAtxHeader = $InitialAtxHeader + "##" foreach ($recommendedHeader in $RecommendedSectionHeaders) { - $Content += "### $recommendedHeader" + $Content += "$sectionsAtxHeader $recommendedHeader" $Content += "" } } + $releaseTitleAtxHeader = $initialAtxHeader + "#" + $newChangeLogEntry = [pscustomobject]@{ ReleaseVersion = $Version ReleaseStatus = $Status - ReleaseTitle = "## $Version $Status" + ReleaseTitle = "$releaseTitleAtxHeader $Version $Status" ReleaseContent = $Content } @@ -265,7 +279,7 @@ function Set-ChangeLogContent { ) $changeLogContent = @() - $changeLogContent += "# Release History" + $changeLogContent += "$($ChangeLogEntries.InitialAtxHeader) Release History" $changeLogContent += "" try @@ -298,7 +312,6 @@ function Remove-EmptySections { ) $releaseContent = $ChangeLogEntry.ReleaseContent - $sectionsToRemove = @() if ($releaseContent.Count -gt 0) { diff --git a/eng/common/scripts/Prepare-Release.ps1 b/eng/common/scripts/Prepare-Release.ps1 index cee038dd18a0..21f4f256830e 100644 --- a/eng/common/scripts/Prepare-Release.ps1 +++ b/eng/common/scripts/Prepare-Release.ps1 @@ -188,7 +188,7 @@ $changelogIsValid = Confirm-ChangeLogEntry -ChangeLogLocation $packageProperties if (!$changelogIsValid) { - Write-Host "The changelog [$($packageProperties.ChangeLogPath)] is not valid for release. Please make sure it is valid before queuing release build." -ForegroundColor Red + Write-Warning "The changelog [$($packageProperties.ChangeLogPath)] is not valid for release. Please make sure it is valid before queuing release build." } git diff -s --exit-code $packageProperties.DirectoryPath diff --git a/eng/common/scripts/Update-ChangeLog.ps1 b/eng/common/scripts/Update-ChangeLog.ps1 index 43e97918bea1..9b9797e083a7 100644 --- a/eng/common/scripts/Update-ChangeLog.ps1 +++ b/eng/common/scripts/Update-ChangeLog.ps1 @@ -113,7 +113,7 @@ if ($ReplaceLatestEntryTitle) { $entryToBeUpdated = Remove-EmptySections -ChangeLogEntry $entryToBeUpdated } - $newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus -Content $entryToBeUpdated + $newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus -InitialAtxHeader $ChangeLogEntries.InitialAtxHeader -Content $entryToBeUpdated LogDebug "Resetting latest entry title to [$($newChangeLogEntry.ReleaseTitle)]" $ChangeLogEntries.Remove($LatestVersion) if ($newChangeLogEntry) { @@ -128,7 +128,7 @@ elseif ($ChangeLogEntries.Contains($Version)) { LogDebug "Updating ReleaseStatus for Version [$Version] to [$($ReleaseStatus)]" $ChangeLogEntries[$Version].ReleaseStatus = $ReleaseStatus - $ChangeLogEntries[$Version].ReleaseTitle = "## $Version $ReleaseStatus" + $ChangeLogEntries[$Version].ReleaseTitle = "$($ChangeLogEntries.InitialAtxHeader)# $Version $ReleaseStatus" if ($SanitizeEntry) { $ChangeLogEntries[$Version] = Remove-EmptySections -ChangeLogEntry $ChangeLogEntries[$Version] @@ -137,7 +137,7 @@ elseif ($ChangeLogEntries.Contains($Version)) else { LogDebug "Adding new ChangeLog entry for Version [$Version]" - $newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus + $newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus -InitialAtxHeader $ChangeLogEntries.InitialAtxHeader if ($newChangeLogEntry) { $ChangeLogEntries.Insert(0, $Version, $newChangeLogEntry) }