Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add for multiple levels of Atx Headers in the CHANGELOG.md #2008

Merged
1 commit merged into from
Sep 15, 2021
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
25 changes: 19 additions & 6 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>.*)"
$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 @@ -42,14 +42,24 @@ function Get-ChangeLogEntriesFromContent {
$changelogEntry = $null
$sectionName = $null
$changeLogEntries = [Ordered]@{}
$initialAtxHeader= "#"
weshaggard marked this conversation as resolved.
Show resolved Hide resolved

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) {
if ($line -match $RELEASE_TITLE_REGEX) {
$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 = @{}
}
Expand Down Expand Up @@ -210,6 +220,7 @@ function New-ChangeLogEntry {
[ValidateNotNullOrEmpty()]
[String]$Version,
[String]$Status=$CHANGELOG_UNRELEASED_STATUS,
[String]$InitialAtxHeader="#",
[String[]]$Content
)

Expand Down Expand Up @@ -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
}

Expand All @@ -265,7 +279,7 @@ function Set-ChangeLogContent {
)

$changeLogContent = @()
$changeLogContent += "# Release History"
$changeLogContent += "$($ChangeLogEntries.InitialAtxHeader) Release History"
$changeLogContent += ""

try
Expand Down Expand Up @@ -298,7 +312,6 @@ function Remove-EmptySections {
)

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

if ($releaseContent.Count -gt 0)
{
Expand Down
2 changes: 1 addition & 1 deletion eng/common/scripts/Prepare-Release.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions eng/common/scripts/Update-ChangeLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
chidozieononiwu marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -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]
Expand All @@ -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)
}
Expand Down