Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions eng/common/pipelines/templates/steps/create-apireview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,25 @@ steps:
parameters:
WorkingDirectory: ${{ parameters.SourceRootPath }}

- task: Powershell@2
- task: AzureCLI@2
inputs:
filePath: ${{ parameters.SourceRootPath }}/eng/common/scripts/Create-APIReview.ps1
azureSubscription: 'APIView prod deployment'
scriptType: pscore
scriptLocation: scriptPath
scriptPath: ${{ parameters.SourceRootPath }}/eng/common/scripts/Create-APIReview.ps1
# PackageInfoFiles example: @('a/file1.json','a/file2.json')
arguments: >
-PackageInfoFiles @('${{ join(''',''', parameters.PackageInfoFiles) }}')
-ArtifactList ('${{ convertToJson(parameters.Artifacts) }}' | ConvertFrom-Json | Select-Object Name)
-ArtifactPath '${{parameters.ArtifactPath}}'
-ArtifactName ${{ parameters.ArtifactName }}
-APIKey '$(azuresdk-apiview-apikey)'
-PackageName '${{parameters.PackageName}}'
-SourceBranch '$(Build.SourceBranchName)'
-DefaultBranch '$(DefaultBranch)'
-ConfigFileDir '${{parameters.ConfigFileDir}}'
-BuildId '$(Build.BuildId)'
-RepoName '$(Build.Repository.Name)'
-MarkPackageAsShipped $${{parameters.MarkPackageAsShipped}}
pwsh: true
displayName: Create API Review
condition: >-
and(
Expand Down
49 changes: 41 additions & 8 deletions eng/common/scripts/Create-APIReview.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,42 @@ Param (
[array] $ArtifactList,
[Parameter(Mandatory=$True)]
[string] $ArtifactPath,
[Parameter(Mandatory=$True)]
[string] $APIKey,
[string] $SourceBranch,
[string] $DefaultBranch,
[string] $RepoName,
[string] $BuildId,
[string] $PackageName = "",
[string] $ConfigFileDir = "",
[string] $APIViewUri = "https://apiview.dev/AutoReview",
[string] $APIViewUri = "https://apiview.dev/autoreview",
[string] $ArtifactName = "packages",
[bool] $MarkPackageAsShipped = $false,
[Parameter(Mandatory=$False)]
[array] $PackageInfoFiles
)

Set-StrictMode -Version 3

. (Join-Path $PSScriptRoot common.ps1)
. (Join-Path $PSScriptRoot Helpers ApiView-Helpers.ps1)

# Get Bearer token for APIView authentication
# In Azure DevOps, this uses the service connection's Managed Identity/Service Principal
function Get-ApiViewBearerToken()
{
try {
$tokenResponse = az account get-access-token --resource "api://apiview" --output json 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to acquire access token: $tokenResponse"
return $null
}
return ($tokenResponse | ConvertFrom-Json).accessToken
}
catch {
Write-Error "Failed to acquire access token: $($_.Exception.Message)"
return $null
}
}

# Submit API review request and return status whether current revision is approved or pending or failed to create review
function Upload-SourceArtifact($filePath, $apiLabel, $releaseStatus, $packageVersion, $packageType)
{
Expand Down Expand Up @@ -78,9 +95,17 @@ function Upload-SourceArtifact($filePath, $apiLabel, $releaseStatus, $packageVer
Write-Host "Request param, compareAllRevisions: true"
}

$uri = "${APIViewUri}/UploadAutoReview"
$uri = "${APIViewUri}/upload"

# Get Bearer token for authentication
$bearerToken = Get-ApiViewBearerToken
if (-not $bearerToken) {
Write-Error "Failed to acquire Bearer token for APIView authentication."
return [System.Net.HttpStatusCode]::Unauthorized
}

$headers = @{
"ApiKey" = $apiKey;
"Authorization" = "Bearer $bearerToken";
"content-type" = "multipart/form-data"
}

Expand Down Expand Up @@ -115,20 +140,28 @@ function Upload-ReviewTokenFile($packageName, $apiLabel, $releaseStatus, $review
if($MarkPackageAsShipped) {
$params += "&setReleaseTag=true"
}
$uri = "${APIViewUri}/CreateApiReview?${params}"
$uri = "${APIViewUri}/create?${params}"
if ($releaseStatus -and ($releaseStatus -ne "Unreleased"))
{
$uri += "&compareAllRevisions=true"
}

Write-Host "Request to APIView: $uri"

# Get Bearer token for authentication
$bearerToken = Get-ApiViewBearerToken
if (-not $bearerToken) {
Write-Error "Failed to acquire Bearer token for APIView authentication."
return [System.Net.HttpStatusCode]::Unauthorized
}

$headers = @{
"ApiKey" = $APIKey;
"Authorization" = "Bearer $bearerToken"
}

try
{
$Response = Invoke-WebRequest -Method 'GET' -Uri $uri -Headers $headers
$Response = Invoke-WebRequest -Method 'POST' -Uri $uri -Headers $headers
Write-Host "API review: $($Response.Content)"
$StatusCode = $Response.StatusCode
}
Expand Down