Sync eng/common directory with azure-sdk-tools for PR 8388 (#5704)

* 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 <jasupliz@microsoft.com>
This commit is contained in:
Azure SDK Bot 2024-06-13 12:10:14 -04:00 коммит произвёл GitHub
Родитель 77e23c2108
Коммит f80f2d7999
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
5 изменённых файлов: 46 добавлений и 75 удалений

Просмотреть файл

@ -10,20 +10,21 @@ steps:
displayName: "Set as release build"
condition: and(succeeded(), eq(variables['SetAsReleaseBuild'], ''))
- task: Powershell@2
- task: AzureCLI@2
inputs:
filePath: $(Build.SourcesDirectory)/eng/common/scripts/Validate-All-Packages.ps1
arguments: >
-ArtifactList ('${{ convertToJson(parameters.Artifacts) }}' | ConvertFrom-Json | Select-Object Name)
-ArtifactPath ${{ parameters.ArtifactPath }}
-RepoRoot $(Build.SourcesDirectory)
-APIKey $(azuresdk-apiview-apikey)
-ConfigFileDir '${{ parameters.ConfigFileDir }}'
-BuildDefinition $(System.CollectionUri)$(System.TeamProject)/_build?definitionId=$(System.DefinitionId)
-PipelineUrl $(System.CollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)
-Devops_pat '$(azuresdk-azure-sdk-devops-release-work-item-pat)'
azureSubscription: opensource-api-connection
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
$(Build.SourcesDirectory)/eng/common/scripts/Validate-All-Packages.ps1 `
-ArtifactList ('${{ convertToJson(parameters.Artifacts) }}' | ConvertFrom-Json | Select-Object Name) `
-ArtifactPath ${{ parameters.ArtifactPath }} `
-RepoRoot $(Build.SourcesDirectory) `
-APIKey $(azuresdk-apiview-apikey) `
-ConfigFileDir '${{ parameters.ConfigFileDir }}' `
-BuildDefinition $(System.CollectionUri)$(System.TeamProject)/_build?definitionId=$(System.DefinitionId) `
-PipelineUrl $(System.CollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId) `
-IsReleaseBuild $$(SetAsReleaseBuild)
pwsh: true
workingDirectory: $(Pipeline.Workspace)
displayName: Validate packages and update work items
continueOnError: true

Просмотреть файл

@ -4,20 +4,16 @@ $ReleaseDevOpsCommonParameters = $ReleaseDevOpsOrgParameters + @("--output", "j
$ReleaseDevOpsCommonParametersWithProject = $ReleaseDevOpsCommonParameters + @("--project", "Release")
function Get-DevOpsRestHeaders()
{
$headers = $null
if (Get-Variable -Name "devops_pat" -ValueOnly -ErrorAction "Ignore")
{
$encodedToken = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes([string]::Format("{0}:{1}", "", $devops_pat)))
$headers = @{ Authorization = "Basic $encodedToken" }
}
else
{
# Get a temp access token from the logged in az cli user for azure devops resource
$jwt_accessToken = (az account get-access-token --resource "499b84ac-1321-427f-aa17-267ca6975798" --query "accessToken" --output tsv)
$headers = @{ Authorization = "Bearer $jwt_accessToken" }
$headerAccessToken = (az account get-access-token --resource "499b84ac-1321-427f-aa17-267ca6975798" --query "accessToken" --output tsv)
if ([System.String]::IsNullOrEmpty($headerAccessToken)) {
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."
}
$headers = @{ Authorization = "Bearer $headerAccessToken" }
return $headers
}
@ -103,15 +99,6 @@ function Invoke-Query($fields, $wiql, $output = $true)
return $workItems
}
function LoginToAzureDevops([string]$devops_pat)
{
if (!$devops_pat) {
return
}
# 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()
{
$filterNulls = $args | Where-Object { $_ }

Просмотреть файл

@ -15,7 +15,6 @@ param(
[string]$packageNewLibrary = "true",
[string]$relatedWorkItemId = $null,
[string]$tag = $null,
[string]$devops_pat = $env:DEVOPS_PAT,
[bool]$inRelease = $true
)
#Requires -Version 6.0
@ -29,17 +28,11 @@ if (!(Get-Command az -ErrorAction SilentlyContinue)) {
. (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 (!$?){

Просмотреть файл

@ -12,7 +12,6 @@ Param (
[string]$BuildDefinition,
[string]$PipelineUrl,
[string]$APIViewUri = "https://apiview.dev/AutoReview/GetReviewStatus",
[string]$Devops_pat = $env:DEVOPS_PAT,
[bool] $IsReleaseBuild = $false
)
@ -33,8 +32,7 @@ function ProcessPackage($PackageName, $ConfigFileDir)
-APIKey $APIKey `
-BuildDefinition $BuildDefinition `
-PipelineUrl $PipelineUrl `
-ConfigFileDir $ConfigFileDir `
-Devops_pat $Devops_pat
-ConfigFileDir $ConfigFileDir
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to validate package $PackageName"
exit 1

Просмотреть файл

@ -15,7 +15,6 @@ param (
[string] $BuildDefinition,
[string] $PipelineUrl,
[string] $APIViewUri,
[string] $Devops_pat = $env:DEVOPS_PAT,
[bool] $IsReleaseBuild = $false
)
Set-StrictMode -Version 3
@ -24,17 +23,11 @@ Set-StrictMode -Version 3
. ${PSScriptRoot}\Helpers\ApiView-Helpers.ps1
. ${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 (!$?){
@ -175,8 +168,7 @@ function CreateUpdatePackageWorkItem($pkgInfo)
-packageNewLibrary $pkgInfo.IsNewSDK `
-serviceName "unknown" `
-packageDisplayName "unknown" `
-inRelease $IsReleaseBuild `
-devops_pat $Devops_pat
-inRelease $IsReleaseBuild
if ($LASTEXITCODE -ne 0)
{