Compare commits
2 Commits
sync-eng/c
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78de0b7c25 | ||
|
|
884ff2fbab |
@ -37,18 +37,16 @@ steps:
|
||||
parameters:
|
||||
WorkingDirectory: ${{ parameters.SourceRootPath }}
|
||||
|
||||
- task: AzureCLI@2
|
||||
- task: Powershell@2
|
||||
inputs:
|
||||
azureSubscription: 'APIView prod deployment'
|
||||
scriptType: pscore
|
||||
scriptLocation: scriptPath
|
||||
scriptPath: ${{ parameters.SourceRootPath }}/eng/common/scripts/Create-APIReview.ps1
|
||||
filePath: ${{ 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)'
|
||||
@ -56,6 +54,7 @@ steps:
|
||||
-BuildId '$(Build.BuildId)'
|
||||
-RepoName '$(Build.Repository.Name)'
|
||||
-MarkPackageAsShipped $${{parameters.MarkPackageAsShipped}}
|
||||
pwsh: true
|
||||
displayName: Create API Review
|
||||
condition: >-
|
||||
and(
|
||||
|
||||
@ -14,9 +14,9 @@ parameters:
|
||||
- name: TestPipeline
|
||||
type: boolean
|
||||
default: false
|
||||
- name: ArtifactsJson
|
||||
type: string
|
||||
default: ''
|
||||
- name: Artifacts
|
||||
type: object
|
||||
default: []
|
||||
|
||||
steps:
|
||||
- ${{ if eq(parameters.TestPipeline, true) }}:
|
||||
@ -31,5 +31,5 @@ steps:
|
||||
-PackageNames '${{ coalesce(parameters.PackageName, parameters.PackageNames) }}'
|
||||
-ServiceDirectory '${{ parameters.ServiceDirectory }}'
|
||||
-TagSeparator '${{ parameters.TagSeparator }}'
|
||||
-ArtifactsJson '${{ parameters.ArtifactsJson }}'
|
||||
-Artifacts @('${{ replace(convertToJson(parameters.Artifacts), '''', '`''') }}' | ConvertFrom-Json)
|
||||
pwsh: true
|
||||
|
||||
@ -4,13 +4,15 @@ 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)]
|
||||
@ -18,28 +20,9 @@ Param (
|
||||
)
|
||||
|
||||
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)
|
||||
{
|
||||
@ -95,17 +78,9 @@ function Upload-SourceArtifact($filePath, $apiLabel, $releaseStatus, $packageVer
|
||||
Write-Host "Request param, compareAllRevisions: true"
|
||||
}
|
||||
|
||||
$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
|
||||
}
|
||||
|
||||
$uri = "${APIViewUri}/UploadAutoReview"
|
||||
$headers = @{
|
||||
"Authorization" = "Bearer $bearerToken";
|
||||
"ApiKey" = $apiKey;
|
||||
"content-type" = "multipart/form-data"
|
||||
}
|
||||
|
||||
@ -140,28 +115,20 @@ function Upload-ReviewTokenFile($packageName, $apiLabel, $releaseStatus, $review
|
||||
if($MarkPackageAsShipped) {
|
||||
$params += "&setReleaseTag=true"
|
||||
}
|
||||
$uri = "${APIViewUri}/create?${params}"
|
||||
$uri = "${APIViewUri}/CreateApiReview?${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 = @{
|
||||
"Authorization" = "Bearer $bearerToken"
|
||||
"ApiKey" = $APIKey;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$Response = Invoke-WebRequest -Method 'POST' -Uri $uri -Headers $headers
|
||||
$Response = Invoke-WebRequest -Method 'GET' -Uri $uri -Headers $headers
|
||||
Write-Host "API review: $($Response.Content)"
|
||||
$StatusCode = $Response.StatusCode
|
||||
}
|
||||
|
||||
@ -5,63 +5,83 @@ param (
|
||||
[string]$BuildID,
|
||||
[Parameter(mandatory = $false)]
|
||||
[string]$PackageNames = "",
|
||||
[Parameter(mandatory = $true)]
|
||||
[Parameter(mandatory = $false)]
|
||||
# ServiceDirectory is required when using PackageNames,
|
||||
# or when Artifacts do not include their own ServiceDirectory property.
|
||||
[string]$ServiceDirectory,
|
||||
[Parameter(mandatory = $false)]
|
||||
[string]$TagSeparator = "_",
|
||||
[Parameter(mandatory = $false)]
|
||||
[string]$ArtifactsJson = ""
|
||||
[object[]]$Artifacts = @()
|
||||
)
|
||||
|
||||
. (Join-Path $PSScriptRoot common.ps1)
|
||||
|
||||
# Ensure Artifacts is always an array
|
||||
$Artifacts = @($Artifacts)
|
||||
|
||||
Write-Host "PackageNames: $PackageNames"
|
||||
Write-Host "ServiceDirectory: $ServiceDirectory"
|
||||
Write-Host "BuildID: $BuildID"
|
||||
Write-Host "ArtifactsJson: $ArtifactsJson"
|
||||
Write-Host "Artifacts count: $($Artifacts.Count)"
|
||||
|
||||
$packageNamesArray = @()
|
||||
$artifacts = $null
|
||||
|
||||
# If ArtifactsJson is provided, extract package names from it
|
||||
if (![String]::IsNullOrWhiteSpace($ArtifactsJson)) {
|
||||
Write-Host "Using ArtifactsJson to determine package names"
|
||||
if ($Artifacts -and $Artifacts.Count -gt 0) {
|
||||
# When using Artifacts, process each artifact with its name and groupId (if applicable)
|
||||
try {
|
||||
$artifacts = $ArtifactsJson | ConvertFrom-Json
|
||||
$packageNamesArray = $artifacts | ForEach-Object { $_.name }
|
||||
Write-Host "Extracted package names from ArtifactsJson: $($packageNamesArray -join ', ')"
|
||||
}
|
||||
catch {
|
||||
LogError "Failed to parse ArtifactsJson: $($_.Exception.Message)"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
elseif (![String]::IsNullOrWhiteSpace($PackageNames)) {
|
||||
$packageNamesArray = $PackageNames.Split(',')
|
||||
}
|
||||
else {
|
||||
LogError "Either PackageNames or ArtifactsJson must be provided."
|
||||
exit 1
|
||||
}
|
||||
foreach ($artifact in $Artifacts) {
|
||||
# Validate required properties
|
||||
if (-not (Get-Member -InputObject $artifact -Name 'name' -MemberType Properties)) {
|
||||
LogError "Artifact is missing required 'name' property."
|
||||
exit 1
|
||||
}
|
||||
|
||||
if ($artifacts) {
|
||||
# When using ArtifactsJson, process each artifact with its name and groupId (if applicable)
|
||||
try {
|
||||
foreach ($artifact in $artifacts) {
|
||||
$packageName = $artifact.name
|
||||
if ([String]::IsNullOrWhiteSpace($packageName)) {
|
||||
LogError "Artifact 'name' property is null or empty."
|
||||
exit 1
|
||||
}
|
||||
|
||||
$artifactServiceDirectory = $null
|
||||
# Check for ServiceDirectory property
|
||||
if (Get-Member -InputObject $artifact -Name 'ServiceDirectory' -MemberType Properties) {
|
||||
if (![String]::IsNullOrWhiteSpace($artifact.ServiceDirectory)) {
|
||||
$artifactServiceDirectory = $artifact.ServiceDirectory
|
||||
}
|
||||
}
|
||||
|
||||
if ([String]::IsNullOrWhiteSpace($artifactServiceDirectory)) {
|
||||
$artifactServiceDirectory = $ServiceDirectory
|
||||
}
|
||||
|
||||
# Validate ServiceDirectory is available
|
||||
if ([String]::IsNullOrWhiteSpace($artifactServiceDirectory)) {
|
||||
LogError "ServiceDirectory is required but not provided for artifact '$packageName'. Provide it via script parameter or artifact property."
|
||||
exit 1
|
||||
}
|
||||
|
||||
$newVersion = [AzureEngSemanticVersion]::new("1.0.0")
|
||||
$prefix = "$packageName$TagSeparator"
|
||||
|
||||
if ($Language -eq "java") {
|
||||
# Check for groupId property
|
||||
if (-not (Get-Member -InputObject $artifact -Name 'groupId' -MemberType Properties)) {
|
||||
LogError "Artifact '$packageName' is missing required 'groupId' property for Java language."
|
||||
exit 1
|
||||
}
|
||||
|
||||
$groupId = $artifact.groupId
|
||||
Write-Host "Processing $packageName with groupId $groupId"
|
||||
if ([String]::IsNullOrWhiteSpace($groupId)) {
|
||||
LogError "GroupId is missing for package $packageName."
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "Processing $packageName with groupId $groupId"
|
||||
# Use groupId+artifactName format for tag prefix (e.g., "com.azure.v2+azure-sdk-template_")
|
||||
$prefix = "$groupId+$packageName$TagSeparator"
|
||||
}
|
||||
else {
|
||||
Write-Host "Processing $packageName"
|
||||
}
|
||||
|
||||
Write-Host "Get Latest Tag : git tag -l $prefix*"
|
||||
$latestTags = git tag -l "$prefix*"
|
||||
@ -87,21 +107,27 @@ if ($artifacts) {
|
||||
if ($Language -ne "java") {
|
||||
SetPackageVersion -PackageName $packageName `
|
||||
-Version $newVersion.ToString() `
|
||||
-ServiceDirectory $ServiceDirectory
|
||||
-ServiceDirectory $artifactServiceDirectory
|
||||
} else {
|
||||
SetPackageVersion -PackageName $packageName `
|
||||
-Version $newVersion.ToString() `
|
||||
-ServiceDirectory $ServiceDirectory `
|
||||
-ServiceDirectory $artifactServiceDirectory `
|
||||
-GroupId $groupId
|
||||
}
|
||||
}
|
||||
}
|
||||
catch {
|
||||
LogError "Failed to process ArtifactsJson: $ArtifactsJson, exception: $($_.Exception.Message)"
|
||||
LogError "Failed to process Artifacts: exception: $($_.Exception.Message)"
|
||||
exit 1
|
||||
}
|
||||
} else {
|
||||
} elseif (![String]::IsNullOrWhiteSpace($PackageNames)) {
|
||||
# Fallback to original logic when using PackageNames string
|
||||
if ([String]::IsNullOrWhiteSpace($ServiceDirectory)) {
|
||||
LogError "ServiceDirectory is required when using PackageNames."
|
||||
exit 1
|
||||
}
|
||||
|
||||
$packageNamesArray = $PackageNames.Split(',')
|
||||
foreach ($packageName in $packageNamesArray) {
|
||||
Write-Host "Processing $packageName"
|
||||
$newVersion = [AzureEngSemanticVersion]::new("1.0.0")
|
||||
@ -131,4 +157,7 @@ if ($artifacts) {
|
||||
-Version $newVersion.ToString() `
|
||||
-ServiceDirectory $ServiceDirectory
|
||||
}
|
||||
} else {
|
||||
LogError "Either PackageNames or Artifacts must be provided."
|
||||
exit 1
|
||||
}
|
||||
|
||||
@ -94,6 +94,9 @@ function LogGroupStart() {
|
||||
elseif (Test-SupportsGitHubLogging) {
|
||||
Write-Host "::group::$args"
|
||||
}
|
||||
else {
|
||||
Write-Host "> $args"
|
||||
}
|
||||
}
|
||||
|
||||
function LogGroupEnd() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user