From be79b11e7b0e0cd6b7759a6737d4d952fd458764 Mon Sep 17 00:00:00 2001 From: Wes Haggard Date: Thu, 15 Sep 2022 12:56:25 -0700 Subject: [PATCH] Sync the devops helper scripts between azure-sdk repo and tools repo This should fix https://github.com/Azure/azure-sdk-tools/issues/3538 as it will now upgrade the devops extension to the latest version which has the auth fix needed. --- .../Helpers/DevOps-WorkItem-Helpers.ps1 | 26 ++++++++++++++++--- .../Update-DevOps-Release-WorkItem.ps1 | 4 +++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1 b/eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1 index 07bd6f8848..534107bfbf 100644 --- a/eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1 +++ b/eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1 @@ -108,8 +108,8 @@ function LoginToAzureDevops([string]$devops_pat) if (!$devops_pat) { return } - $azCmdStr = "'$devops_pat' | az devops login $($ReleaseDevOpsOrgParameters -join ' ')" - Invoke-Expression $azCmdStr + # based on the docs at https://aka.ms/azure-devops-cli-auth the recommendation is to set this env variable to login + $env:AZURE_DEVOPS_EXT_PAT = $devops_pat } function BuildHashKeyNoNull() @@ -234,6 +234,7 @@ function FindPackageWorkItem($lang, $packageName, $version, $outputCommand = $tr $fields += "Custom.PackagePatchVersions" $fields += "Custom.Generated" $fields += "Custom.RoadmapState" + $fields += "Microsoft.VSTS.Common.StateChangeDate" $fieldList = ($fields | ForEach-Object { "[$_]"}) -join ", " $query = "SELECT ${fieldList} FROM WorkItems WHERE [Work Item Type] = 'Package'" @@ -466,7 +467,7 @@ function CreateOrUpdatePackageWorkItem($lang, $pkg, $verMajorMinor, $existingIte if ($pkgName -ne $existingItem.fields["Custom.Package"]) { $changedField = "Custom.Package" } if ($verMajorMinor -ne $existingItem.fields["Custom.PackageVersionMajorMinor"]) { $changedField = "Custom.PackageVersionMajorMinor" } if ($pkgDisplayName -ne $existingItem.fields["Custom.PackageDisplayName"]) { $changedField = "Custom.PackageDisplayName" } - if ($pkgType -ne $existingItem.fields["Custom.PackageType"]) { $changedField = "Custom.PackageType" } + if ($pkgType -ne [string]$existingItem.fields["Custom.PackageType"]) { $changedField = "Custom.PackageType" } if ($pkgNewLibrary -ne $existingItem.fields["Custom.PackageTypeNewLibrary"]) { $changedField = "Custom.PackageTypeNewLibrary" } if ($pkgRepoPath -ne $existingItem.fields["Custom.PackageRepoPath"]) { $changedField = "Custom.PackageRepoPath" } if ($serviceName -ne $existingItem.fields["Custom.ServiceName"]) { $changedField = "Custom.ServiceName" } @@ -884,6 +885,25 @@ 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/Update-DevOps-Release-WorkItem.ps1 b/eng/common/scripts/Update-DevOps-Release-WorkItem.ps1 index 34c7540062..cb96691b83 100644 --- a/eng/common/scripts/Update-DevOps-Release-WorkItem.ps1 +++ b/eng/common/scripts/Update-DevOps-Release-WorkItem.ps1 @@ -33,6 +33,10 @@ 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 + # this is needed to ensure we have the authentication issue fixed from earlier versions + az extension update -n azure-devops *> $null } . (Join-Path $PSScriptRoot SemVer.ps1)