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

Updates to Update-Changelog.ps1 #1299

Merged
1 commit merged into from
Jan 5, 2021
Merged
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
53 changes: 31 additions & 22 deletions eng/common/scripts/Update-ChangeLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Parameter description
# 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"
# ReplaceLatestEntry: Replaces the latest changelog entry, including its content.
# ReplaceLatestEntryTitle: Replaces the latest changelog entry title.

param (
[Parameter(Mandatory = $true)]
Expand All @@ -12,41 +12,46 @@ param (
[String]$ServiceDirectory,
[Parameter(Mandatory = $true)]
[String]$PackageName,
[boolean]$Unreleased=$True,
[boolean]$ReplaceLatestEntry = $False,
[String]$Unreleased=$True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want these to be strings now we should probably default them to strings instead of booleans.

[String]$ReplaceLatestEntryTitle = $False,
[String]$ReleaseDate
)

if ($ReleaseDate -and ($Unreleased -eq $True)) {
[Boolean]$Unreleased = [System.Convert]::ToBoolean($Unreleased)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do the manual conversion here as opposed to just having the parameters be Boolean as they currently are?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We call it from various python and Js scripts. Passing the parameters a Booleans was problematic. It wasn't clear to me how to get it working from all ends with Boolean parameters hence I just did the conversion after.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured you could just pass in the string "true" or "false" (or 0/1) as arguments and it would just work. Did that not work when calling it from python/JS?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that the issue. Even thought "true" and "false" is passed in the JS script . It is still recognized a s string on the PowerShell side and errors if the parameters are Boolean. Python has a similar weirdness.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. We could also consider making these switches so we don't have to pass a value in most cases. In either case if you keep these as strings it would be nice to add a comment as to why you are doing it so it is clear to use later.

[Boolean]$ReplaceLatestEntryTitle = [System.Convert]::ToBoolean($ReplaceLatestEntryTitle)

. (Join-Path $PSScriptRoot common.ps1)

if ($ReleaseDate -and $Unreleased) {
LogError "Do not pass 'ReleaseDate' arguement when 'Unreleased' is true"
chidozieononiwu marked this conversation as resolved.
Show resolved Hide resolved
exit 1
}

. (Join-Path $PSScriptRoot common.ps1)
weshaggard marked this conversation as resolved.
Show resolved Hide resolved

if ($ReleaseDate)
{
try {
$ReleaseStatus = ([DateTime]$ReleaseDate).ToString($CHANGELOG_DATE_FORMAT)
$ReleaseStatus = "($ReleaseStatus)"
}
catch {
LogError "Invalid 'ReleaseDate'. Please use a valid date in the format '$CHANGELOG_DATE_FORMAT'"
LogError "Invalid 'ReleaseDate'. Please use a valid date in the format '$CHANGELOG_DATE_FORMAT'. See https://aka.ms/azsdk/changelogguide"
exit 1
}
}
elseif ($Unreleased) {
elseif ($Unreleased)
{
$ReleaseStatus = $CHANGELOG_UNRELEASED_STATUS
}
else {
else
{
$ReleaseStatus = "$(Get-Date -Format $CHANGELOG_DATE_FORMAT)"
$ReleaseStatus = "($ReleaseStatus)"
}

if ($null -eq [AzureEngSemanticVersion]::ParseVersionString($Version))
{
LogError "Version [$Version] is invalid. Please use a valid SemVer"
exit(0)
LogError "Version [$Version] is invalid. Please use a valid SemVer. See https://aka.ms/azsdk/changelogguide"
exit 1
}

$PkgProperties = Get-PkgProperties -PackageName $PackageName -ServiceDirectory $ServiceDirectory
Expand All @@ -57,21 +62,21 @@ if ($ChangeLogEntries.Contains($Version))
{
if ($ChangeLogEntries[$Version].ReleaseStatus -eq $ReleaseStatus)
{
LogWarning "Version is already present in change log with specificed ReleaseStatus [$ReleaseStatus]"
LogWarning "Version [$Version] is already present in change log with specificed ReleaseStatus [$ReleaseStatus]. No Change made."
exit(0)
}

if ($Unreleased -and ($ChangeLogEntries[$Version].ReleaseStatus -ne $ReleaseStatus))
{
LogWarning "Version is already present in change log with a release date. Please review [$($PkgProperties.ChangeLogPath)]"
LogWarning "Version [$Version] is already present in change log with a release date. Please review [$($PkgProperties.ChangeLogPath)]. No Change made."
exit(0)
}

if (!$Unreleased -and ($ChangeLogEntries[$Version].ReleaseStatus -ne $CHANGELOG_UNRELEASED_STATUS))
{
if ((Get-Date ($ChangeLogEntries[$Version].ReleaseStatus).Trim("()")) -gt (Get-Date $ReleaseStatus.Trim("()")))
{
LogWarning "New ReleaseDate for version [$Version] is older than existing release date in changelog. Please review [$($PkgProperties.ChangeLogPath)]"
LogWarning "New ReleaseDate for version [$Version] is older than existing release date in changelog. Please review [$($PkgProperties.ChangeLogPath)]. No Change made."
exit(0)
}
}
Expand All @@ -80,40 +85,44 @@ if ($ChangeLogEntries.Contains($Version))
$PresentVersionsSorted = [AzureEngSemanticVersion]::SortVersionStrings($ChangeLogEntries.Keys)
$LatestVersion = $PresentVersionsSorted[0]

LogDebug "The latest release note entry in the changelog is for version [$($LatestVersion)]"

$LatestsSorted = [AzureEngSemanticVersion]::SortVersionStrings(@($LatestVersion, $Version))
if ($LatestsSorted[0] -ne $Version) {
LogWarning "Passed Version [$Version] is older than the latestversion [$LatestVersion] in the changelog. Please use a more recent version."
LogWarning "Version [$Version] is older than the latestversion [$LatestVersion] in the changelog. Please use a more recent version."
exit(0)
}

if ($ReplaceLatestEntry)
if ($ReplaceLatestEntryTitle)
{
$newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus -Content $ChangeLogEntries[$LatestVersion].ReleaseContent
LogDebug "Resetting latest entry title to [$($newChangeLogEntry.ReleaseTitle)]"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why LogDebug here as opposed to a standard log message?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could make it the standard output. Just the LogDebug is colored blue on DevOps which looks quite better, that's the only reason am using it here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I guess LogDebug just didn't seem right in my head as I associated it with Write-Debug which will not write anything unless Debug preference is setup. We may want to think about the naming that function a little more.

$ChangeLogEntries.Remove($LatestVersion)
$newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus
if ($newChangeLogEntry) {
$ChangeLogEntries[$Version] = $newChangeLogEntry
}
else {
LogError "Failed to create new changelog entry"
exit 1
}
}
elseif ($ChangeLogEntries.Contains($Version))
{
$ChangeLogEntries[$Version].ReleaseVersion = $Version
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if there was any reason why ReleaseVersion wouldn't match Version? Did we used to set it when we didn't need to?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ReleaseVersion should be the same as the Version in the title of the Release Entry. Its just that its named ReleaseVersion in the object returned from the ChangeLog operation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok if there is no case were we need to update it then I'm fine with removing this.

LogDebug "Updating ReleaseStatus for Version [$Version] to [$($ReleaseStatus)]"
$ChangeLogEntries[$Version].ReleaseStatus = $ReleaseStatus
$ChangeLogEntries[$Version].ReleaseTitle = "## $Version $ReleaseStatus"
}
else
else
{
LogDebug "Adding new ChangeLog entry for Version [$Version]"
$newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus
if ($newChangeLogEntry) {
$ChangeLogEntries[$Version] = $newChangeLogEntry
}
else {
LogError "Failed to create new changelog entry"
exit 1
}
}

Set-ChangeLogContent -ChangeLogLocation $PkgProperties.ChangeLogPath -ChangeLogEntries $ChangeLogEntries


Set-ChangeLogContent -ChangeLogLocation $PkgProperties.ChangeLogPath -ChangeLogEntries $ChangeLogEntries