Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools repository (Azure#24071)
Browse files Browse the repository at this point in the history
  • Loading branch information
azure-sdk authored Sep 17, 2021
1 parent 4979296 commit 44ce01c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
28 changes: 9 additions & 19 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>\(.+\))))"
$SECTION_HEADER_REGEX_SUFFIX = "##\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 @@ -49,7 +49,6 @@ function Get-ChangeLogEntriesFromContent {
$initialAtxHeader = $matches["HeaderLevel"]
}

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

Expand All @@ -68,7 +67,7 @@ function Get-ChangeLogEntriesFromContent {
}
else {
if ($changeLogEntry) {
if ($line.Trim() -match $sectionHeaderRegex)
if ($line.Trim() -match $SECTIONS_HEADER_REGEX)
{
$sectionName = $matches["sectionName"].Trim()
$changeLogEntry.Sections[$sectionName] = @()
Expand Down Expand Up @@ -137,24 +136,16 @@ function Confirm-ChangeLogEntry {
[String]$ChangeLogLocation,
[Parameter(Mandatory = $true)]
[String]$VersionString,
[boolean]$ForRelease = $false,
[Switch]$SantizeEntry
[boolean]$ForRelease = $false
)

$changeLogEntries = Get-ChangeLogEntries -ChangeLogLocation $ChangeLogLocation
$changeLogEntry = $changeLogEntries[$VersionString]
$changeLogEntry = Get-ChangeLogEntry -ChangeLogLocation $ChangeLogLocation -VersionString $VersionString

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 @@ -317,26 +308,24 @@ function Set-ChangeLogContent {
function Remove-EmptySections {
param (
[Parameter(Mandatory = $true)]
$ChangeLogEntry,
$InitialAtxHeader = "#"
$ChangeLogEntry
)

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

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

foreach ($key in @($parsedSections.Keys))
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 $sectionHeaderRegex -and $matches["sectionName"].Trim() -eq $key)
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]))
Expand All @@ -351,4 +340,5 @@ function Remove-EmptySections {
}
$ChangeLogEntry.ReleaseContent = $sanitizedReleaseContent.ToArray()
}
}
return $changeLogEntry
}
2 changes: 1 addition & 1 deletion eng/common/scripts/Prepare-Release.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ else
exit 1
}

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

if (!$changelogIsValid)
{
Expand Down
15 changes: 13 additions & 2 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,7 +108,12 @@ if ($LatestsSorted[0] -ne $Version) {

if ($ReplaceLatestEntryTitle)
{
$newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus -InitialAtxHeader $ChangeLogEntries.InitialAtxHeader -Content $ChangeLogEntries[$LatestVersion].ReleaseContent
$entryToBeUpdated = $ChangeLogEntries[$LatestVersion]
if ($SanitizeEntry)
{
$entryToBeUpdated = Remove-EmptySections -ChangeLogEntry $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) {
Expand All @@ -122,6 +129,10 @@ elseif ($ChangeLogEntries.Contains($Version))
LogDebug "Updating ReleaseStatus for Version [$Version] to [$($ReleaseStatus)]"
$ChangeLogEntries[$Version].ReleaseStatus = $ReleaseStatus
$ChangeLogEntries[$Version].ReleaseTitle = "$($ChangeLogEntries.InitialAtxHeader)# $Version $ReleaseStatus"
if ($SanitizeEntry)
{
$ChangeLogEntries[$Version] = Remove-EmptySections -ChangeLogEntry $ChangeLogEntries[$Version]
}
}
else
{
Expand Down

0 comments on commit 44ce01c

Please sign in to comment.