Skip to content

Commit 86747c4

Browse files
Sync eng/common directory with azure-sdk-tools for PR 8388 (Azure#44448)
* Removal of the devops release PAT * Don't pass in the access token, just use the AzureCLI task and do everything in the scripts * Updates for feedback --------- Co-authored-by: James Suplizio <[email protected]>
1 parent e7865a6 commit 86747c4

File tree

5 files changed

+46
-75
lines changed

5 files changed

+46
-75
lines changed

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@ steps:
1010
displayName: "Set as release build"
1111
condition: and(succeeded(), eq(variables['SetAsReleaseBuild'], ''))
1212
13-
- task: Powershell@2
13+
- task: AzureCLI@2
1414
inputs:
15-
filePath: $(Build.SourcesDirectory)/eng/common/scripts/Validate-All-Packages.ps1
16-
arguments: >
17-
-ArtifactList ('${{ convertToJson(parameters.Artifacts) }}' | ConvertFrom-Json | Select-Object Name)
18-
-ArtifactPath ${{ parameters.ArtifactPath }}
19-
-RepoRoot $(Build.SourcesDirectory)
20-
-APIKey $(azuresdk-apiview-apikey)
21-
-ConfigFileDir '${{ parameters.ConfigFileDir }}'
22-
-BuildDefinition $(System.CollectionUri)$(System.TeamProject)/_build?definitionId=$(System.DefinitionId)
23-
-PipelineUrl $(System.CollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)
24-
-Devops_pat '$(azuresdk-azure-sdk-devops-release-work-item-pat)'
25-
-IsReleaseBuild $$(SetAsReleaseBuild)
26-
pwsh: true
15+
azureSubscription: opensource-api-connection
16+
scriptType: pscore
17+
scriptLocation: inlineScript
18+
inlineScript: |
19+
$(Build.SourcesDirectory)/eng/common/scripts/Validate-All-Packages.ps1 `
20+
-ArtifactList ('${{ convertToJson(parameters.Artifacts) }}' | ConvertFrom-Json | Select-Object Name) `
21+
-ArtifactPath ${{ parameters.ArtifactPath }} `
22+
-RepoRoot $(Build.SourcesDirectory) `
23+
-APIKey $(azuresdk-apiview-apikey) `
24+
-ConfigFileDir '${{ parameters.ConfigFileDir }}' `
25+
-BuildDefinition $(System.CollectionUri)$(System.TeamProject)/_build?definitionId=$(System.DefinitionId) `
26+
-PipelineUrl $(System.CollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId) `
27+
-IsReleaseBuild $$(SetAsReleaseBuild)
2728
workingDirectory: $(Pipeline.Workspace)
2829
displayName: Validate packages and update work items
2930
continueOnError: true

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

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,15 @@ $ReleaseDevOpsCommonParametersWithProject = $ReleaseDevOpsCommonParameters + @("
55

66
function Get-DevOpsRestHeaders()
77
{
8-
$headers = $null
9-
if (Get-Variable -Name "devops_pat" -ValueOnly -ErrorAction "Ignore")
10-
{
11-
$encodedToken = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes([string]::Format("{0}:{1}", "", $devops_pat)))
12-
$headers = @{ Authorization = "Basic $encodedToken" }
13-
}
14-
else
15-
{
16-
# Get a temp access token from the logged in az cli user for azure devops resource
17-
$jwt_accessToken = (az account get-access-token --resource "499b84ac-1321-427f-aa17-267ca6975798" --query "accessToken" --output tsv)
18-
$headers = @{ Authorization = "Bearer $jwt_accessToken" }
8+
# Get a temp access token from the logged in az cli user for azure devops resource
9+
$headerAccessToken = (az account get-access-token --resource "499b84ac-1321-427f-aa17-267ca6975798" --query "accessToken" --output tsv)
10+
11+
if ([System.String]::IsNullOrEmpty($headerAccessToken)) {
12+
throw "Unable to create the DevOpsRestHeader due to access token being null or empty. The caller needs to be logged in with az login to an account with enough permissions to edit work items in the azure-sdk Release team project."
1913
}
2014

15+
$headers = @{ Authorization = "Bearer $headerAccessToken" }
16+
2117
return $headers
2218
}
2319

@@ -103,15 +99,6 @@ function Invoke-Query($fields, $wiql, $output = $true)
10399
return $workItems
104100
}
105101

106-
function LoginToAzureDevops([string]$devops_pat)
107-
{
108-
if (!$devops_pat) {
109-
return
110-
}
111-
# based on the docs at https://aka.ms/azure-devops-cli-auth the recommendation is to set this env variable to login
112-
$env:AZURE_DEVOPS_EXT_PAT = $devops_pat
113-
}
114-
115102
function BuildHashKeyNoNull()
116103
{
117104
$filterNulls = $args | Where-Object { $_ }
@@ -374,7 +361,7 @@ function CreateWorkItem($title, $type, $iteration, $area, $fields, $assignedTo,
374361
{
375362
CreateWorkItemRelation $workItemId $parentId "parent" $outputCommand
376363
}
377-
364+
378365
# Add a work item as related if given.
379366
if ($relatedId)
380367
{

eng/common/scripts/Update-DevOps-Release-WorkItem.ps1

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ param(
1515
[string]$packageNewLibrary = "true",
1616
[string]$relatedWorkItemId = $null,
1717
[string]$tag = $null,
18-
[string]$devops_pat = $env:DEVOPS_PAT,
1918
[bool]$inRelease = $true
2019
)
2120
#Requires -Version 6.0
@@ -29,16 +28,10 @@ if (!(Get-Command az -ErrorAction SilentlyContinue)) {
2928
. (Join-Path $PSScriptRoot SemVer.ps1)
3029
. (Join-Path $PSScriptRoot Helpers DevOps-WorkItem-Helpers.ps1)
3130

32-
if (!$devops_pat) {
33-
az account show *> $null
34-
if (!$?) {
35-
Write-Host 'Running az login...'
36-
az login *> $null
37-
}
38-
}
39-
else {
40-
# Login using PAT
41-
LoginToAzureDevops $devops_pat
31+
az account show *> $null
32+
if (!$?) {
33+
Write-Host 'Running az login...'
34+
az login *> $null
4235
}
4336

4437
az extension show -n azure-devops *> $null

eng/common/scripts/Validate-All-Packages.ps1

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Param (
1212
[string]$BuildDefinition,
1313
[string]$PipelineUrl,
1414
[string]$APIViewUri = "https://apiview.dev/AutoReview/GetReviewStatus",
15-
[string]$Devops_pat = $env:DEVOPS_PAT,
1615
[bool] $IsReleaseBuild = $false
1716
)
1817

@@ -33,8 +32,7 @@ function ProcessPackage($PackageName, $ConfigFileDir)
3332
-APIKey $APIKey `
3433
-BuildDefinition $BuildDefinition `
3534
-PipelineUrl $PipelineUrl `
36-
-ConfigFileDir $ConfigFileDir `
37-
-Devops_pat $Devops_pat
35+
-ConfigFileDir $ConfigFileDir
3836
if ($LASTEXITCODE -ne 0) {
3937
Write-Error "Failed to validate package $PackageName"
4038
exit 1

eng/common/scripts/Validate-Package.ps1

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@
22

33
[CmdletBinding()]
44
param (
5-
[Parameter(Mandatory = $true)]
5+
[Parameter(Mandatory = $true)]
66
[string] $PackageName,
7-
[Parameter(Mandatory = $true)]
7+
[Parameter(Mandatory = $true)]
88
[string] $ArtifactPath,
99
[Parameter(Mandatory=$True)]
1010
[string] $RepoRoot,
1111
[Parameter(Mandatory=$True)]
12-
[string] $APIKey,
12+
[string] $APIKey,
1313
[Parameter(Mandatory=$True)]
1414
[string] $ConfigFileDir,
1515
[string] $BuildDefinition,
1616
[string] $PipelineUrl,
1717
[string] $APIViewUri,
18-
[string] $Devops_pat = $env:DEVOPS_PAT,
1918
[bool] $IsReleaseBuild = $false
2019
)
2120
Set-StrictMode -Version 3
@@ -24,16 +23,10 @@ Set-StrictMode -Version 3
2423
. ${PSScriptRoot}\Helpers\ApiView-Helpers.ps1
2524
. ${PSScriptRoot}\Helpers\DevOps-WorkItem-Helpers.ps1
2625

27-
if (!$Devops_pat) {
28-
az account show *> $null
29-
if (!$?) {
30-
Write-Host 'Running az login...'
31-
az login *> $null
32-
}
33-
}
34-
else {
35-
# Login using PAT
36-
LoginToAzureDevops $Devops_pat
26+
az account show *> $null
27+
if (!$?) {
28+
Write-Host 'Running az login...'
29+
az login *> $null
3730
}
3831

3932
az extension show -n azure-devops *> $null
@@ -57,12 +50,12 @@ function ValidateChangeLog($changeLogPath, $versionString, $validationStatus)
5750
Message = ""
5851
}
5952
$changeLogFullPath = Join-Path $RepoRoot $changeLogPath
60-
Write-Host "Path to change log: [$changeLogFullPath]"
53+
Write-Host "Path to change log: [$changeLogFullPath]"
6154
if (Test-Path $changeLogFullPath)
6255
{
6356
Confirm-ChangeLogEntry -ChangeLogLocation $changeLogFullPath -VersionString $versionString -ForRelease $true -ChangeLogStatus $ChangeLogStatus -SuppressErrors $true
6457
$validationStatus.Status = if ($ChangeLogStatus.IsValid) { "Success" } else { "Failed" }
65-
$validationStatus.Message = $ChangeLogStatus.Message
58+
$validationStatus.Message = $ChangeLogStatus.Message
6659
}
6760
else {
6861
$validationStatus.Status = "Failed"
@@ -83,7 +76,7 @@ function VerifyAPIReview($packageName, $packageVersion, $language)
8376
$APIReviewValidation = [PSCustomObject]@{
8477
Name = "API Review Approval"
8578
Status = "Pending"
86-
Message = ""
79+
Message = ""
8780
}
8881
$PackageNameValidation = [PSCustomObject]@{
8982
Name = "Package Name Approval"
@@ -101,7 +94,7 @@ function VerifyAPIReview($packageName, $packageVersion, $language)
10194
IsApproved = $false
10295
Details = ""
10396
}
104-
Write-Host "Checking API review status for package $packageName with version $packageVersion. language [$language]."
97+
Write-Host "Checking API review status for package $packageName with version $packageVersion. language [$language]."
10598
Check-ApiReviewStatus $packageName $packageVersion $language $APIViewUri $APIKey $apiStatus $packageNameStatus
10699

107100
Write-Host "API review approval details: $($apiStatus.Details)"
@@ -132,14 +125,14 @@ function VerifyAPIReview($packageName, $packageVersion, $language)
132125

133126
function IsVersionShipped($packageName, $packageVersion)
134127
{
135-
# This function will decide if a package version is already shipped or not
128+
# This function will decide if a package version is already shipped or not
136129
Write-Host "Checking if a version is already shipped for package $packageName with version $packageVersion."
137130
$parsedNewVersion = [AzureEngSemanticVersion]::new($packageVersion)
138131
$versionMajorMinor = "" + $parsedNewVersion.Major + "." + $parsedNewVersion.Minor
139132
$workItem = FindPackageWorkItem -lang $LanguageDisplayName -packageName $packageName -version $versionMajorMinor -includeClosed $true -outputCommand $false
140133
if ($workItem)
141134
{
142-
# Check if the package version is already shipped
135+
# Check if the package version is already shipped
143136
$shippedVersionSet = ParseVersionSetFromMDField $workItem.fields["Custom.ShippedPackages"]
144137
if ($shippedVersionSet.ContainsKey($packageVersion)) {
145138
return $true
@@ -163,8 +156,8 @@ function CreateUpdatePackageWorkItem($pkgInfo)
163156
$setReleaseState = $false
164157
$plannedDate = "unknown"
165158
}
166-
167-
# Create or update package work item
159+
160+
# Create or update package work item
168161
&$EngCommonScriptsDir/Update-DevOps-Release-WorkItem.ps1 `
169162
-language $LanguageDisplayName `
170163
-packageName $packageName `
@@ -175,9 +168,8 @@ function CreateUpdatePackageWorkItem($pkgInfo)
175168
-packageNewLibrary $pkgInfo.IsNewSDK `
176169
-serviceName "unknown" `
177170
-packageDisplayName "unknown" `
178-
-inRelease $IsReleaseBuild `
179-
-devops_pat $Devops_pat
180-
171+
-inRelease $IsReleaseBuild
172+
181173
if ($LASTEXITCODE -ne 0)
182174
{
183175
Write-Host "Update of the Devops Release WorkItem failed."
@@ -244,7 +236,7 @@ $updatedWi = CreateUpdatePackageWorkItem $pkgInfo
244236
# Update validation status in package work item
245237
if ($updatedWi) {
246238
Write-Host "Updating validation status in package work item."
247-
$updatedWi = UpdateValidationStatus $pkgValidationDetails $BuildDefinition $PipelineUrl
239+
$updatedWi = UpdateValidationStatus $pkgValidationDetails $BuildDefinition $PipelineUrl
248240
}
249241

250242
# Fail the build if any validation is not successful for a release build
@@ -254,7 +246,7 @@ Write-Host "Package Name status:" $apireviewDetails.PackageNameApproval.Status
254246

255247
if ($IsReleaseBuild)
256248
{
257-
if (!$updatedWi -or $changelogStatus.Status -ne "Success" -or $apireviewDetails.ApiviewApproval.Status -ne "Approved" -or $apireviewDetails.PackageNameApproval.Status -ne "Approved") {
249+
if (!$updatedWi -or $changelogStatus.Status -ne "Success" -or $apireviewDetails.ApiviewApproval.Status -ne "Approved" -or $apireviewDetails.PackageNameApproval.Status -ne "Approved") {
258250
Write-Error "At least one of the Validations above failed for package $pkgName with version $versionString."
259251
exit 1
260252
}

0 commit comments

Comments
 (0)