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

Support calculating and setting release date #14876

Merged
merged 5 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
13 changes: 9 additions & 4 deletions eng/common/Update-Change-Log.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ param (
[Parameter(Mandatory = $true)]
[String]$ChangeLogPath,
[String]$Unreleased = $True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you declaring booleans as strings? PowerShell way is [switch] $Unreleased. Specifying it means $true, but you can pass :$false or :$true explicitly like -Unreleased:$false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave it as is for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes lets not change too much here currently. @chidozieononiwu does have issue Azure/azure-sdk-tools#829 which we will use as a clean-up effort for our various PS scripts.

[String]$ReplaceVersion = $False
[String]$ReplaceVersion = $False,
[String]$ReleaseDate
)


Expand Down Expand Up @@ -46,8 +47,12 @@ function Get-VersionTitle($Version, $Unreleased)
# Generate version title
$newVersionTitle = "## $Version $UNRELEASED_TAG"
if ($Unreleased -eq $False) {
$releaseDate = Get-Date -Format "(yyyy-MM-dd)"
$newVersionTitle = "## $Version $releaseDate"
$actualReleaseDate = $ReleaseDate;

if (!$actualReleaseDate) {
$actualReleaseDate = Get-Date -Format "yyyy-MM-dd"
}
$newVersionTitle = "## $Version ($actualReleaseDate)"
}
return $newVersionTitle
}
Expand Down Expand Up @@ -95,7 +100,7 @@ function Get-NewChangeLog( [System.Collections.ArrayList]$ChangelogLines, $Versi
exit(0)
}

if (($ReplaceVersion -eq $True) -and ($Unreleased -eq $False) -and $CurrentTitle.Contains($version) -and (-not $CurrentTitle.Contains($UNRELEASED_TAG))) {
if (($ReplaceVersion -eq $True) -and ($Unreleased -eq $False) -and $CurrentTitle.Contains($version) -and (-not $CurrentTitle.Contains($UNRELEASED_TAG)) -and (-not $ReleaseDate)) {
Write-Host "Version is already present in change log with a release date."
exit(0)
}
Expand Down
62 changes: 51 additions & 11 deletions eng/scripts/Prepare-Release.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
$package
[string]$package,
pakrym marked this conversation as resolved.
Show resolved Hide resolved
[string]$ReleaseDate
)

function Get-LevenshteinDistance {
Expand Down Expand Up @@ -74,6 +75,20 @@ function Get-LevenshteinDistance {
}
}

function Get-ReleaseDay($baseDate)
{
# Find first friday
while ($baseDate.DayOfWeek -ne 5)
{
$baseDate = $baseDate.AddDays(1)
}

# Go to Tuesday
$baseDate = $baseDate.AddDays(4)

return $baseDate;
}

$ErrorPreference = 'Stop'
$repoRoot = Resolve-Path "$PSScriptRoot/../..";

Expand Down Expand Up @@ -166,19 +181,43 @@ else
Write-Host
Write-Host "Detected released type $releaseType" -ForegroundColor Green

Write-Host
Write-Host "Updating versions" -ForegroundColor Green

& "$repoRoot\eng\scripts\Update-PkgVersion.ps1" -ServiceDirectory $serviceDirectory -PackageName $package -NewVersionString $newVersion

$date = Get-Date
$month = $date.ToString("MMMM")
if ($date.Day -gt 15)
if (!$ReleaseDate)
{
$month = $date.AddMonths(1).ToString("MMMM")
$currentDate = Get-Date
$thisMonthReleaseDate = Get-ReleaseDay((Get-Date -Day 1));
$nextMonthReleaseDate = Get-ReleaseDay((Get-Date -Day 1).AddMonths(1));

if ($thisMonthReleaseDate -ge $currentDate)
{
# On track for this month release
$ParsedReleaseDate = $thisMonthReleaseDate
}
elseif ($currentDate.Day -lt 15)
{
# Catching up to this month release
$ParsedReleaseDate = $currentDate
}
else
{
# Next month release
$ParsedReleaseDate = $nextMonthReleaseDate
}
}
else
{
$ParsedReleaseDate = [datetime]::ParseExact($ReleaseDate, 'yyyy-MM-dd', [Globalization.CultureInfo]::InvariantCulture)
}

$releaseDateString = $ParsedReleaseDate.ToString("yyyy-MM-dd")
$month = $ParsedReleaseDate.ToString("MMMM")

Write-Host
Write-Host "Assuming release is in $month with release date $releaseDateString" -ForegroundColor Green

Write-Host
Write-Host "Assuming release is in $month" -ForegroundColor Green
Write-Host "Updating versions" -ForegroundColor Green

& "$repoRoot\eng\scripts\Update-PkgVersion.ps1" -ServiceDirectory $serviceDirectory -PackageName $package -NewVersionString $newVersion -ReleaseDate $releaseDateString

$commonParameter = @("--organization", "https://dev.azure.com/azure-sdk", "-o", "json", "--only-show-errors")

Expand Down Expand Up @@ -219,6 +258,7 @@ $fields = @{
"Library Type"=$libraryType
"Release Type"=$releaseType
"Version Number"=$newVersion
"Planned Release Date"=$releaseDateString
"Notes"="<pre>"+$notes.Replace("`n", "<br>")+"</pre>"
}

Expand Down
10 changes: 7 additions & 3 deletions eng/scripts/Update-PkgVersion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Update-PkgVersion.ps1 -ServiceDirectory core -PackageName Azure.Core
Updating package version for Azure.Core with a specified verion
Update-PkgVersion.ps1 -ServiceDirectory core -PackageName Azure.Core -NewVersionString 2.0.5

Updating package version for Azure.Core with a specified verion and release date
Update-PkgVersion.ps1 -ServiceDirectory core -PackageName Azure.Core -NewVersionString 2.0.5 -ReleaseDate "2020-05-01"

Updating package version for Microsoft.Azure.CognitiveServices.AnomalyDetector
Update-PkgVersion.ps1 -ServiceDirectory cognitiveservices -PackageName Microsoft.Azure.CognitiveServices.AnomalyDetector -PackageDirName AnomalyDetector

Expand All @@ -42,7 +45,8 @@ Param (
[Parameter(Mandatory=$True)]
[string] $PackageName,
[string] $PackageDirName,
[string] $NewVersionString
[string] $NewVersionString,
[string] $ReleaseDate
)

. ${PSScriptRoot}\..\common\scripts\SemVer.ps1
Expand All @@ -68,7 +72,7 @@ if ([System.String]::IsNullOrEmpty($NewVersionString)) {
else {
$packageSemVer = [AzureEngSemanticVersion]::new($NewVersionString)

& "${PSScriptRoot}/../common/Update-Change-Log.ps1" -Version $packageSemVer.ToString() -ChangeLogPath $changeLogPath -Unreleased $false -ReplaceVersion $true
& "${PSScriptRoot}/../common/Update-Change-Log.ps1" -Version $packageSemVer.ToString() -ChangeLogPath $changeLogPath -Unreleased $false -ReplaceVersion $true -ReleaseDate $ReleaseDate
}

Write-Host "New Version: ${packageSemVer}"
Expand All @@ -77,7 +81,7 @@ if ($packageSemVer.HasValidPrereleaseLabel() -ne $true){
exit 1
}

if (!$packageOldSemVer.IsPrerelease) {
if (!$packageOldSemVer.IsPrerelease -and ($packageVersion -ne $NewVersionString)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't set ApiCompatVersion if it's the same.

if (!$propertyGroup.ApiCompatVersion) {
$propertyGroup.InsertAfter($csproj.CreateElement("ApiCompatVersion"), $propertyGroup["Version"]) | Out-Null
$whitespace = $propertyGroup["Version"].PreviousSibling
Expand Down