@@ -27,10 +27,10 @@ function Get-ChangelogPath($Path)
27
27
{
28
28
# Check if CHANGELOG.md is present in path
29
29
$ChangeLogPath = Join-Path - Path $Path - ChildPath " CHANGELOG.md"
30
- if ((Test-Path - Path $ChangeLogPath ) -eq $False ){
30
+ if ((Test-Path - Path $ChangeLogPath ) -eq $False ) {
31
31
# Check if change log exists with name HISTORY.md
32
32
$ChangeLogPath = Join-Path - Path $Path - ChildPath " HISTORY.md"
33
- if ((Test-Path - Path $ChangeLogPath ) -eq $False ){
33
+ if ((Test-Path - Path $ChangeLogPath ) -eq $False ) {
34
34
Write-Host " Change log is not found in path[$Path ]"
35
35
exit (1 )
36
36
}
@@ -45,7 +45,7 @@ function Get-VersionTitle($Version, $Unreleased)
45
45
{
46
46
# Generate version title
47
47
$newVersionTitle = " ## $Version $UNRELEASED_TAG "
48
- if ($Unreleased -eq $False ){
48
+ if ($Unreleased -eq $False ) {
49
49
$releaseDate = Get-Date - Format " (yyyy-MM-dd)"
50
50
$newVersionTitle = " ## $Version $releaseDate "
51
51
}
@@ -67,10 +67,10 @@ function Get-NewChangeLog( [System.Collections.ArrayList]$ChangelogLines, $Versi
67
67
# Version increment tool passes replaceversion as False and Unreleased as True
68
68
$is_version_increment = $ReplaceVersion -eq $False -and $Unreleased -eq $True
69
69
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 ])) {
72
72
# Find current title in change log
73
- if ( -not $CurrentTitle ){
73
+ if ( -not $CurrentTitle ) {
74
74
$CurrentTitle = $ChangelogLines [$Index ]
75
75
$CurrentIndex = $Index
76
76
Write-Host " Current Version title: $CurrentTitle "
@@ -80,7 +80,7 @@ function Get-NewChangeLog( [System.Collections.ArrayList]$ChangelogLines, $Versi
80
80
# update change log script is triggered for all packages with current version for Java ( or any language where version is maintained in common file)
81
81
# and this can cause an issue if someone changes changelog manually to prepare for release without updating actual version in central version file
82
82
# 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 )) {
84
84
Write-Host " Version is already present in change log."
85
85
exit (0 )
86
86
}
@@ -90,26 +90,24 @@ function Get-NewChangeLog( [System.Collections.ArrayList]$ChangelogLines, $Versi
90
90
# Generate version title
91
91
$newVersionTitle = Get-VersionTitle - Version $Version - Unreleased $Unreleased
92
92
93
- if ( $newVersionTitle -eq $CurrentTitle ){
93
+ if ( $newVersionTitle -eq $CurrentTitle ) {
94
94
Write-Host " No change is required in change log. Version is already present."
95
95
exit (0 )
96
96
}
97
97
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 ))) {
101
99
Write-Host " Version is already present in change log with a release date."
102
100
exit (0 )
103
101
}
104
102
105
103
# 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 ) {
107
105
Write-Host " Version is already present in title. Updating version title"
108
106
$ReplaceVersion = $True
109
107
}
110
108
111
109
# if version is already found and not replacing then nothing to do
112
- if ($ReplaceVersion -eq $False ){
110
+ if ($ReplaceVersion -eq $False ) {
113
111
Write-Host " Adding version title $newVersionTitle "
114
112
$ChangelogLines.insert ($CurrentIndex , " " )
115
113
$ChangelogLines.insert ($CurrentIndex , " " )
@@ -121,24 +119,28 @@ function Get-NewChangeLog( [System.Collections.ArrayList]$ChangelogLines, $Versi
121
119
$ChangelogLines [$CurrentIndex ] = $newVersionTitle
122
120
}
123
121
124
- return $ChangelogLines
122
+ return $ChangelogLines
125
123
}
126
124
127
125
128
126
# Make sure path is valid
129
- if ((Test-Path - Path $ChangeLogPath ) -eq $False ){
127
+ if ((Test-Path - Path $ChangeLogPath ) -eq $False ) {
130
128
Write-Host " Change log path is invalid. [$ChangeLogPath ]"
131
129
exit (1 )
132
130
}
133
131
134
132
# 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) {
137
134
$ChangeLogPath = Get-ChangelogPath - Path $ChangeLogPath
138
135
}
139
136
140
137
# Read current change logs and add/update version
141
138
$ChangelogLines = [System.Collections.ArrayList ](Get-Content - Path $ChangeLogPath )
139
+
140
+ if ($null -eq $ChangelogLines ) {
141
+ $ChangelogLines = @ ()
142
+ }
143
+
142
144
$NewContents = Get-NewChangeLog - ChangelogLines $ChangelogLines - Version $Version - Unreleased $Unreleased - ReplaceVersion $ReplaceVersion
143
145
144
146
Write-Host " Writing change log to file [$ChangeLogPath ]"
0 commit comments