diff --git a/eng/common/scripts/Get-PackageApprovalStatus.ps1 b/eng/common/scripts/Get-PackageApprovalStatus.ps1 index 642add267..c3107bbc3 100644 --- a/eng/common/scripts/Get-PackageApprovalStatus.ps1 +++ b/eng/common/scripts/Get-PackageApprovalStatus.ps1 @@ -4,6 +4,7 @@ Checks whether a package is approved for release. .DESCRIPTION Invokes the centralized Azure SDK CLI API review release gate and fails unless its structured result approves the package. +Approval summary headings include the package name and version to distinguish packages in CI logs. .PARAMETER PackageInfoFiles Package-info JSON files containing the package name, version, and optional API hash. @@ -58,25 +59,25 @@ function Write-BackendStatus([string] $Name, [object] $Status) { } } -function Write-ApprovalSummary([object] $Response) { +function Write-ApprovalSummary([object] $Response, [string] $PackageName, [string] $PackageVersion) { $result = $Response.result $source = if ($result.PSObject.Properties["finalSource"]) { $result.finalSource } else { "unknown" } $reason = if ($result.PSObject.Properties["reason"]) { $result.reason } else { "none" } Write-Host "" - Write-Host "Approval results" + Write-Host "Approval Results ($PackageName $PackageVersion)" Write-Host "----------------" if ($result.PSObject.Properties["reviewHub"]) { - Write-BackendStatus "API Review Hub" $result.reviewHub + Write-BackendStatus "API Review Hub ($PackageName $PackageVersion)" $result.reviewHub } if ($result.PSObject.Properties["apiView"]) { Write-Host "" - Write-BackendStatus "APIView" $result.apiView + Write-BackendStatus "APIView ($PackageName $PackageVersion)" $result.apiView } $approval = if ($result.isApproved) { "APPROVED" } else { "NOT APPROVED" } Write-Host "" - Write-Host "Overall" + Write-Host "Overall ($PackageName $PackageVersion)" Write-Host " Status: $approval" Write-Host " Source: $source" Write-Host " Reason: $reason" @@ -120,7 +121,7 @@ function Test-PackageApproval([string] $PackageName, [string] $PackageVersion, [ $null -ne $response.result -and $response.result.PSObject.Properties["isApproved"] -and $response.result.isApproved -is [bool]) { - Write-ApprovalSummary $response + Write-ApprovalSummary $response $PackageName $PackageVersion } if ($exitCode -ne 0) { diff --git a/eng/common/scripts/tests/Get-PackageApprovalStatus.Tests.ps1 b/eng/common/scripts/tests/Get-PackageApprovalStatus.Tests.ps1 index d6a744e3d..6f8614823 100644 --- a/eng/common/scripts/tests/Get-PackageApprovalStatus.Tests.ps1 +++ b/eng/common/scripts/tests/Get-PackageApprovalStatus.Tests.ps1 @@ -125,9 +125,31 @@ Describe "Get-PackageApprovalStatus.ps1" { $messages = @(& $scriptPath -PackageInfoFiles $packageInfoPath 6>&1) | ForEach-Object { "$_" } - [Array]::IndexOf($messages, "API Review Hub") | Should BeLessThan ([Array]::IndexOf($messages, "APIView")) - [Array]::IndexOf($messages, "APIView") | Should BeLessThan ([Array]::IndexOf($messages, "Overall")) - ($messages -join [Environment]::NewLine) | Should Match "Overall\r?\n Status: APPROVED\r?\n Source: APIView\r?\n Reason: approved" + foreach ($heading in @("Approval Results", "API Review Hub", "APIView", "Overall")) { + @($messages | Where-Object { $_ -eq "$heading (azure-test 1.0.0)" }).Count | Should Be 1 + } + [Array]::IndexOf($messages, "API Review Hub (azure-test 1.0.0)") | Should BeLessThan ([Array]::IndexOf($messages, "APIView (azure-test 1.0.0)")) + [Array]::IndexOf($messages, "APIView (azure-test 1.0.0)") | Should BeLessThan ([Array]::IndexOf($messages, "Overall (azure-test 1.0.0)")) + ($messages -join [Environment]::NewLine) | Should Match "Overall \(azure-test 1\.0\.0\)\r?\n Status: APPROVED\r?\n Source: APIView\r?\n Reason: approved" + } + + It "includes each package name and version in all summary headings when checking multiple packages" { + $secondPackageInfoPath = Join-Path $TestDrive "azure-other.json" + @{ + Name = "azure-other" + Version = "2.0.0b1" + } | ConvertTo-Json | Set-Content $secondPackageInfoPath + $global:AzSdkOutput = '{"operation_status":"Succeeded","result":{"isApproved":true,"finalSource":"APIView","reason":"approved","reviewHub":{"isApproved":false,"reason":"repositoryNotSupported","statusCode":200},"apiView":{"isApproved":true,"reason":"approved","statusCode":200}}}' + + $messages = @(& $scriptPath -PackageInfoFiles @($packageInfoPath, $secondPackageInfoPath) 6>&1) | + ForEach-Object { "$_" } + + foreach ($package in @("azure-test 1.0.0", "azure-other 2.0.0b1")) { + foreach ($heading in @("Approval Results", "API Review Hub", "APIView", "Overall")) { + @($messages | Where-Object { $_ -eq "$heading ($package)" }).Count | Should Be 1 + } + } + $global:CapturedAzSdkInvocations.Count | Should Be 2 } It "includes raw output when azsdk returns malformed output" {