Skip to content

Commit e38a4fe

Browse files
authored
Sync eng/common directory with azure-sdk-tools repository (Azure#13315)
1 parent def94ad commit e38a4fe

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

eng/common/Update-Change-Log.ps1

+19-17
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ function Get-ChangelogPath($Path)
2727
{
2828
# Check if CHANGELOG.md is present in path
2929
$ChangeLogPath = Join-Path -Path $Path -ChildPath "CHANGELOG.md"
30-
if ((Test-Path -Path $ChangeLogPath) -eq $False){
30+
if ((Test-Path -Path $ChangeLogPath) -eq $False) {
3131
# Check if change log exists with name HISTORY.md
3232
$ChangeLogPath = Join-Path -Path $Path -ChildPath "HISTORY.md"
33-
if ((Test-Path -Path $ChangeLogPath) -eq $False){
33+
if ((Test-Path -Path $ChangeLogPath) -eq $False) {
3434
Write-Host "Change log is not found in path[$Path]"
3535
exit(1)
3636
}
@@ -45,7 +45,7 @@ function Get-VersionTitle($Version, $Unreleased)
4545
{
4646
# Generate version title
4747
$newVersionTitle = "## $Version $UNRELEASED_TAG"
48-
if ($Unreleased -eq $False){
48+
if ($Unreleased -eq $False) {
4949
$releaseDate = Get-Date -Format "(yyyy-MM-dd)"
5050
$newVersionTitle = "## $Version $releaseDate"
5151
}
@@ -67,10 +67,10 @@ function Get-NewChangeLog( [System.Collections.ArrayList]$ChangelogLines, $Versi
6767
# Version increment tool passes replaceversion as False and Unreleased as True
6868
$is_version_increment = $ReplaceVersion -eq $False -and $Unreleased -eq $True
6969

70-
for(; $Index -lt $ChangelogLines.Count; $Index++){
71-
if (Version-Matches($ChangelogLines[$Index])){
70+
for (; $Index -lt $ChangelogLines.Count; $Index++) {
71+
if (Version-Matches($ChangelogLines[$Index])) {
7272
# Find current title in change log
73-
if( -not $CurrentTitle){
73+
if( -not $CurrentTitle) {
7474
$CurrentTitle = $ChangelogLines[$Index]
7575
$CurrentIndex = $Index
7676
Write-Host "Current Version title: $CurrentTitle"
@@ -80,7 +80,7 @@ function Get-NewChangeLog( [System.Collections.ArrayList]$ChangelogLines, $Versi
8080
# update change log script is triggered for all packages with current version for Java ( or any language where version is maintained in common file)
8181
# and this can cause an issue if someone changes changelog manually to prepare for release without updating actual version in central version file
8282
# Do not add new line or replace existing title when version is already present and script is triggered to add new line
83-
if ($is_version_increment -and $ChangelogLines[$Index].Contains($Version)){
83+
if ($is_version_increment -and $ChangelogLines[$Index].Contains($Version)) {
8484
Write-Host "Version is already present in change log."
8585
exit(0)
8686
}
@@ -90,26 +90,24 @@ function Get-NewChangeLog( [System.Collections.ArrayList]$ChangelogLines, $Versi
9090
# Generate version title
9191
$newVersionTitle = Get-VersionTitle -Version $Version -Unreleased $Unreleased
9292

93-
if( $newVersionTitle -eq $CurrentTitle){
93+
if( $newVersionTitle -eq $CurrentTitle) {
9494
Write-Host "No change is required in change log. Version is already present."
9595
exit(0)
9696
}
9797

98-
99-
100-
if (($ReplaceVersion -eq $True) -and ($Unreleased -eq $False) -and (-not $CurrentTitle.Contains($UNRELEASED_TAG))){
98+
if (($ReplaceVersion -eq $True) -and ($Unreleased -eq $False) -and $CurrentTitle.Contains($version) -and (-not $CurrentTitle.Contains($UNRELEASED_TAG))) {
10199
Write-Host "Version is already present in change log with a release date."
102100
exit(0)
103101
}
104102

105103
# if current version title already has new version then we should replace title to update it
106-
if ($CurrentTitle.Contains($Version) -and $ReplaceVersion -eq $False){
104+
if ($CurrentTitle.Contains($Version) -and $ReplaceVersion -eq $False) {
107105
Write-Host "Version is already present in title. Updating version title"
108106
$ReplaceVersion = $True
109107
}
110108

111109
# if version is already found and not replacing then nothing to do
112-
if ($ReplaceVersion -eq $False){
110+
if ($ReplaceVersion -eq $False) {
113111
Write-Host "Adding version title $newVersionTitle"
114112
$ChangelogLines.insert($CurrentIndex, "")
115113
$ChangelogLines.insert($CurrentIndex, "")
@@ -121,24 +119,28 @@ function Get-NewChangeLog( [System.Collections.ArrayList]$ChangelogLines, $Versi
121119
$ChangelogLines[$CurrentIndex] = $newVersionTitle
122120
}
123121

124-
return $ChangelogLines
122+
return $ChangelogLines
125123
}
126124

127125

128126
# Make sure path is valid
129-
if ((Test-Path -Path $ChangeLogPath) -eq $False){
127+
if ((Test-Path -Path $ChangeLogPath) -eq $False) {
130128
Write-Host "Change log path is invalid. [$ChangeLogPath]"
131129
exit(1)
132130
}
133131

134132
# probe change log path if path is directory
135-
if (Test-Path -Path $ChangeLogPath -PathType Container)
136-
{
133+
if (Test-Path -Path $ChangeLogPath -PathType Container) {
137134
$ChangeLogPath = Get-ChangelogPath -Path $ChangeLogPath
138135
}
139136

140137
# Read current change logs and add/update version
141138
$ChangelogLines = [System.Collections.ArrayList](Get-Content -Path $ChangeLogPath)
139+
140+
if ($null -eq $ChangelogLines) {
141+
$ChangelogLines = @()
142+
}
143+
142144
$NewContents = Get-NewChangeLog -ChangelogLines $ChangelogLines -Version $Version -Unreleased $Unreleased -ReplaceVersion $ReplaceVersion
143145

144146
Write-Host "Writing change log to file [$ChangeLogPath]"

0 commit comments

Comments
 (0)