From 3c52b479b196d82a8bfa79795c2437dcc78bf6dd Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Fri, 26 Feb 2021 18:46:39 -0800 Subject: [PATCH] Update Prepare-Release script (#14023) - 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 --- .../Helpers/DevOps-WorkItem-Helpers.ps1 | 68 +++++------ eng/common/scripts/Prepare-Release.ps1 | 111 ++++++++++-------- eng/common/scripts/common.ps1 | 4 +- eng/common/scripts/logging.ps1 | 7 +- 4 files changed, 95 insertions(+), 95 deletions(-) diff --git a/eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1 b/eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1 index 327366c7a917..367efb090cd8 100644 --- a/eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1 +++ b/eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1 @@ -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 diff --git a/eng/common/scripts/Prepare-Release.ps1 b/eng/common/scripts/Prepare-Release.ps1 index dded6a346343..1da047449e34 100644 --- a/eng/common/scripts/Prepare-Release.ps1 +++ b/eng/common/scripts/Prepare-Release.ps1 @@ -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) - - return $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 - } + $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 + $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 -} \ No newline at end of file + 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 +} diff --git a/eng/common/scripts/common.ps1 b/eng/common/scripts/common.ps1 index 8ccf27b0ba4f..52c6b9d48f41 100644 --- a/eng/common/scripts/common.ps1 +++ b/eng/common/scripts/common.ps1 @@ -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 } diff --git a/eng/common/scripts/logging.ps1 b/eng/common/scripts/logging.ps1 index 9b327fd81c19..5266d9614d67 100644 --- a/eng/common/scripts/logging.ps1 +++ b/eng/common/scripts/logging.ps1 @@ -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" } -} \ No newline at end of file +}