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>
This commit is contained in:
parent
fe2f0d6d85
commit
02622fff74
@ -127,7 +127,6 @@ function FindPackageWorkItem($lang, $packageName, $version, $outputCommand = $tr
|
||||
$fields += "ID"
|
||||
$fields += "State"
|
||||
$fields += "System.AssignedTo"
|
||||
$fields += "Microsoft.VSTS.Common.StateChangeDate"
|
||||
$fields += "Parent"
|
||||
$fields += "Language"
|
||||
$fields += "Package"
|
||||
@ -265,19 +264,6 @@ function CreateWorkItem($title, $type, $iteration, $area, $fields, $assignedTo,
|
||||
return $workItem
|
||||
}
|
||||
|
||||
function ResetWorkItemState($workItem, $resetState = $null, $outputCommand = $true)
|
||||
{
|
||||
if (!$resetState -or $resetState -eq "New") {
|
||||
$resetState = "Next Release Unknown"
|
||||
}
|
||||
if ($workItem.fields["System.State"] -ne $resetState)
|
||||
{
|
||||
Write-Verbose "Resetting state for [$($workItem.id)] from '$($workItem.fields['System.State'])' to '$resetState'"
|
||||
return UpdateWorkItem $workItem.id -state $resetState -outputCommand $outputCommand
|
||||
}
|
||||
return $workItem
|
||||
}
|
||||
|
||||
function UpdateWorkItem($id, $fields, $title, $state, $assignedTo, $outputCommand = $true)
|
||||
{
|
||||
$parameters = $ReleaseDevOpsCommonParameters
|
||||
@ -305,6 +291,30 @@ function UpdatePackageWorkItemReleaseState($id, $state, $releaseType, $outputCom
|
||||
return UpdateWorkItem -id $id -state $state -fields $fields -outputCommand $outputCommand
|
||||
}
|
||||
|
||||
function FindOrCreateClonePackageWorkItem($lang, $pkg, $verMajorMinor, $outputCommand = $false)
|
||||
{
|
||||
$workItem = FindPackageWorkItem -lang $lang -packageName $pkg.Package -version $verMajorMinor -includeClosed $true -outputCommand $outputCommand
|
||||
|
||||
if (!$workItem) {
|
||||
$latestVersionItem = FindLatestPackageWorkItem -lang $lang -packageName $pkg.Package -outputCommand $outputCommand
|
||||
$assignedTo = "me"
|
||||
if ($latestVersionItem) {
|
||||
Write-Verbose "Copying data from latest matching [$($latestVersionItem.id)] with version $($latestVersionItem.fields["Custom.PackageVersionMajorMinor"])"
|
||||
if ($latestVersionItem.fields["System.AssignedTo"]) {
|
||||
$assignedTo = $latestVersionItem.fields["System.AssignedTo"]["uniqueName"]
|
||||
}
|
||||
$pkg.DisplayName = $latestVersionItem.fields["Custom.PackageDisplayName"]
|
||||
$pkg.ServiceName = $latestVersionItem.fields["Custom.ServiceName"]
|
||||
if (!$pkg.RepoPath -and $pkg.RepoPath -ne "NA" -and $pkg.fields["Custom.PackageRepoPath"]) {
|
||||
$pkg.RepoPath = $pkg.fields["Custom.PackageRepoPath"]
|
||||
}
|
||||
}
|
||||
$workItem = CreateOrUpdatePackageWorkItem $lang $pkg $verMajorMinor -existingItem $null -assignedTo $assignedTo -outputCommand $outputCommand
|
||||
}
|
||||
|
||||
return $workItem
|
||||
}
|
||||
|
||||
function CreateOrUpdatePackageWorkItem($lang, $pkg, $verMajorMinor, $existingItem, $assignedTo = $null, $outputCommand = $true)
|
||||
{
|
||||
if (!$lang -or !$pkg -or !$verMajorMinor) {
|
||||
@ -347,14 +357,18 @@ function CreateOrUpdatePackageWorkItem($lang, $pkg, $verMajorMinor, $existingIte
|
||||
Write-Host "At least field $changedField ($($existingItem.fields[$changedField])) changed so updating."
|
||||
}
|
||||
|
||||
$beforeState = $existingItem.fields["System.State"]
|
||||
|
||||
if ($changedField) {
|
||||
$beforeState = $existingItem.fields["System.State"]
|
||||
|
||||
# Need to set to New to be able to update
|
||||
$existingItem = UpdateWorkItem -id $existingItem.id -fields $fields -title $title -state "New" -assignedTo $assignedTo -outputCommand $outputCommand
|
||||
Write-Host "[$($existingItem.id)]$lang - $pkgName($verMajorMinor) - Updated"
|
||||
|
||||
if ($beforeState -ne $existingItem.fields['System.State']) {
|
||||
Write-Verbose "Resetting state for [$($existingItem.id)] from '$($existingItem.fields['System.State'])' to '$beforeState'"
|
||||
$existingItem = UpdateWorkItem $existingItem.id -state $beforeState -outputCommand $outputCommand
|
||||
}
|
||||
}
|
||||
$existingItem = ResetWorkItemState $existingItem $beforeState -outputCommand $outputCommand
|
||||
|
||||
$newparentItem = FindOrCreatePackageGroupParent $serviceName $pkgDisplayName -outputCommand $false
|
||||
UpdateWorkItemParent $existingItem $newParentItem -outputCommand $outputCommand
|
||||
@ -363,7 +377,6 @@ function CreateOrUpdatePackageWorkItem($lang, $pkg, $verMajorMinor, $existingIte
|
||||
|
||||
$parentItem = FindOrCreatePackageGroupParent $serviceName $pkgDisplayName -outputCommand $false
|
||||
$workItem = CreateWorkItem $title "Package" "Release" "Release" $fields $assignedTo $parentItem.id -outputCommand $outputCommand
|
||||
$workItem = ResetWorkItemState $workItem -outputCommand $outputCommand
|
||||
Write-Host "[$($workItem.id)]$lang - $pkgName($verMajorMinor) - Created"
|
||||
return $workItem
|
||||
}
|
||||
@ -752,25 +765,6 @@ function UpdatePackageVersions($pkgWorkItem, $plannedVersions, $shippedVersions)
|
||||
"value": "$shippedPackages"
|
||||
}
|
||||
"@
|
||||
|
||||
# If we shipped a version after we set "In Release" state then reset the state to "Next Release Unknown"
|
||||
if ($pkgWorkItem.fields["System.State"] -eq "In Release")
|
||||
{
|
||||
$lastShippedDate = [DateTime]$newShippedVersions[0].Date
|
||||
$markedInReleaseDate = ([DateTime]$pkgWorkItem.fields["Microsoft.VSTS.Common.StateChangeDate"])
|
||||
|
||||
# We just shipped so lets set the state to "Next Release Unknown"
|
||||
if ($markedInReleaseDate -le $lastShippedDate)
|
||||
{
|
||||
$fieldUpdates += @'
|
||||
{
|
||||
"op": "replace",
|
||||
"path": "/fields/State",
|
||||
"value": "Next Release Unknown"
|
||||
}
|
||||
'@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Full merged version set
|
||||
|
||||
@ -2,60 +2,67 @@
|
||||
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]$PackageName,
|
||||
[string]$ServiceDirectory,
|
||||
[string]$ReleaseDate, # Pass Date in the form MM/dd/yyyy"
|
||||
[string]$BuildType # For Java
|
||||
[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)
|
||||
# Find first friday
|
||||
while ($baseDate.DayOfWeek -ne 5)
|
||||
{
|
||||
$baseDate = $baseDate.AddDays(1)
|
||||
}
|
||||
|
||||
return $baseDate;
|
||||
# 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));
|
||||
$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
|
||||
}
|
||||
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
|
||||
$ParsedReleaseDate = [datetime]$ReleaseDate
|
||||
}
|
||||
|
||||
$releaseDateString = $ParsedReleaseDate.ToString("MM/dd/yyyy")
|
||||
@ -70,40 +77,42 @@ $newVersion = Read-Host -Prompt "Input the new version, or press Enter to use us
|
||||
|
||||
if (!$newVersion)
|
||||
{
|
||||
$newVersion = $currentProjectVersion;
|
||||
$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
|
||||
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 `
|
||||
-BuildType $BuildType -GroupId $packageProperties.Group
|
||||
SetPackageVersion -PackageName $packageProperties.Name -Version $newVersion -ServiceDirectory $serviceDirectory -ReleaseDate $releaseDateString `
|
||||
-PackageProperties $packageProperties
|
||||
}
|
||||
else
|
||||
{
|
||||
LogError "The function 'SetPackageVersion' was not found.`
|
||||
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
|
||||
exit 1
|
||||
}
|
||||
|
||||
&$EngCommonScriptsDir/Update-DevOps-Release-WorkItem.ps1 `
|
||||
-language $LanguageDisplayName `
|
||||
-packageName $packageProperties.Name `
|
||||
-version $newVersion `
|
||||
-plannedDate $releaseDateString `
|
||||
-packageRepoPath $packageProperties.serviceDirectory
|
||||
-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
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
@ -25,12 +25,12 @@ if (Test-Path $EngScriptsLanguageSettings) {
|
||||
. $EngScriptsLanguageSettings
|
||||
}
|
||||
|
||||
if (-not $LanguageShort)
|
||||
if (!(Get-Variable -Name "LangaugeShort" -ValueOnly -ErrorAction "Ignore"))
|
||||
{
|
||||
$LangaugeShort = $Language
|
||||
}
|
||||
|
||||
if (-not $LanguageDisplayName)
|
||||
if (!(Get-Variable -Name "LanguageDisplayName" -ValueOnly -ErrorAction "Ignore"))
|
||||
{
|
||||
$LanguageDisplayName = $Language
|
||||
}
|
||||
|
||||
@ -1,7 +1,4 @@
|
||||
if (-not $isDevOpsRun)
|
||||
{
|
||||
$isDevOpsRun = ($null -ne $env:SYSTEM_TEAMPROJECTID)
|
||||
}
|
||||
$isDevOpsRun = ($null -ne $env:SYSTEM_TEAMPROJECTID)
|
||||
|
||||
function LogWarning
|
||||
{
|
||||
@ -37,4 +34,4 @@ function LogDebug
|
||||
{
|
||||
Write-Debug "$args"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user