Sync eng/common directory with azure-sdk-tools for PR 7322 (#5176)

* Create new pipeline to create package work item

* Update powershell script to pass tag

* Fixes as per review comments

* Update as per review comments

* Login as az devops

* Create new entry point script to create package work item

* Load common ps module

* Add devops login step

* Pipe login token to devops login

* Pipe login token to devops login

* Add looging

* more logging

* Remove duplicate login from new script and add more logging

* More logging to debug create work item

* Remove script added for debugging

* Skip az interactive login when PAT is passed

* Remove debug logging

---------

Co-authored-by: praveenkuttappan <praveenkuttappan@gmail.com>
This commit is contained in:
Azure SDK Bot 2023-11-21 14:08:14 -08:00 committed by GitHub
parent 361a0199b8
commit 94fc220f77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 84 additions and 41 deletions

View File

@ -135,7 +135,7 @@ function BuildHashKey()
}
$parentWorkItems = @{}
function FindParentWorkItem($serviceName, $packageDisplayName, $outputCommand = $false, $ignoreReleasePlannerTests = $true)
function FindParentWorkItem($serviceName, $packageDisplayName, $outputCommand = $false, $ignoreReleasePlannerTests = $true, $tag = $null)
{
$key = BuildHashKey $serviceName $packageDisplayName
if ($key -and $parentWorkItems.ContainsKey($key)) {
@ -154,6 +154,9 @@ function FindParentWorkItem($serviceName, $packageDisplayName, $outputCommand =
else {
$serviceCondition = "[ServiceName] <> ''"
}
if ($tag) {
$serviceCondition += " AND [Tags] CONTAINS '${tag}'"
}
if($ignoreReleasePlannerTests){
$serviceCondition += " AND [Tags] NOT CONTAINS 'Release Planner App Test'"
}
@ -185,10 +188,10 @@ function FindParentWorkItem($serviceName, $packageDisplayName, $outputCommand =
$packageWorkItems = @{}
$packageWorkItemWithoutKeyFields = @{}
function FindLatestPackageWorkItem($lang, $packageName, $outputCommand = $true, $ignoreReleasePlannerTests = $true)
function FindLatestPackageWorkItem($lang, $packageName, $outputCommand = $true, $ignoreReleasePlannerTests = $true, $tag = $null)
{
# Cache all the versions of this package and language work items
$null = FindPackageWorkItem $lang $packageName -includeClosed $true -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests
$null = FindPackageWorkItem $lang $packageName -includeClosed $true -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests -tag $tag
$latestWI = $null
foreach ($wi in $packageWorkItems.Values)
@ -208,7 +211,7 @@ function FindLatestPackageWorkItem($lang, $packageName, $outputCommand = $true,
return $latestWI
}
function FindPackageWorkItem($lang, $packageName, $version, $outputCommand = $true, $includeClosed = $false, $ignoreReleasePlannerTests = $true)
function FindPackageWorkItem($lang, $packageName, $version, $outputCommand = $true, $includeClosed = $false, $ignoreReleasePlannerTests = $true, $tag = $null)
{
$key = BuildHashKeyNoNull $lang $packageName $version
if ($key -and $packageWorkItems.ContainsKey($key)) {
@ -254,6 +257,9 @@ function FindPackageWorkItem($lang, $packageName, $version, $outputCommand = $tr
if ($version) {
$query += " AND [PackageVersionMajorMinor] = '${version}'"
}
if ($tag) {
$query += " AND [Tags] CONTAINS '${tag}'"
}
if($ignoreReleasePlannerTests){
$query += " AND [Tags] NOT CONTAINS 'Release Planner App Test'"
}
@ -331,7 +337,8 @@ function CreateWorkItemParent($id, $parentId, $oldParentId, $outputCommand = $tr
Invoke-AzBoardsCmd "work-item relation add" $parameters $outputCommand | Out-Null
}
function CreateWorkItem($title, $type, $iteration, $area, $fields, $assignedTo, $parentId, $outputCommand = $true)
function CreateWorkItem($title, $type, $iteration, $area, $fields, $assignedTo, $parentId, $relatedId = $null, $outputCommand = $true, $tag = $null)
{
$parameters = $ReleaseDevOpsCommonParametersWithProject
$parameters += "--title", "`"${title}`""
@ -341,25 +348,51 @@ function CreateWorkItem($title, $type, $iteration, $area, $fields, $assignedTo,
if ($assignedTo) {
$parameters += "--assigned-to", "`"${assignedTo}`""
}
if ($tag)
{
if ($fields)
{
$fields += "`"System.Tags=${tag}`""
}
else
{
$parameters += "--fields"
$parameters += "`"System.Tags=${tag}`""
}
}
if ($fields) {
$parameters += "--fields"
$parameters += $fields
}
Write-Host "Creating work item"
$workItem = Invoke-AzBoardsCmd "work-item create" $parameters $outputCommand
if ($parentId) {
$parameters = $ReleaseDevOpsCommonParameters
$parameters += "--id", $workItem.id
$parameters += "--relation-type", "parent"
$parameters += "--target-id", $parentId
Invoke-AzBoardsCmd "work-item relation add" $parameters $outputCommand | Out-Null
Write-Host $workItem
$workItemId = $workItem.id
Write-Host "Created work item [$workItemId]."
if ($parentId)
{
CreateWorkItemRelation $workItemId $parentId "parent" $outputCommand
}
# Add a work item as related if given.
if ($relatedId)
{
CreateWorkItemRelation $workItemId $relatedId "Related" $outputCommand
}
return $workItem
}
function CreateWorkItemRelation($id, $relatedId, $relationType, $outputCommand = $true)
{
$parameters = $ReleaseDevOpsCommonParameters
$parameters += "--id", $id
$parameters += "--relation-type", $relationType
$parameters += "--target-id", $relatedId
Write-Host "Updating work item [$relatedId] as [$relationType] of [$id]."
Invoke-AzBoardsCmd "work-item relation add" $parameters $outputCommand | Out-Null
}
function UpdateWorkItem($id, $fields, $title, $state, $assignedTo, $outputCommand = $true)
{
$parameters = $ReleaseDevOpsCommonParameters
@ -387,12 +420,12 @@ function UpdatePackageWorkItemReleaseState($id, $state, $releaseType, $outputCom
return UpdateWorkItem -id $id -state $state -fields $fields -outputCommand $outputCommand
}
function FindOrCreateClonePackageWorkItem($lang, $pkg, $verMajorMinor, $allowPrompt = $false, $outputCommand = $false)
function FindOrCreateClonePackageWorkItem($lang, $pkg, $verMajorMinor, $allowPrompt = $false, $outputCommand = $false, $relatedId = $null, $tag= $null, $ignoreReleasePlannerTests = $true)
{
$workItem = FindPackageWorkItem -lang $lang -packageName $pkg.Package -version $verMajorMinor -includeClosed $true -outputCommand $outputCommand
$workItem = FindPackageWorkItem -lang $lang -packageName $pkg.Package -version $verMajorMinor -includeClosed $true -outputCommand $outputCommand -tag $tag -ignoreReleasePlannerTests $ignoreReleasePlannerTests
if (!$workItem) {
$latestVersionItem = FindLatestPackageWorkItem -lang $lang -packageName $pkg.Package -outputCommand $outputCommand
$latestVersionItem = FindLatestPackageWorkItem -lang $lang -packageName $pkg.Package -outputCommand $outputCommand -tag $tag -ignoreReleasePlannerTests $ignoreReleasePlannerTests
$assignedTo = "me"
$extraFields = @()
if ($latestVersionItem) {
@ -428,15 +461,13 @@ function FindOrCreateClonePackageWorkItem($lang, $pkg, $verMajorMinor, $allowPro
$packageInfo.ServiceName = $readInput
}
}
$workItem = CreateOrUpdatePackageWorkItem $lang $pkg $verMajorMinor -existingItem $null -assignedTo $assignedTo -extraFields $extraFields -outputCommand $outputCommand
$workItem = CreateOrUpdatePackageWorkItem $lang $pkg $verMajorMinor -existingItem $null -assignedTo $assignedTo -extraFields $extraFields -outputCommand $outputCommand -relatedId $relatedId -tag $tag -ignoreReleasePlannerTests $ignoreReleasePlannerTests
}
return $workItem
}
function CreateOrUpdatePackageWorkItem($lang, $pkg, $verMajorMinor, $existingItem, $assignedTo = $null, $extraFields = $null, $outputCommand = $true)
function CreateOrUpdatePackageWorkItem($lang, $pkg, $verMajorMinor, $existingItem, $assignedTo = $null, $extraFields = $null, $outputCommand = $true, $relatedId = $null, $tag = $null, $ignoreReleasePlannerTests = $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]"
@ -495,23 +526,24 @@ function CreateOrUpdatePackageWorkItem($lang, $pkg, $verMajorMinor, $existingIte
}
}
$newparentItem = FindOrCreatePackageGroupParent $serviceName $pkgDisplayName -outputCommand $false
$newparentItem = FindOrCreatePackageGroupParent $serviceName $pkgDisplayName -outputCommand $false -tag $tag -ignoreReleasePlannerTests $ignoreReleasePlannerTests
UpdateWorkItemParent $existingItem $newParentItem -outputCommand $outputCommand
return $existingItem
}
$parentItem = FindOrCreatePackageGroupParent $serviceName $pkgDisplayName -outputCommand $false
$workItem = CreateWorkItem $title "Package" "Release" "Release" $fields $assignedTo $parentItem.id -outputCommand $outputCommand
$parentItem = FindOrCreatePackageGroupParent $serviceName $pkgDisplayName -outputCommand $false -tag $tag -ignoreReleasePlannerTests $ignoreReleasePlannerTests
Write-Host "Found product work item [$($parentItem.id)]. Creating package work item."
$workItem = CreateWorkItem $title "Package" "Release" "Release" $fields $assignedTo $parentItem.id -outputCommand $outputCommand -relatedId $relatedId -tag $tag
Write-Host "[$($workItem.id)]$lang - $pkgName($verMajorMinor) - Created"
return $workItem
}
function FindOrCreatePackageGroupParent($serviceName, $packageDisplayName, $outputCommand = $true, $ignoreReleasePlannerTests = $true)
function FindOrCreatePackageGroupParent($serviceName, $packageDisplayName, $outputCommand = $true, $ignoreReleasePlannerTests = $true, $tag = $null)
{
$existingItem = FindParentWorkItem $serviceName $packageDisplayName -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests
$existingItem = FindParentWorkItem $serviceName $packageDisplayName -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests -tag $tag
if ($existingItem) {
Write-Host "Found existing product work item [$($existingItem.id)]"
$newparentItem = FindOrCreateServiceParent $serviceName -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests
$newparentItem = FindOrCreateServiceParent $serviceName -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests -tag $tag
UpdateWorkItemParent $existingItem $newParentItem
return $existingItem
}
@ -520,8 +552,8 @@ function FindOrCreatePackageGroupParent($serviceName, $packageDisplayName, $outp
$fields += "`"PackageDisplayName=${packageDisplayName}`""
$fields += "`"ServiceName=${serviceName}`""
$fields += "`"Custom.EpicType=Product`""
$serviceParentItem = FindOrCreateServiceParent $serviceName -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests
$workItem = CreateWorkItem $packageDisplayName "Epic" "Release" "Release" $fields $null $serviceParentItem.id
$serviceParentItem = FindOrCreateServiceParent $serviceName -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests -tag $tag
$workItem = CreateWorkItem $packageDisplayName "Epic" "Release" "Release" $fields $null $serviceParentItem.id -tag $tag
$localKey = BuildHashKey $serviceName $packageDisplayName
Write-Host "[$($workItem.id)]$localKey - Created Parent"
@ -529,9 +561,9 @@ function FindOrCreatePackageGroupParent($serviceName, $packageDisplayName, $outp
return $workItem
}
function FindOrCreateServiceParent($serviceName, $outputCommand = $true, $ignoreReleasePlannerTests = $true)
function FindOrCreateServiceParent($serviceName, $outputCommand = $true, $ignoreReleasePlannerTests = $true, $tag = $null)
{
$serviceParent = FindParentWorkItem $serviceName -packageDisplayName $null -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests
$serviceParent = FindParentWorkItem $serviceName -packageDisplayName $null -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests -tag $tag
if ($serviceParent) {
Write-Host "Found existing service work item [$($serviceParent.id)]"
return $serviceParent
@ -542,7 +574,7 @@ function FindOrCreateServiceParent($serviceName, $outputCommand = $true, $ignore
$fields += "`"ServiceName=${serviceName}`""
$fields += "`"Custom.EpicType=Service`""
$parentId = $null
$workItem = CreateWorkItem $serviceName "Epic" "Release" "Release" $fields $null $parentId -outputCommand $outputCommand
$workItem = CreateWorkItem $serviceName "Epic" "Release" "Release" $fields $null $parentId -outputCommand $outputCommand -tag $tag
$localKey = BuildHashKey $serviceName
Write-Host "[$($workItem.id)]$localKey - Created service work item"

View File

@ -13,6 +13,8 @@ param(
[string]$packageRepoPath = "NA",
[string]$packageType = "client",
[string]$packageNewLibrary = "true",
[string]$relatedWorkItemId = $null,
[string]$tag = $null,
[string]$devops_pat = $env:DEVOPS_PAT
)
#Requires -Version 6.0
@ -23,15 +25,23 @@ if (!(Get-Command az -ErrorAction SilentlyContinue)) {
exit 1
}
az account show *> $null
if (!$?) {
Write-Host 'Running az login...'
az login *> $null
. (Join-Path $PSScriptRoot SemVer.ps1)
. (Join-Path $PSScriptRoot Helpers DevOps-WorkItem-Helpers.ps1)
if (!$devops_pat) {
az account show *> $null
if (!$?) {
Write-Host 'Running az login...'
az login *> $null
}
}
else {
# Login using PAT
LoginToAzureDevops $devops_pat
}
az extension show -n azure-devops *> $null
if (!$?){
Write-Host 'Installing azure-devops extension'
az extension add --name azure-devops
} else {
# Force update the extension to the latest version if it was already installed
@ -39,9 +49,6 @@ if (!$?){
az extension update -n azure-devops *> $null
}
. (Join-Path $PSScriptRoot SemVer.ps1)
. (Join-Path $PSScriptRoot Helpers DevOps-WorkItem-Helpers.ps1)
CheckDevOpsAccess
$parsedNewVersion = [AzureEngSemanticVersion]::new($version)
@ -69,8 +76,12 @@ $plannedVersions = @(
Date = $plannedDate
}
)
$ignoreReleasePlannerTests = $true
if ($tag -and $tag.Contains("Release Planner App Test")) {
$ignoreReleasePlannerTests = $false
}
$workItem = FindOrCreateClonePackageWorkItem $language $packageInfo $versionMajorMinor -allowPrompt $true -outputCommand $false
$workItem = FindOrCreateClonePackageWorkItem $language $packageInfo $versionMajorMinor -allowPrompt $true -outputCommand $false -relatedId $relatedWorkItemId -tag $tag -ignoreReleasePlannerTests $ignoreReleasePlannerTests
if (!$workItem) {
Write-Host "Something failed as we don't have a work-item so exiting."