azure-sdk-for-cpp/eng/common/scripts/Prepare-Release.ps1
Azure SDK Bot 02622fff74
Update Prepare-Release script (#1757)
- Remove BuildType parameter as we can default it from package properties
- Stop passing BuildType and GroupId and instead defaul them from package properties
- Enable StrictMode to help identify potential errors
- Start passing sdktype and isnewsdk properties to devops script
- Sync latest changes with devops work item to fix a couple bugs

Co-authored-by: Wes Haggard <Wes.Haggard@microsoft.com>
2021-02-26 18:46:42 -08:00

119 lines
3.2 KiB
PowerShell

#Requires -Version 6.0
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$PackageName,
[string]$ServiceDirectory,
[string]$ReleaseDate # Pass Date in the form MM/dd/yyyy"
)
Set-StrictMode -Version 3
. ${PSScriptRoot}\common.ps1
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'
$packageProperties = Get-PkgProperties -PackageName $PackageName -ServiceDirectory $serviceDirectory
if (!$packageProperties)
{
Write-Error "Could not find a package with name [ $packageName ], please verify the package name matches the exact name."
exit 1
}
Write-Host "Package Name [ $($packageProperties.Name) ]"
Write-Host "Source directory [ $serviceDirectory ]"
if (!$ReleaseDate)
{
$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]$ReleaseDate
}
$releaseDateString = $ParsedReleaseDate.ToString("MM/dd/yyyy")
$month = $ParsedReleaseDate.ToString("MMMM")
Write-Host
Write-Host "Assuming release is in $month with release date $releaseDateString" -ForegroundColor Green
$currentProjectVersion = $packageProperties.Version
$newVersion = Read-Host -Prompt "Input the new version, or press Enter to use use current project version '$currentProjectVersion'"
if (!$newVersion)
{
$newVersion = $currentProjectVersion;
}
$newVersionParsed = [AzureEngSemanticVersion]::ParseVersionString($newVersion)
if ($null -eq $newVersionParsed)
{
Write-Error "Invalid version $newVersion. Version must follow standard SemVer rules, see https://aka.ms/azsdk/engsys/packageversioning"
exit 1
}
if (Test-Path "Function:SetPackageVersion")
{
SetPackageVersion -PackageName $packageProperties.Name -Version $newVersion -ServiceDirectory $serviceDirectory -ReleaseDate $releaseDateString `
-PackageProperties $packageProperties
}
else
{
LogError "The function 'SetPackageVersion' was not found.`
Make sure it is present in eng/scripts/Language-Settings.ps1.`
See https://github.com/Azure/azure-sdk-tools/blob/master/doc/common/common_engsys.md#code-structure"
exit 1
}
&$EngCommonScriptsDir/Update-DevOps-Release-WorkItem.ps1 `
-language $LanguageDisplayName `
-packageName $packageProperties.Name `
-version $newVersion `
-plannedDate $releaseDateString `
-packageRepoPath $packageProperties.serviceDirectory `
-packageType $packageProperties.SDKType `
-packageNewLibrary $packageProperties.IsNewSDK
git diff -s --exit-code $packageProperties.DirectoryPath
if ($LASTEXITCODE -ne 0)
{
git status
Write-Host "Some changes were made to the repo source" -ForegroundColor Green
Write-Host "Submit a pull request with the necessary changes to the repo" -ForegroundColor Green
}