Compare commits
9 Commits
a2082c3e5b
...
e5a4c64c36
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e5a4c64c36 | ||
|
|
1dc056f265 | ||
|
|
28ae0f9bba | ||
|
|
ef74176810 | ||
|
|
b4ff6c4578 | ||
|
|
cbff29908b | ||
|
|
210faebfba | ||
|
|
e528dc9c10 | ||
|
|
377d7094f5 |
@ -37,16 +37,18 @@ steps:
|
|||||||
parameters:
|
parameters:
|
||||||
WorkingDirectory: ${{ parameters.SourceRootPath }}
|
WorkingDirectory: ${{ parameters.SourceRootPath }}
|
||||||
|
|
||||||
- task: Powershell@2
|
- task: AzureCLI@2
|
||||||
inputs:
|
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')
|
# PackageInfoFiles example: @('a/file1.json','a/file2.json')
|
||||||
arguments: >
|
arguments: >
|
||||||
-PackageInfoFiles @('${{ join(''',''', parameters.PackageInfoFiles) }}')
|
-PackageInfoFiles @('${{ join(''',''', parameters.PackageInfoFiles) }}')
|
||||||
-ArtifactList ('${{ convertToJson(parameters.Artifacts) }}' | ConvertFrom-Json | Select-Object Name)
|
-ArtifactList ('${{ convertToJson(parameters.Artifacts) }}' | ConvertFrom-Json | Select-Object Name)
|
||||||
-ArtifactPath '${{parameters.ArtifactPath}}'
|
-ArtifactPath '${{parameters.ArtifactPath}}'
|
||||||
-ArtifactName ${{ parameters.ArtifactName }}
|
-ArtifactName ${{ parameters.ArtifactName }}
|
||||||
-APIKey '$(azuresdk-apiview-apikey)'
|
|
||||||
-PackageName '${{parameters.PackageName}}'
|
-PackageName '${{parameters.PackageName}}'
|
||||||
-SourceBranch '$(Build.SourceBranchName)'
|
-SourceBranch '$(Build.SourceBranchName)'
|
||||||
-DefaultBranch '$(DefaultBranch)'
|
-DefaultBranch '$(DefaultBranch)'
|
||||||
@ -54,7 +56,6 @@ steps:
|
|||||||
-BuildId '$(Build.BuildId)'
|
-BuildId '$(Build.BuildId)'
|
||||||
-RepoName '$(Build.Repository.Name)'
|
-RepoName '$(Build.Repository.Name)'
|
||||||
-MarkPackageAsShipped $${{parameters.MarkPackageAsShipped}}
|
-MarkPackageAsShipped $${{parameters.MarkPackageAsShipped}}
|
||||||
pwsh: true
|
|
||||||
displayName: Create API Review
|
displayName: Create API Review
|
||||||
condition: >-
|
condition: >-
|
||||||
and(
|
and(
|
||||||
|
|||||||
@ -4,15 +4,13 @@ Param (
|
|||||||
[array] $ArtifactList,
|
[array] $ArtifactList,
|
||||||
[Parameter(Mandatory=$True)]
|
[Parameter(Mandatory=$True)]
|
||||||
[string] $ArtifactPath,
|
[string] $ArtifactPath,
|
||||||
[Parameter(Mandatory=$True)]
|
|
||||||
[string] $APIKey,
|
|
||||||
[string] $SourceBranch,
|
[string] $SourceBranch,
|
||||||
[string] $DefaultBranch,
|
[string] $DefaultBranch,
|
||||||
[string] $RepoName,
|
[string] $RepoName,
|
||||||
[string] $BuildId,
|
[string] $BuildId,
|
||||||
[string] $PackageName = "",
|
[string] $PackageName = "",
|
||||||
[string] $ConfigFileDir = "",
|
[string] $ConfigFileDir = "",
|
||||||
[string] $APIViewUri = "https://apiview.dev/AutoReview",
|
[string] $APIViewUri = "https://apiview.dev/autoreview",
|
||||||
[string] $ArtifactName = "packages",
|
[string] $ArtifactName = "packages",
|
||||||
[bool] $MarkPackageAsShipped = $false,
|
[bool] $MarkPackageAsShipped = $false,
|
||||||
[Parameter(Mandatory=$False)]
|
[Parameter(Mandatory=$False)]
|
||||||
@ -20,9 +18,28 @@ Param (
|
|||||||
)
|
)
|
||||||
|
|
||||||
Set-StrictMode -Version 3
|
Set-StrictMode -Version 3
|
||||||
|
|
||||||
. (Join-Path $PSScriptRoot common.ps1)
|
. (Join-Path $PSScriptRoot common.ps1)
|
||||||
. (Join-Path $PSScriptRoot Helpers ApiView-Helpers.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
|
# 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)
|
function Upload-SourceArtifact($filePath, $apiLabel, $releaseStatus, $packageVersion, $packageType)
|
||||||
{
|
{
|
||||||
@ -78,9 +95,17 @@ function Upload-SourceArtifact($filePath, $apiLabel, $releaseStatus, $packageVer
|
|||||||
Write-Host "Request param, compareAllRevisions: true"
|
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 = @{
|
$headers = @{
|
||||||
"ApiKey" = $apiKey;
|
"Authorization" = "Bearer $bearerToken";
|
||||||
"content-type" = "multipart/form-data"
|
"content-type" = "multipart/form-data"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,20 +140,28 @@ function Upload-ReviewTokenFile($packageName, $apiLabel, $releaseStatus, $review
|
|||||||
if($MarkPackageAsShipped) {
|
if($MarkPackageAsShipped) {
|
||||||
$params += "&setReleaseTag=true"
|
$params += "&setReleaseTag=true"
|
||||||
}
|
}
|
||||||
$uri = "${APIViewUri}/CreateApiReview?${params}"
|
$uri = "${APIViewUri}/create?${params}"
|
||||||
if ($releaseStatus -and ($releaseStatus -ne "Unreleased"))
|
if ($releaseStatus -and ($releaseStatus -ne "Unreleased"))
|
||||||
{
|
{
|
||||||
$uri += "&compareAllRevisions=true"
|
$uri += "&compareAllRevisions=true"
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Request to APIView: $uri"
|
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 = @{
|
$headers = @{
|
||||||
"ApiKey" = $APIKey;
|
"Authorization" = "Bearer $bearerToken"
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
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)"
|
Write-Host "API review: $($Response.Content)"
|
||||||
$StatusCode = $Response.StatusCode
|
$StatusCode = $Response.StatusCode
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user