Add for multiple levels of Atx Headers in the CHANGELOG.md (#2900)

Co-authored-by: Chidozie Ononiwu <chononiw@microsoft.com>
This commit is contained in:
Azure SDK Bot 2021-09-14 16:56:12 -07:00 committed by GitHub
parent 14aa1516d0
commit 818cab9a2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 10 deletions

View File

@ -3,7 +3,7 @@
. "${PSScriptRoot}\SemVer.ps1"
$RELEASE_TITLE_REGEX = "(?<releaseNoteTitle>^\#+\s+(?<version>$([AzureEngSemanticVersion]::SEMVER_REGEX))(\s+(?<releaseStatus>\(.+\))))"
$SECTIONS_HEADER_REGEX = "^###\s(?<sectionName>.*)"
$SECTIONS_HEADER_REGEX = "^###+\s(?<sectionName>.*)"
$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 "(?<HeaderLevel>^#+)\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)
{

View File

@ -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

View File

@ -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)
}