Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools for PR 8053 (#43316)
Browse files Browse the repository at this point in the history
* Pass flag to suppress errors correctly when verifying release change log

* Changes as per review comments

---------

Co-authored-by: Praveen Kuttappan <[email protected]>
  • Loading branch information
azure-sdk and praveenkuttappan authored Apr 10, 2024
1 parent e6be0d2 commit 325e3d5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
38 changes: 16 additions & 22 deletions eng/common/scripts/ChangeLog-Operations.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -139,27 +139,23 @@ function Confirm-ChangeLogEntry {
[String]$VersionString,
[boolean]$ForRelease = $false,
[Switch]$SantizeEntry,
[PSCustomObject]$ChangeLogStatus = $null
[PSCustomObject]$ChangeLogStatus = $null,
[boolean]$SuppressErrors = $false
)

$suppressErrors = $false
if (!$ChangeLogStatus) {
$ChangeLogStatus = [PSCustomObject]@{
IsValid = $false
Message = ""
}
}
else {
# Do not stop the script on error when status object is passed as param
$suppressErrors = $true
}
$changeLogEntries = Get-ChangeLogEntries -ChangeLogLocation $ChangeLogLocation
$changeLogEntry = $changeLogEntries[$VersionString]

if (!$changeLogEntry) {
$ChangeLogStatus.Message = "ChangeLog[${ChangeLogLocation}] does not have an entry for version ${VersionString}."
$ChangeLogStatus.IsValid = $false
if (!$suppressErrors) {
if (!$SuppressErrors) {
LogError "$($ChangeLogStatus.Message)"
}
return $false
Expand All @@ -179,7 +175,7 @@ function Confirm-ChangeLogEntry {
if ([System.String]::IsNullOrEmpty($changeLogEntry.ReleaseStatus)) {
$ChangeLogStatus.Message = "Entry does not have a release status. Please ensure the status is set to a date '($CHANGELOG_DATE_FORMAT)' or '$CHANGELOG_UNRELEASED_STATUS' if not yet released. See https://aka.ms/azsdk/guideline/changelogs for more info."
$ChangeLogStatus.IsValid = $false
if (!$suppressErrors) {
if (!$SuppressErrors) {
LogError "$($ChangeLogStatus.Message)"
}
return $false
Expand All @@ -188,15 +184,15 @@ function Confirm-ChangeLogEntry {
if ($ForRelease -eq $True)
{
LogDebug "Verifying as a release build because ForRelease parameter is set to true"
return Confirm-ChangeLogForRelease -changeLogEntry $changeLogEntry -changeLogEntries $changeLogEntries -ChangeLogStatus $ChangeLogStatus
return Confirm-ChangeLogForRelease -changeLogEntry $changeLogEntry -changeLogEntries $changeLogEntries -ChangeLogStatus $ChangeLogStatus -SuppressErrors $SuppressErrors
}

# 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 as a release build because the changelog entry has a valid date."
return Confirm-ChangeLogForRelease -changeLogEntry $changeLogEntry -changeLogEntries $changeLogEntries -ChangeLogStatus $ChangeLogStatus
return Confirm-ChangeLogForRelease -changeLogEntry $changeLogEntry -changeLogEntries $changeLogEntries -ChangeLogStatus $ChangeLogStatus -SuppressErrors $SuppressErrors
}

$ChangeLogStatus.Message = "ChangeLog[${ChangeLogLocation}] has an entry for version ${VersionString}."
Expand Down Expand Up @@ -361,26 +357,24 @@ function Confirm-ChangeLogForRelease {
$changeLogEntry,
[Parameter(Mandatory = $true)]
$changeLogEntries,
$ChangeLogStatus = $null
$ChangeLogStatus = $null,
$SuppressErrors = $false
)

$suppressErrors = $false
if (!$ChangeLogStatus) {
$ChangeLogStatus = [PSCustomObject]@{
IsValid = $false
Message = ""
}
}
else {
$suppressErrors = $true
}

$entries = Sort-ChangeLogEntries -changeLogEntries $changeLogEntries

$ChangeLogStatus.IsValid = $true
if ($changeLogEntry.ReleaseStatus -eq $CHANGELOG_UNRELEASED_STATUS) {
$ChangeLogStatus.Message = "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."
$ChangeLogStatus.IsValid = $false
if (!$suppressErrors) {
if (!$SuppressErrors) {
LogError "$($ChangeLogStatus.Message)"
}
}
Expand All @@ -392,7 +386,7 @@ function Confirm-ChangeLogForRelease {
{
$ChangeLogStatus.Message = "Date must be in the format $($CHANGELOG_DATE_FORMAT). See https://aka.ms/azsdk/guideline/changelogs for more info."
$ChangeLogStatus.IsValid = $false
if (!$suppressErrors) {
if (!$SuppressErrors) {
LogError "$($ChangeLogStatus.Message)"
}
}
Expand All @@ -401,15 +395,15 @@ function Confirm-ChangeLogForRelease {
{
$ChangeLogStatus.Message = "Invalid date [ $status ]. The date for the changelog being released must be the latest in the file."
$ChangeLogStatus.IsValid = $false
if (!$suppressErrors) {
if (!$SuppressErrors) {
LogError "$($ChangeLogStatus.Message)"
}
}
}
catch {
$ChangeLogStatus.Message = "Invalid date [ $status ] passed as status for Version [$($changeLogEntry.ReleaseVersion)]. See https://aka.ms/azsdk/guideline/changelogs for more info."
$ChangeLogStatus.IsValid = $false
if (!$suppressErrors) {
if (!$SuppressErrors) {
LogError "$($ChangeLogStatus.Message)"
}
}
Expand All @@ -418,7 +412,7 @@ function Confirm-ChangeLogForRelease {
if ([System.String]::IsNullOrWhiteSpace($changeLogEntry.ReleaseContent)) {
$ChangeLogStatus.Message = "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."
$ChangeLogStatus.IsValid = $false
if (!$suppressErrors) {
if (!$SuppressErrors) {
LogError "$($ChangeLogStatus.Message)"
}
}
Expand All @@ -441,14 +435,14 @@ function Confirm-ChangeLogForRelease {
{
$ChangeLogStatus.Message = "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."
$ChangeLogStatus.IsValid = $false
if (!$suppressErrors) {
if (!$SuppressErrors) {
LogError "$($ChangeLogStatus.Message)"
}
}
if (!$foundRecommendedSection)
{
$ChangeLogStatus.Message = "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."
if (!$suppressErrors) {
if (!$SuppressErrors) {
LogError "$($ChangeLogStatus.Message)"
}
}
Expand Down
2 changes: 1 addition & 1 deletion eng/common/scripts/Validate-Package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function ValidateChangeLog($changeLogPath, $versionString, $validationStatus)
Write-Host "Path to change log: [$changeLogFullPath]"
if (Test-Path $changeLogFullPath)
{
Confirm-ChangeLogEntry -ChangeLogLocation $changeLogFullPath -VersionString $versionString -ForRelease $true -ChangeLogStatus $ChangeLogStatus
Confirm-ChangeLogEntry -ChangeLogLocation $changeLogFullPath -VersionString $versionString -ForRelease $true -ChangeLogStatus $ChangeLogStatus -SuppressErrors $true
$validationStatus.Status = if ($ChangeLogStatus.IsValid) { "Success" } else { "Failed" }
$validationStatus.Message = $ChangeLogStatus.Message
}
Expand Down

0 comments on commit 325e3d5

Please sign in to comment.