Skip to content

Commit 502e098

Browse files
azure-sdkraych1
andauthored
Sync eng/common directory with azure-sdk-tools for PR 12478 (#53271)
* Updated validate pkg template to use packageInfo * Fixed typo * Fixed the right variable to use * output debug log * Fixed errors in expression evaluation * removed debug code * Fixed an issue in pipeline * Updated condition for variable setting step * Join paths of the script path * Use join-path * return from the function rather than exit --------- Co-authored-by: ray chen <[email protected]>
1 parent 13f9e93 commit 502e098

File tree

4 files changed

+438
-50
lines changed

4 files changed

+438
-50
lines changed

eng/common/pipelines/templates/steps/validate-all-packages.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
parameters:
2-
ArtifactPath: $(Build.ArtifactStagingDirectory)
3-
Artifacts: []
4-
ConfigFileDir: $(Build.ArtifactStagingDirectory)/PackageInfo
2+
- name: ArtifactPath
3+
type: string
4+
default: $(Build.ArtifactStagingDirectory)
5+
- name: Artifacts
6+
type: object
7+
default: []
8+
- name: ConfigFileDir
9+
type: string
10+
default: $(Build.ArtifactStagingDirectory)/PackageInfo
11+
- name: PackageInfoFiles
12+
type: object
13+
default: []
514

615
steps:
716
- ${{ if and(ne(variables['Skip.PackageValidation'], 'true'), and(ne(variables['Build.Reason'], 'PullRequest'), eq(variables['System.TeamProject'], 'internal'))) }}:
817
- pwsh: |
918
echo "##vso[task.setvariable variable=SetAsReleaseBuild]false"
1019
displayName: "Set as release build"
11-
condition: and(succeeded(), eq(variables['SetAsReleaseBuild'], ''))
20+
condition: and(succeededOrFailed(), eq(variables['SetAsReleaseBuild'], ''))
1221
1322
- task: AzureCLI@2
1423
inputs:
@@ -24,7 +33,8 @@ steps:
2433
-ConfigFileDir '${{ parameters.ConfigFileDir }}' `
2534
-BuildDefinition $(System.CollectionUri)$(System.TeamProject)/_build?definitionId=$(System.DefinitionId) `
2635
-PipelineUrl $(System.CollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId) `
27-
-IsReleaseBuild $$(SetAsReleaseBuild)
36+
-IsReleaseBuild $$(SetAsReleaseBuild) `
37+
-PackageInfoFiles ('${{ convertToJson(parameters.PackageInfoFiles) }}' | ConvertFrom-Json -NoEnumerate)
2838
workingDirectory: $(Pipeline.Workspace)
2939
displayName: Validate packages and update work items
3040
continueOnError: true

eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1

Lines changed: 137 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11

2+
. (Join-Path $PSScriptRoot .. SemVer.ps1)
3+
24
$ReleaseDevOpsOrgParameters = @("--organization", "https://dev.azure.com/azure-sdk")
35
$ReleaseDevOpsCommonParameters = $ReleaseDevOpsOrgParameters + @("--output", "json")
46
$ReleaseDevOpsCommonParametersWithProject = $ReleaseDevOpsCommonParameters + @("--project", "Release")
57

8+
# This is used to determine whether or not the az login and azure-devops extension
9+
# install have already been completed.
10+
$global:AzLoginAndDevOpsExtensionInstallComplete = $false
11+
$global:HasDevOpsAccess = $false
12+
613
function Get-DevOpsRestHeaders()
714
{
815
# Get a temp access token from the logged in az cli user for azure devops resource
@@ -17,17 +24,44 @@ function Get-DevOpsRestHeaders()
1724
return $headers
1825
}
1926

27+
# Function was created from the same code being in Update-DevOps-Release-WorkItem.ps1
28+
# and Validate-Package.ps1. The global variable is used to prevent az commands from
29+
# being rerun multiple times
30+
function CheckAzLoginAndDevOpsExtensionInstall()
31+
{
32+
if (-not $global:AzLoginAndDevOpsExtensionInstallComplete) {
33+
az account show *> $null
34+
if (!$?) {
35+
Write-Host 'Running az login...'
36+
az login *> $null
37+
}
38+
39+
az extension show -n azure-devops *> $null
40+
if (!$?){
41+
az extension add --name azure-devops
42+
} else {
43+
# Force update the extension to the latest version if it was already installed
44+
# this is needed to ensure we have the authentication issue fixed from earlier versions
45+
az extension update -n azure-devops *> $null
46+
}
47+
$global:AzLoginAndDevOpsExtensionInstallComplete = $true
48+
}
49+
}
50+
2051
function CheckDevOpsAccess()
2152
{
22-
# Dummy test query to validate permissions
23-
$query = "SELECT [System.ID] FROM WorkItems WHERE [Work Item Type] = 'Package' AND [Package] = 'azure-sdk-template'"
53+
if (-not $global:HasDevOpsAccess) {
54+
# Dummy test query to validate permissions
55+
$query = "SELECT [System.ID] FROM WorkItems WHERE [Work Item Type] = 'Package' AND [Package] = 'azure-sdk-template'"
2456

25-
$response = Invoke-RestMethod -Method POST `
26-
-Uri "https://dev.azure.com/azure-sdk/Release/_apis/wit/wiql/?api-version=6.0" `
27-
-Headers (Get-DevOpsRestHeaders) -Body "{ ""query"": ""$query"" }" -ContentType "application/json" | ConvertTo-Json -Depth 10 | ConvertFrom-Json -AsHashTable
57+
$response = Invoke-RestMethod -Method POST `
58+
-Uri "https://dev.azure.com/azure-sdk/Release/_apis/wit/wiql/?api-version=6.0" `
59+
-Headers (Get-DevOpsRestHeaders) -Body "{ ""query"": ""$query"" }" -ContentType "application/json" | ConvertTo-Json -Depth 10 | ConvertFrom-Json -AsHashTable
2860

29-
if ($response -isnot [HashTable] -or !$response.ContainsKey("workItems")) {
30-
throw "Failed to run test query against Azure DevOps. Please ensure you are logged into the public azure cloud. Consider running 'az logout' and then 'az login'."
61+
if ($response -isnot [HashTable] -or !$response.ContainsKey("workItems")) {
62+
throw "Failed to run test query against Azure DevOps. Please ensure you are logged into the public azure cloud. Consider running 'az logout' and then 'az login'."
63+
}
64+
$global:HasDevOpsAccess = $true
3165
}
3266
}
3367

@@ -1018,7 +1052,7 @@ function UpdateValidationStatus($pkgvalidationDetails, $BuildDefinition, $Pipeli
10181052

10191053
function Get-LanguageDevOpsName($LanguageShort)
10201054
{
1021-
switch ($LanguageShort.ToLower())
1055+
switch ($LanguageShort.ToLower())
10221056
{
10231057
"net" { return "Dotnet" }
10241058
"js" { return "JavaScript" }
@@ -1057,7 +1091,7 @@ function Get-ReleasePlanForPackage($packageName)
10571091
}
10581092

10591093
function Update-ReleaseStatusInReleasePlan($releasePlanWorkItemId, $status, $version)
1060-
{
1094+
{
10611095
$devopsFieldLanguage = Get-LanguageDevOpsName -LanguageShort $LanguageShort
10621096
if (!$devopsFieldLanguage)
10631097
{
@@ -1170,7 +1204,7 @@ function Get-TriagesForCPEXAttestation()
11701204
$query += " AND [Custom.ProductType] IN ('Feature', 'Offering', 'Sku')"
11711205

11721206
$workItems = Invoke-Query $fields $query
1173-
return $workItems
1207+
return $workItems
11741208
}
11751209

11761210
function Update-AttestationStatusInWorkItem($workItemId, $fieldName, $status)
@@ -1181,4 +1215,96 @@ function Update-AttestationStatusInWorkItem($workItemId, $fieldName, $status)
11811215
$workItem = UpdateWorkItem -id $workItemId -fields $fields
11821216
Write-Host "Updated attestation status for [$fieldName] in Work Item [$workItemId]"
11831217
return $true
1184-
}
1218+
}
1219+
1220+
# This function was originally the entirety of what was in Update-DevOps-Release-WorkItem.ps1
1221+
# and has been converted to a function.
1222+
function Update-DevOpsReleaseWorkItem {
1223+
param(
1224+
[Parameter(Mandatory=$true)]
1225+
[string]$language,
1226+
[Parameter(Mandatory=$true)]
1227+
[string]$packageName,
1228+
[Parameter(Mandatory=$true)]
1229+
[string]$version,
1230+
[string]$plannedDate,
1231+
[string]$serviceName = $null,
1232+
[string]$packageDisplayName = $null,
1233+
[string]$packageRepoPath = "NA",
1234+
[string]$packageType = "client",
1235+
[string]$packageNewLibrary = "true",
1236+
[string]$relatedWorkItemId = $null,
1237+
[string]$tag = $null,
1238+
[bool]$inRelease = $true
1239+
)
1240+
1241+
if (!(Get-Command az -ErrorAction SilentlyContinue)) {
1242+
Write-Error 'You must have the Azure CLI installed: https://aka.ms/azure-cli'
1243+
return $false
1244+
}
1245+
1246+
CheckAzLoginAndDevOpsExtensionInstall
1247+
1248+
CheckDevOpsAccess
1249+
1250+
$parsedNewVersion = [AzureEngSemanticVersion]::new($version)
1251+
$state = "In Release"
1252+
$releaseType = $parsedNewVersion.VersionType
1253+
$versionMajorMinor = "" + $parsedNewVersion.Major + "." + $parsedNewVersion.Minor
1254+
1255+
$packageInfo = [PSCustomObject][ordered]@{
1256+
Package = $packageName
1257+
DisplayName = $packageDisplayName
1258+
ServiceName = $serviceName
1259+
RepoPath = $packageRepoPath
1260+
Type = $packageType
1261+
New = $packageNewLibrary
1262+
};
1263+
1264+
if (!$plannedDate) {
1265+
$plannedDate = Get-Date -Format "MM/dd/yyyy"
1266+
}
1267+
1268+
$plannedVersions = @(
1269+
[PSCustomObject][ordered]@{
1270+
Type = $releaseType
1271+
Version = $version
1272+
Date = $plannedDate
1273+
}
1274+
)
1275+
$ignoreReleasePlannerTests = $true
1276+
if ($tag -and $tag.Contains("Release Planner App Test")) {
1277+
$ignoreReleasePlannerTests = $false
1278+
}
1279+
1280+
$workItem = FindOrCreateClonePackageWorkItem $language $packageInfo $versionMajorMinor -allowPrompt $true -outputCommand $false -relatedId $relatedWorkItemId -tag $tag -ignoreReleasePlannerTests $ignoreReleasePlannerTests
1281+
1282+
if (!$workItem) {
1283+
Write-Host "Something failed as we don't have a work-item so exiting."
1284+
return $false
1285+
}
1286+
1287+
Write-Host "Updated or created a release work item for a package release with the following properties:"
1288+
Write-Host " Language: $($workItem.fields['Custom.Language'])"
1289+
Write-Host " Version: $($workItem.fields['Custom.PackageVersionMajorMinor'])"
1290+
Write-Host " Package: $($workItem.fields['Custom.Package'])"
1291+
if ($workItem.fields['System.AssignedTo']) {
1292+
Write-Host " AssignedTo: $($workItem.fields['System.AssignedTo']["uniqueName"])"
1293+
}
1294+
else {
1295+
Write-Host " AssignedTo: unassigned"
1296+
}
1297+
Write-Host " PackageDisplayName: $($workItem.fields['Custom.PackageDisplayName'])"
1298+
Write-Host " ServiceName: $($workItem.fields['Custom.ServiceName'])"
1299+
Write-Host " PackageType: $($workItem.fields['Custom.PackageType'])"
1300+
Write-Host ""
1301+
if ($inRelease)
1302+
{
1303+
Write-Host "Marking item [$($workItem.id)]$($workItem.fields['System.Title']) as '$state' for '$releaseType'"
1304+
$updatedWI = UpdatePackageWorkItemReleaseState -id $workItem.id -state "In Release" -releaseType $releaseType -outputCommand $false
1305+
}
1306+
$updatedWI = UpdatePackageVersions $workItem -plannedVersions $plannedVersions
1307+
1308+
Write-Host "Release tracking item is at https://dev.azure.com/azure-sdk/Release/_workitems/edit/$($updatedWI.id)/"
1309+
return $true
1310+
}

eng/common/scripts/Prepare-Release.ps1

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Set-StrictMode -Version 3
5555

5656
. ${PSScriptRoot}\common.ps1
5757
. ${PSScriptRoot}\Helpers\ApiView-Helpers.ps1
58+
. ${PSScriptRoot}\Helpers\DevOps-WorkItem-Helpers.ps1
5859

5960
function Get-ReleaseDay($baseDate)
6061
{
@@ -141,18 +142,18 @@ if ($null -eq $newVersionParsed)
141142
exit 1
142143
}
143144

144-
&$EngCommonScriptsDir/Update-DevOps-Release-WorkItem.ps1 `
145-
-language $LanguageDisplayName `
146-
-packageName $packageProperties.Name `
147-
-version $newVersion `
148-
-plannedDate $releaseDateString `
149-
-packageRepoPath $packageProperties.serviceDirectory `
150-
-packageType $packageProperties.SDKType `
151-
-packageNewLibrary $packageProperties.IsNewSDK
152-
153-
if ($LASTEXITCODE -ne 0) {
154-
Write-Error "Updating of the Devops Release WorkItem failed."
155-
exit 1
145+
$result = Update-DevOpsReleaseWorkItem -language $LanguageDisplayName `
146+
-packageName $packageProperties.Name `
147+
-version $newVersion `
148+
-plannedDate $releaseDateString `
149+
-packageRepoPath $packageProperties.serviceDirectory `
150+
-packageType $packageProperties.SDKType `
151+
-packageNewLibrary $packageProperties.IsNewSDK
152+
153+
if (-not $result)
154+
{
155+
Write-Error "Update of the Devops Release WorkItem failed."
156+
exit 1
156157
}
157158

158159
# Check API status

0 commit comments

Comments
 (0)