Skip to content

Commit

Permalink
Support calculating and setting release date (#14876)
Browse files Browse the repository at this point in the history
* Support calculating and setting release date

* FB

* More FB

* Tuesday
  • Loading branch information
pakrym authored Sep 4, 2020
1 parent ae0a919 commit b208eea
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 14 deletions.
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,
[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"=[System.Net.WebUtility]::HtmlEncode($notes).Replace("`n", "<br>")
}

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

0 comments on commit b208eea

Please sign in to comment.