From ce2c8db5017bf7de3fe3b1ffaa584b710d8aa90c Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Fri, 8 Apr 2022 20:37:20 -0700 Subject: [PATCH] Sync eng/common directory with azure-sdk-tools for PR 2963 (#3542) * Verify changelog like a release is about to take place if a vlaid date is present * Update eng/common/scripts/ChangeLog-Operations.ps1 Co-authored-by: Ben Broderick Phillips * Update eng/common/scripts/ChangeLog-Operations.ps1 Co-authored-by: Ben Broderick Phillips * Update eng/common/scripts/ChangeLog-Operations.ps1 Co-authored-by: Ben Broderick Phillips * Update eng/common/scripts/ChangeLog-Operations.ps1 Co-authored-by: Ben Broderick Phillips * Update eng/common/scripts/ChangeLog-Operations.ps1 Co-authored-by: Ben Broderick Phillips * Remove strict date verification * Add function for sorting changelog entries * Minor cleanups Co-authored-by: Chidozie Ononiwu Co-authored-by: Chidozie Ononiwu (His Righteousness) <31145988+chidozieononiwu@users.noreply.github.com> Co-authored-by: Ben Broderick Phillips --- eng/common/scripts/ChangeLog-Operations.ps1 | 163 ++++++++++++-------- 1 file changed, 100 insertions(+), 63 deletions(-) diff --git a/eng/common/scripts/ChangeLog-Operations.ps1 b/eng/common/scripts/ChangeLog-Operations.ps1 index df2bc9d1d..7363c2690 100644 --- a/eng/common/scripts/ChangeLog-Operations.ps1 +++ b/eng/common/scripts/ChangeLog-Operations.ps1 @@ -165,61 +165,20 @@ function Confirm-ChangeLogEntry { return $false } - if ($ForRelease -eq $True) { - if ($changeLogEntry.ReleaseStatus -eq $CHANGELOG_UNRELEASED_STATUS) { - LogError "Entry has no release date set. Please ensure to set a release date with format '$CHANGELOG_DATE_FORMAT'. See https://aka.ms/azsdk/guideline/changelogs for more info." - return $false - } - else { - $status = $changeLogEntry.ReleaseStatus.Trim().Trim("()") - try { - $releaseDate = [DateTime]$status - if ($status -ne ($releaseDate.ToString($CHANGELOG_DATE_FORMAT))) - { - LogError "Date must be in the format $($CHANGELOG_DATE_FORMAT). See https://aka.ms/azsdk/guideline/changelogs for more info." - return $false - } - if (((Get-Date).AddMonths(-1) -gt $releaseDate) -or ($releaseDate -gt (Get-Date).AddMonths(1))) - { - LogError "The date must be within +/- one month from today. See https://aka.ms/azsdk/guideline/changelogs for more info." - return $false - } - } - catch { - LogError "Invalid date [ $status ] passed as status for Version [$($changeLogEntry.ReleaseVersion)]. See https://aka.ms/azsdk/guideline/changelogs for more info." - return $false - } - } - - if ([System.String]::IsNullOrWhiteSpace($changeLogEntry.ReleaseContent)) { - LogError "Entry has no content. Please ensure to provide some content of what changed in this version. See https://aka.ms/azsdk/guideline/changelogs for more info." - return $false - } - - $foundRecomendedSection = $false - $emptySections = @() - foreach ($key in $changeLogEntry.Sections.Keys) - { - $sectionContent = $changeLogEntry.Sections[$key] - if ([System.String]::IsNullOrWhiteSpace(($sectionContent | Out-String))) - { - $emptySections += $key - } - if ($RecommendedSectionHeaders -contains $key) - { - $foundRecomendedSection = $true - } - } - if ($emptySections.Count -gt 0) - { - LogError "The changelog entry has the following sections with no content ($($emptySections -join ', ')). Please ensure to either remove the empty sections or add content to the section." - return $false - } - if (!$foundRecomendedSection) - { - LogWarning "The changelog entry did not contain any of the recommended sections ($($RecommendedSectionHeaders -join ', ')), pease add at least one. See https://aka.ms/azsdk/guideline/changelogs for more info." - } + if ($ForRelease -eq $True) + { + LogDebug "Verifying as a release build because ForRelease parameter is set to true" + return Confirm-ChangeLogForRelease -changeLogEntry $changeLogEntry -changeLogEntries $changeLogEntries } + + # If the release status is a valid date then verify like its about to be released + $status = $changeLogEntry.ReleaseStatus.Trim().Trim("()") + if ($status -as [DateTime]) + { + LogDebug "Verifying like it's a release build because the changelog entry has a valid date." + return Confirm-ChangeLogForRelease -changeLogEntry $changeLogEntry -changeLogEntries $changeLogEntries + } + return $true } @@ -291,15 +250,7 @@ function Set-ChangeLogContent { $changeLogContent += "$($ChangeLogEntries.InitialAtxHeader) Release History" $changeLogContent += "" - try - { - $ChangeLogEntries = $ChangeLogEntries.Values | Sort-Object -Descending -Property ReleaseStatus, ` - @{e = {[AzureEngSemanticVersion]::new($_.ReleaseVersion)}} - } - catch { - LogError "Problem sorting version in ChangeLogEntries" - return - } + $ChangeLogEntries = Sort-ChangeLogEntries -changeLogEntries $ChangeLogEntries foreach ($changeLogEntry in $ChangeLogEntries) { $changeLogContent += $changeLogEntry.ReleaseTitle @@ -362,4 +313,90 @@ function Get-LatestReleaseDateFromChangeLog $changeLogEntries = Get-ChangeLogEntries -ChangeLogLocation $ChangeLogLocation $latestVersion = $changeLogEntries[0].ReleaseStatus.Trim("()") return ($latestVersion -as [DateTime]) +} + +function Sort-ChangeLogEntries { + param ( + [Parameter(Mandatory = $true)] + $changeLogEntries + ) + + try + { + $changeLogEntries = $ChangeLogEntries.Values | Sort-Object -Descending -Property ReleaseStatus, ` + @{e = {[AzureEngSemanticVersion]::new($_.ReleaseVersion)}} + } + catch { + LogError "Problem sorting version in ChangeLogEntries" + exit(1) + } + return $changeLogEntries +} + +function Confirm-ChangeLogForRelease { + param ( + [Parameter(Mandatory = $true)] + $changeLogEntry, + [Parameter(Mandatory = $true)] + $changeLogEntries + ) + + $entries = Sort-ChangeLogEntries -changeLogEntries $changeLogEntries + + $isValid = $true + if ($changeLogEntry.ReleaseStatus -eq $CHANGELOG_UNRELEASED_STATUS) { + LogError "Entry has no release date set. Please ensure to set a release date with format '$CHANGELOG_DATE_FORMAT'. See https://aka.ms/azsdk/guideline/changelogs for more info." + $isValid = $false + } + else { + $status = $changeLogEntry.ReleaseStatus.Trim().Trim("()") + try { + $releaseDate = [DateTime]$status + if ($status -ne ($releaseDate.ToString($CHANGELOG_DATE_FORMAT))) + { + LogError "Date must be in the format $($CHANGELOG_DATE_FORMAT). See https://aka.ms/azsdk/guideline/changelogs for more info." + $isValid = $false + } + + if (@($entries.ReleaseStatus)[0] -ne $changeLogEntry.ReleaseStatus) + { + LogError "Invalid date [ $status ]. The date for the changelog being released must be the latest in the file." + $isValid = $false + } + } + catch { + LogError "Invalid date [ $status ] passed as status for Version [$($changeLogEntry.ReleaseVersion)]. See https://aka.ms/azsdk/guideline/changelogs for more info." + $isValid = $false + } + } + + if ([System.String]::IsNullOrWhiteSpace($changeLogEntry.ReleaseContent)) { + LogError "Entry has no content. Please ensure to provide some content of what changed in this version. See https://aka.ms/azsdk/guideline/changelogs for more info." + $isValid = $false + } + + $foundRecommendedSection = $false + $emptySections = @() + foreach ($key in $changeLogEntry.Sections.Keys) + { + $sectionContent = $changeLogEntry.Sections[$key] + if ([System.String]::IsNullOrWhiteSpace(($sectionContent | Out-String))) + { + $emptySections += $key + } + if ($RecommendedSectionHeaders -contains $key) + { + $foundRecommendedSection = $true + } + } + if ($emptySections.Count -gt 0) + { + LogError "The changelog entry has the following sections with no content ($($emptySections -join ', ')). Please ensure to either remove the empty sections or add content to the section." + $isValid = $false + } + if (!$foundRecommendedSection) + { + LogWarning "The changelog entry did not contain any of the recommended sections ($($RecommendedSectionHeaders -join ', ')), please add at least one. See https://aka.ms/azsdk/guideline/changelogs for more info." + } + return $isValid } \ No newline at end of file