Skip to content

Commit

Permalink
More changeLog Logic Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
chidozieononiwu committed Oct 29, 2020
1 parent a544e40 commit 4e1082a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 24 deletions.
69 changes: 47 additions & 22 deletions eng/common/scripts/ChangeLog-Operations.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Common Changelog Operations
if (!(Test-Path Function:LogWarning)) { . "${PSScriptRoot}\logging.ps1" }

$RELEASE_TITLE_REGEX = "(?<releaseNoteTitle>^\#+.*(?<version>\b\d+\.\d+\.\d+([^0-9\s][^\s:]+)?)(\s(?<releaseStatus>\(Unreleased\)|\(\d{4}-\d{2}-\d{2}\)))?)"

Expand All @@ -22,7 +23,7 @@ function Get-ChangeLogEntries {
foreach ($line in $contents) {
if ($line -match $RELEASE_TITLE_REGEX) {
$changeLogEntry = New-ChangeLogEntry -Version $matches["version"] -Status $matches["releaseStatus"] `
-Title $line -Content @()
-Title $line
$changeLogEntries[$changeLogEntry.ReleaseVersion] = $changeLogEntry
}
else {
Expand Down Expand Up @@ -121,19 +122,35 @@ function Confirm-ChangeLogEntry {
function New-ChangeLogEntry {
param (
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]$Version,
[Parameter(Mandatory = $true)]
[ValidateScript({$_.StartsWith('(') -and $_.EndsWith(')')})]
[String]$Status,
[String]$Status="(Unreleased)",
[String]$Title,
[String[]]$Content
)

# Validate relase Status
$Status = $Status.Trim().Trim("()")
if ($Status -ne "Unreleased") {
$dateFormat = "yyyy-MM-dd"
$provider = [System.Globalization.CultureInfo]::InvariantCulture
try {
$Status = ([System.DateTime]::ParseExact($Status, $dateFormat, $provider)).ToString($dateFormat)
}
catch {
LogWarning "Invalid date [ $Status ] passed as status for Version [$Version]. Please use a valid date in the format '$dateFormat' or use '(Unreleased)'"
}
}

$Status = "($Status)"
if (!$Content) { $Content = @() }
if (!$Title) { $Title = "## $Version $Status" }

$newChangeLogEntry = [pscustomobject]@{
ReleaseVersion = $Version
ReleaseStatus = $Status
ReleaseTitle = If ($Title) { $Title } Else { "## $Version $Status"}
ReleaseContent = If ($Content) { $Content } Else { @("") }
ReleaseTitle = $Title
ReleaseContent = $Content
}

return $newChangeLogEntry
Expand All @@ -144,38 +161,48 @@ function Add-ChangeLogEntry {
[Parameter(Mandatory = $false)]
[Hashtable]$ChangeLogEntries,
[Parameter(Mandatory = $true)]
[String]$ChangeLogLocation,
[Parameter(Mandatory = $true)]
[String]$NewEntryVersion,
[String]$NewEntryReleaseStatus="(Unreleased)",
[String]$NewEntryContent=""
[String[]]$NewEntryContent=""
)

if ($ChangeLogEntries.Contains($NewEntryVersion))
{
LogError "This Changelog already contains this entry. Do you mean to edit the entry?"
exit 1
return
}

$newChangeLogEntry = New-ChangeLogEntry -Version $NewEntryVersion -Status $NewEntryReleaseStatus `
-Content $NewEntryContent
$ChangeLogEntries.Add($NewEntryVersion,$newChangeLogEntry)
return $ChangeLogEntries

$ChangeLogEntries

Set-ChangeLogContent -ChangeLogLocation $ChangeLogLocation -ChangeLogEntries $ChangeLogEntries
}

function Edit-ChangeLogEntry {
param (
[Parameter(Mandatory = $true)]
[Hashtable]$ChangeLogEntries,
[Parameter(Mandatory = $true)]
[String]$ChangeLogLocation,
[Parameter(Mandatory = $true)]
[string]$VersionToEdit,
[String]$NewEntryReleaseVersion,
[String]$NewEntryReleaseStatus,
[String]$NewEntryReleaseContent
[String[]]$NewEntryReleaseContent
)

if ($NewEntryReleaseVersion) { $ChangeLogEntries[$VersionToEdit].ReleaseVersion = $NewEntryReleaseVersion }
if ($NewEntryReleaseStatus) {$ChangeLogEntries[$VersionToEdit].ReleaseStatus = $NewEntryReleaseStatus }
if ($NewEntryReleaseContent) {$ChangeLogEntries[$VersionToEdit].ReleaseContent = $NewEntryReleaseContent }
return $ChangeLogEntries
if ($NewEntryReleaseStatus) { $ChangeLogEntries[$VersionToEdit].ReleaseStatus = $NewEntryReleaseStatus }
if ($NewEntryReleaseContent) { $ChangeLogEntries[$VersionToEdit].ReleaseContent = $NewEntryReleaseContent }

$ChangeLogEntries

Set-ChangeLogContent -ChangeLogLocation $ChangeLogLocation -ChangeLogEntries $ChangeLogEntries
}

function Set-ChangeLogContent {
Expand All @@ -186,24 +213,22 @@ function Set-ChangeLogContent {
$ChangeLogEntries
)

$changeLogContent = @()
$changeLogContent += "# Release History"

try {
[AzureEngSemanticVersion]
$var = [AzureEngSemanticVersion]
}
catch {
. "${PSScriptRoot}\SemVer.ps1."
. "${PSScriptRoot}\SemVer.ps1"
}

$changeLogContent = @()
$changeLogContent += "# Release History"
$changeLogContent += ""

$VersionsSorted = [AzureEngSemanticVersion]::SortVersionStrings($ChangeLogEntries.Keys)
foreach ($version in $VersionsSorted) {
$changeLogEntry = $ChangeLogEntries[$version]
$changeLogContent += $changeLogEntry.ReleaseTitle
foreach ($line in $changeLogEntry.ReleaseContent) {
$changeLogContent += $line
}
$changeLogContent += ""
$changeLogContent += $changeLogEntry.ReleaseContent
}

Set-Content -Path $ChangeLogLocation -Value $changeLogContent
Expand Down
2 changes: 1 addition & 1 deletion eng/common/scripts/Update-ChangeLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Begin {
if ($ReleaseDate)
{
try {
$ReleaseStatus = ([System.DateTime]::ParseExact($ReleaseDate, $dateFormat, $provider)).ToString($dateFormat)
$ReleaseStatus = "({0})" -f ([System.DateTime]::ParseExact($ReleaseDate, $dateFormat, $provider)).ToString($dateFormat)
}
catch {
LogError "Invalid Release date. Please use a valid date in the format '$dateFormat'"
Expand Down
2 changes: 1 addition & 1 deletion eng/pipelines/eng-common-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pr:
- eng/common

pool:
vmImage: windows-2019
vmImage: ubuntu-18.04

stages:
- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
Expand Down

0 comments on commit 4e1082a

Please sign in to comment.