Skip to content

Commit 8bb488e

Browse files
authored
Sync eng/common directory with azure-sdk-tools repository (Azure#12447)
1 parent 379812f commit 8bb488e

File tree

4 files changed

+95
-55
lines changed

4 files changed

+95
-55
lines changed

eng/common/Update-Change-Log.ps1

Lines changed: 19 additions & 17 deletions
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]"

eng/common/scripts/Verify-ChangeLog.ps1

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,25 @@ $ProgressPreference = "SilentlyContinue"
1515
. (Join-Path $PSScriptRoot SemVer.ps1)
1616
Import-Module (Join-Path $PSScriptRoot modules ChangeLog-Operations.psm1)
1717

18-
if ((Test-Path $ChangeLogLocation) -and -not([System.String]::IsNullOrEmpty($VersionString)))
18+
$validChangeLog = $false
19+
if ($ChangeLogLocation -and $VersionString)
1920
{
20-
Confirm-ChangeLogEntry -ChangeLogLocation $ChangeLogLocation -VersionString $VersionString -ForRelease $ForRelease
21+
$validChangeLog = Confirm-ChangeLogEntry -ChangeLogLocation $ChangeLogLocation -VersionString $VersionString -ForRelease $ForRelease
2122
}
2223
else
2324
{
24-
Import-Module (Join-Path $PSScriptRoot modules Package-Properties.psm1)
25-
if ([System.String]::IsNullOrEmpty($Language))
26-
{
27-
$Language = $RepoName.Substring($RepoName.LastIndexOf('-') + 1)
28-
}
25+
Import-Module (Join-Path $PSScriptRoot modules Package-Properties.psm1)
26+
if ([System.String]::IsNullOrEmpty($Language))
27+
{
28+
$Language = $RepoName.Substring($RepoName.LastIndexOf('-') + 1)
29+
}
2930

30-
$PackageProp = Get-PkgProperties -PackageName $PackageName -ServiceName $ServiceName -Language $Language -RepoRoot $RepoRoot
31-
Confirm-ChangeLogEntry -ChangeLogLocation $PackageProp.pkgChangeLogPath -VersionString $PackageProp.pkgVersion -ForRelease $ForRelease
32-
}
31+
$PackageProp = Get-PkgProperties -PackageName $PackageName -ServiceName $ServiceName -Language $Language -RepoRoot $RepoRoot
32+
$validChangeLog = Confirm-ChangeLogEntry -ChangeLogLocation $PackageProp.pkgChangeLogPath -VersionString $PackageProp.pkgVersion -ForRelease $ForRelease
33+
}
34+
35+
if (!$validChangeLog) {
36+
exit 1
37+
}
38+
39+
exit 0

eng/common/scripts/modules/ChangeLog-Operations.psm1

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ function Get-ChangeLogEntries {
1111

1212
$changeLogEntries = @{}
1313
if (!(Test-Path $ChangeLogLocation)) {
14-
Write-Host "ChangeLog '{0}' was not found" -f $ChangeLogLocation
15-
exit 1
14+
Write-Error "ChangeLog[${ChangeLogLocation}] does not exist"
15+
return $null
1616
}
1717

1818
try {
@@ -51,14 +51,12 @@ function Get-ChangeLogEntry {
5151
[Parameter(Mandatory = $true)]
5252
[String]$VersionString
5353
)
54-
5554
$changeLogEntries = Get-ChangeLogEntries -ChangeLogLocation $ChangeLogLocation
5655

57-
if ($changeLogEntries.ContainsKey($VersionString)) {
56+
if ($changeLogEntries -and $changeLogEntries.ContainsKey($VersionString)) {
5857
return $changeLogEntries[$VersionString]
5958
}
60-
Write-Error "Release Notes for the Specified version ${VersionString} was not found"
61-
exit 1
59+
return $null
6260
}
6361

6462
#Returns the changelog for a particular version as string
@@ -70,9 +68,16 @@ function Get-ChangeLogEntryAsString {
7068
[String]$VersionString
7169
)
7270

73-
$changeLogEntries = Get-ChangeLogEntry -ChangeLogLocation $ChangeLogLocation -VersionString $VersionString
74-
[string]$releaseTitle = $changeLogEntries.ReleaseTitle
75-
[string]$releaseContent = $changeLogEntries.ReleaseContent -Join [Environment]::NewLine
71+
$changeLogEntry = Get-ChangeLogEntry -ChangeLogLocation $ChangeLogLocation -VersionString $VersionString
72+
return ChangeLogEntryAsString $changeLogEntry
73+
}
74+
75+
function ChangeLogEntryAsString($changeLogEntry) {
76+
if (!$changeLogEntry) {
77+
return "[Missing change log entry]"
78+
}
79+
[string]$releaseTitle = $changeLogEntry.ReleaseTitle
80+
[string]$releaseContent = $changeLogEntry.ReleaseContent -Join [Environment]::NewLine
7681
return $releaseTitle, $releaseContent -Join [Environment]::NewLine
7782
}
7883

@@ -87,27 +92,33 @@ function Confirm-ChangeLogEntry {
8792

8893
$changeLogEntry = Get-ChangeLogEntry -ChangeLogLocation $ChangeLogLocation -VersionString $VersionString
8994

95+
if (!$changeLogEntry) {
96+
Write-Error "ChangeLog[${ChangeLogLocation}] does not have an entry for version ${VersionString}."
97+
return $false
98+
}
99+
100+
Write-Host "Found the following change log entry for version '${VersionString}' in [${ChangeLogLocation}]."
101+
Write-Host "-----"
102+
Write-Host (ChangeLogEntryAsString $changeLogEntry)
103+
Write-Host "-----"
104+
90105
if ([System.String]::IsNullOrEmpty($changeLogEntry.ReleaseStatus)) {
91-
Write-Host ("##[error]Changelog '{0}' has wrong release note title" -f $ChangeLogLocation)
92-
Write-Host "##[info]Ensure the release date is included i.e. (yyyy-MM-dd) or (Unreleased) if not yet released"
93-
exit 1
106+
Write-Error "Entry does not have a correct release status. Please ensure the status is set to a date '(yyyy-MM-dd)' or '(Unreleased)' if not yet released."
107+
return $false
94108
}
95109

96110
if ($ForRelease -eq $True) {
97111
if ($changeLogEntry.ReleaseStatus -eq "(Unreleased)") {
98-
Write-Host ("##[error]No release date set. Please set a release date with format 'yyyy-MM-dd' in the heading for version '{0}' in the changelog '{1}'." -f $VersionString, $ChangelogLocation)
99-
exit 1
112+
Write-Error "Entry has no release date set. Please ensure to set a release date with format 'yyyy-MM-dd'."
113+
return $false
100114
}
101115

102116
if ([System.String]::IsNullOrWhiteSpace($changeLogEntry.ReleaseContent)) {
103-
Write-Host ("##[error]Empty Release Notes for '{0}' in '{1}'" -f $VersionString, $ChangeLogLocation)
104-
Write-Host "##[info]Please ensure there is a release notes entry before releasing the package."
105-
exit 1
117+
Write-Error "Entry has no content. Please ensure to provide some content of what changed in this version."
118+
return $false
106119
}
107120
}
108-
109-
Write-Host $changeLogEntry.ReleaseTitle
110-
Write-Host $changeLogEntry.ReleaseContent
121+
return $true
111122
}
112123

113124
Export-ModuleMember -Function 'Get-ChangeLogEntries'

eng/common/scripts/modules/Package-Properties.psm1

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,32 @@
33
class PackageProps
44
{
55
[string]$pkgName
6-
[AzureEngSemanticVersion]$pkgVersion
6+
[string]$pkgVersion
77
[string]$pkgDirectoryPath
88
[string]$pkgServiceName
99
[string]$pkgReadMePath
1010
[string]$pkgChangeLogPath
11+
[string]$pkgGroup
1112

12-
PackageProps(
13+
PackageProps([string]$pkgName,[string]$pkgVersion,[string]$pkgDirectoryPath,[string]$pkgServiceName)
14+
{
15+
$this.Initialize($pkgName, $pkgVersion, $pkgDirectoryPath, $pkgServiceName)
16+
}
17+
18+
PackageProps([string]$pkgName,[string]$pkgVersion,[string]$pkgDirectoryPath,[string]$pkgServiceName,[string]$pkgGroup="")
19+
{
20+
$this.Initialize($pkgName, $pkgVersion, $pkgDirectoryPath, $pkgServiceName, $pkgGroup)
21+
}
22+
23+
hidden [void]Initialize(
1324
[string]$pkgName,
1425
[string]$pkgVersion,
1526
[string]$pkgDirectoryPath,
1627
[string]$pkgServiceName
1728
)
1829
{
1930
$this.pkgName = $pkgName
20-
$this.pkgVersion = [AzureEngSemanticVersion]::ParseVersionString($pkgVersion)
21-
if ($this.pkgVersion -eq $null)
22-
{
23-
Write-Error "Invalid version in $pkgDirectoryPath"
24-
}
31+
$this.pkgVersion = $pkgVersion
2532
$this.pkgDirectoryPath = $pkgDirectoryPath
2633
$this.pkgServiceName = $pkgServiceName
2734

@@ -43,6 +50,18 @@ class PackageProps
4350
$this.pkgChangeLogPath = $null
4451
}
4552
}
53+
54+
hidden [void]Initialize(
55+
[string]$pkgName,
56+
[string]$pkgVersion,
57+
[string]$pkgDirectoryPath,
58+
[string]$pkgServiceName,
59+
[string]$pkgGroup
60+
)
61+
{
62+
$this.Initialize($pkgName, $pkgVersion, $pkgDirectoryPath, $pkgServiceName)
63+
$this.pkgGroup = $pkgGroup
64+
}
4665
}
4766

4867
$ProgressPreference = "SilentlyContinue"
@@ -127,10 +146,11 @@ function Extract-JavaPkgProps ($pkgPath, $serviceName, $pkgName)
127146
$projectData.load($projectPath)
128147
$projectPkgName = $projectData.project.artifactId
129148
$pkgVersion = $projectData.project.version
149+
$pkgGroup = $projectData.project.groupId
130150

131151
if ($projectPkgName -eq $pkgName)
132152
{
133-
return [PackageProps]::new($pkgName, $pkgVersion.ToString(), $pkgPath, $serviceName)
153+
return [PackageProps]::new($pkgName, $pkgVersion.ToString(), $pkgPath, $serviceName, $pkgGroup)
134154
}
135155
}
136156
return $null

0 commit comments

Comments
 (0)