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

Sync eng/common directory with azure-sdk-tools repository #12912

Merged
merged 1 commit into from
Jul 8, 2020
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
36 changes: 19 additions & 17 deletions eng/common/Update-Change-Log.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ function Get-ChangelogPath($Path)
{
# Check if CHANGELOG.md is present in path
$ChangeLogPath = Join-Path -Path $Path -ChildPath "CHANGELOG.md"
if ((Test-Path -Path $ChangeLogPath) -eq $False){
if ((Test-Path -Path $ChangeLogPath) -eq $False) {
# Check if change log exists with name HISTORY.md
$ChangeLogPath = Join-Path -Path $Path -ChildPath "HISTORY.md"
if ((Test-Path -Path $ChangeLogPath) -eq $False){
if ((Test-Path -Path $ChangeLogPath) -eq $False) {
Write-Host "Change log is not found in path[$Path]"
exit(1)
}
Expand All @@ -45,7 +45,7 @@ function Get-VersionTitle($Version, $Unreleased)
{
# Generate version title
$newVersionTitle = "## $Version $UNRELEASED_TAG"
if ($Unreleased -eq $False){
if ($Unreleased -eq $False) {
$releaseDate = Get-Date -Format "(yyyy-MM-dd)"
$newVersionTitle = "## $Version $releaseDate"
}
Expand All @@ -67,10 +67,10 @@ function Get-NewChangeLog( [System.Collections.ArrayList]$ChangelogLines, $Versi
# Version increment tool passes replaceversion as False and Unreleased as True
$is_version_increment = $ReplaceVersion -eq $False -and $Unreleased -eq $True

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

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



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

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

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

return $ChangelogLines
return $ChangelogLines
}


# Make sure path is valid
if ((Test-Path -Path $ChangeLogPath) -eq $False){
if ((Test-Path -Path $ChangeLogPath) -eq $False) {
Write-Host "Change log path is invalid. [$ChangeLogPath]"
exit(1)
}

# probe change log path if path is directory
if (Test-Path -Path $ChangeLogPath -PathType Container)
{
if (Test-Path -Path $ChangeLogPath -PathType Container) {
$ChangeLogPath = Get-ChangelogPath -Path $ChangeLogPath
}

# Read current change logs and add/update version
$ChangelogLines = [System.Collections.ArrayList](Get-Content -Path $ChangeLogPath)

if ($null -eq $ChangelogLines) {
$ChangelogLines = @()
}

$NewContents = Get-NewChangeLog -ChangelogLines $ChangelogLines -Version $Version -Unreleased $Unreleased -ReplaceVersion $ReplaceVersion

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