Skip to content

Commit

Permalink
Sync Devops helper scripts from azure-sdk repo (Azure#15089)
Browse files Browse the repository at this point in the history
DevOps helper scripts were updated in azure-sdk repo
so syncing those changes into the tools repo so they
can be used prepare-release script.

Co-authored-by: Wes Haggard <Wes.Haggard@microsoft.com>
  • Loading branch information
azure-sdk and weshaggard authored Apr 29, 2021
1 parent 42da7f6 commit a18b7c9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 43 deletions.
32 changes: 29 additions & 3 deletions eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ function FindPackageWorkItem($lang, $packageName, $version, $outputCommand = $tr
$fields += "PackageBetaVersions"
$fields += "PackageGAVersion"
$fields += "PackagePatchVersions"
$fields += "Generated"
$fields += "RoadmapState"

$fieldList = ($fields | ForEach-Object { "[$_]"}) -join ", "
$query = "SELECT ${fieldList} FROM WorkItems WHERE [Work Item Type] = 'Package'"
Expand Down Expand Up @@ -295,13 +297,14 @@ function UpdatePackageWorkItemReleaseState($id, $state, $releaseType, $outputCom
return UpdateWorkItem -id $id -state $state -fields $fields -outputCommand $outputCommand
}

function FindOrCreateClonePackageWorkItem($lang, $pkg, $verMajorMinor, $outputCommand = $false)
function FindOrCreateClonePackageWorkItem($lang, $pkg, $verMajorMinor, $allowPrompt = $false, $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"
$extraFields = @()
if ($latestVersionItem) {
Write-Verbose "Copying data from latest matching [$($latestVersionItem.id)] with version $($latestVersionItem.fields["Custom.PackageVersionMajorMinor"])"
if ($latestVersionItem.fields["System.AssignedTo"]) {
Expand All @@ -312,14 +315,33 @@ function FindOrCreateClonePackageWorkItem($lang, $pkg, $verMajorMinor, $outputCo
if (!$pkg.RepoPath -and $pkg.RepoPath -ne "NA" -and $pkg.fields["Custom.PackageRepoPath"]) {
$pkg.RepoPath = $pkg.fields["Custom.PackageRepoPath"]
}

$extraFields += "`"Generated=" + $latestVersionItem.fields["Custom.Generated"] + "`""
$extraFields += "`"RoadmapState=" + $latestVersionItem.fields["Custom.RoadmapState"] + "`""
}

if ($allowPrompt) {
if (!$pkg.DisplayName) {
Write-Host "We need a package display name to be used in various places and it should be consistent across languages for similar packages."
while (($readInput = Read-Host -Prompt "Input the display name") -eq "") { }
$packageInfo.DisplayName = $readInput
}

if (!$pkg.ServiceName) {
Write-Host "We need a package service name to be used in various places and it should be consistent across languages for similar packages."
while (($readInput = Read-Host -Prompt "Input the service name") -eq "") { }
$packageInfo.ServiceName = $readInput
}
}
$workItem = CreateOrUpdatePackageWorkItem $lang $pkg $verMajorMinor -existingItem $null -assignedTo $assignedTo -outputCommand $outputCommand


$workItem = CreateOrUpdatePackageWorkItem $lang $pkg $verMajorMinor -existingItem $null -assignedTo $assignedTo -extraFields $extraFields -outputCommand $outputCommand
}

return $workItem
}

function CreateOrUpdatePackageWorkItem($lang, $pkg, $verMajorMinor, $existingItem, $assignedTo = $null, $outputCommand = $true)
function CreateOrUpdatePackageWorkItem($lang, $pkg, $verMajorMinor, $existingItem, $assignedTo = $null, $extraFields = $null, $outputCommand = $true)
{
if (!$lang -or !$pkg -or !$verMajorMinor) {
Write-Host "Cannot create or update because one of lang, pkg or verMajorMinor aren't set. [$lang|$($pkg.Package)|$verMajorMinor]"
Expand All @@ -343,6 +365,10 @@ function CreateOrUpdatePackageWorkItem($lang, $pkg, $verMajorMinor, $existingIte
$fields += "`"ServiceName=${serviceName}`""
$fields += "`"PackageRepoPath=${pkgRepoPath}`""

if ($extraFields) {
$fields += $extraFields
}

if ($existingItem)
{
$changedField = $null
Expand Down
51 changes: 11 additions & 40 deletions eng/common/scripts/Update-DevOps-Release-WorkItem.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,51 +58,22 @@ $plannedVersions = @(
}
)

$workItem = FindPackageWorkItem -lang $language -packageName $packageName -version $versionMajorMinor -includeClosed $true -outputCommand $false

if (!$workItem) {
$latestVersionItem = FindLatestPackageWorkItem -lang $language -packageName $packageName -outputCommand $false
$assignedTo = "me"
if ($latestVersionItem) {
Write-Host "Copying data from latest matching [$($latestVersionItem.id)] with version $($latestVersionItem.fields["Custom.PackageVersionMajorMinor"])"
if ($latestVersionItem.fields["System.AssignedTo"]) {
$assignedTo = $latestVersionItem.fields["System.AssignedTo"]["uniqueName"]
}
$packageInfo.DisplayName = $latestVersionItem.fields["Custom.PackageDisplayName"]
$packageInfo.ServiceName = $latestVersionItem.fields["Custom.ServiceName"]
if (!$packageInfo.RepoPath -and $packageInfo.RepoPath -ne "NA" -and $packageInfo.fields["Custom.PackageRepoPath"]) {
$packageInfo.RepoPath = $packageInfo.fields["Custom.PackageRepoPath"]
}
}

Write-Host "Creating a release work item for a package release with the following properties:"
Write-Host " Lanuage: $language"
Write-Host " Version: $versionMajorMinor"
Write-Host " Package: $packageName"
Write-Host " AssignedTo: $assignedTo"

if (!$packageInfo.DisplayName) {
Write-Host "We need a package display name to be used in various places and it should be consistent across languages for similar packages."
while (($readInput = Read-Host -Prompt "Input the display name") -eq "") { }
$packageInfo.DisplayName = $readInput
}
Write-Host " PackageDisplayName: $($packageInfo.DisplayName)"

if (!$packageInfo.ServiceName) {
Write-Host "We need a package service name to be used in various places and it should be consistent across languages for similar packages."
while (($readInput = Read-Host -Prompt "Input the service name") -eq "") { }
$packageInfo.ServiceName = $readInput
}
Write-Host " ServiceName: $($packageInfo.ServiceName)"
Write-Host " PackageType: $packageType"

$workItem = CreateOrUpdatePackageWorkItem -lang $language -pkg $packageInfo -verMajorMinor $versionMajorMinor -assignedTo $assignedTo -outputCommand $false
}
$workItem = FindOrCreateClonePackageWorkItem $language $packageInfo $versionMajorMinor -allowPrompt $true -outputCommand $false

if (!$workItem) {
Write-Host "Something failed as we don't have a work-item so exiting."
exit 1
}

Write-Host "Updated or created a release work item for a package release with the following properties:"
Write-Host " Lanuage: $($workItem.fields['Custom.Language'])"
Write-Host " Version: $($workItem.fields['Custom.PackageVersionMajorMinor'])"
Write-Host " Package: $($workItem.fields['Custom.Package'])"
Write-Host " AssignedTo: $($workItem.fields['System.AssignedTo']["uniqueName"])"
Write-Host " PackageDisplayName: $($workItem.fields['Custom.PackageDisplayName'])"
Write-Host " ServiceName: $($workItem.fields['Custom.ServiceName'])"
Write-Host " PackageType: $($workItem.fields['Custom.PackageType'])"
Write-Host ""
Write-Host "Marking item [$($workItem.id)]$($workItem.fields['System.Title']) as '$state' for '$releaseType'"
$updatedWI = UpdatePackageWorkItemReleaseState -id $workItem.id -state "In Release" -releaseType $releaseType -outputCommand $false
$updatedWI = UpdatePackageVersions $workItem -plannedVersions $plannedVersions
Expand Down

0 comments on commit a18b7c9

Please sign in to comment.