Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync eng/common directory with azure-sdk-tools for PR 1508 #17493

Merged
merged 5 commits into from
Mar 26, 2021
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
6 changes: 6 additions & 0 deletions eng/common/pipelines/templates/steps/create-apireview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ parameters:
ConfigFileDir: $(Build.ArtifactStagingDirectory)/PackageInfo

steps:
# ideally this should be done as initial step of a job in caller template
# We can remove this step later once it is added in caller
- template: /eng/common/pipelines/templates/steps/set-default-branch.yml

- ${{ each artifact in parameters.Artifacts }}:
- task: Powershell@2
inputs:
Expand All @@ -14,6 +18,8 @@ steps:
-APIKey $(azuresdk-apiview-apikey)
-APILabel "Auto Review - $(Build.SourceVersion)"
-PackageName ${{artifact.name}}
-SourceBranch $(Build.SourceBranchName)
-DefaultBranch $(DefaultBranch)
-ConfigFileDir '${{parameters.ConfigFileDir}}'
pwsh: true
workingDirectory: $(Pipeline.Workspace)
Expand Down
107 changes: 65 additions & 42 deletions eng/common/scripts/Create-APIReview.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ Param (
[Parameter(Mandatory=$True)]
[string] $APILabel,
[string] $PackageName,
[string] $SourceBranch,
[string] $DefaultBranch,
[string] $ConfigFileDir = ""
)


# Submit API review request and return status whether current revision is approved or pending or failed to create review
function Submit-APIReview($packagename, $filePath, $uri, $apiKey, $apiLabel)
{
Expand Down Expand Up @@ -55,6 +56,12 @@ function Submit-APIReview($packagename, $filePath, $uri, $apiKey, $apiLabel)


. (Join-Path $PSScriptRoot common.ps1)

Write-Host "Artifact path: $($ArtifactPath)"
Write-Host "Package Name: $($PackageName)"
Write-Host "Source branch: $($SourceBranch)"
Write-Host "Config File directory: $($ConfigFileDir)"

$packages = @{}
if ($FindArtifactForApiReviewFn -and (Test-Path "Function:$FindArtifactForApiReviewFn"))
{
Expand All @@ -68,67 +75,83 @@ else
exit(1)
}

$responses = @{}
if ($packages)
{
foreach($pkg in $packages.Keys)
{
Write-Host "Submitting API Review for package $($pkg)"
Write-Host $packages[$pkg]
$responses[$pkg] = Submit-APIReview -packagename $pkg -filePath $packages[$pkg] -uri $APIViewUri -apiKey $APIKey -apiLabel $APILabel
}
}
else
{
Write-Host "No package is found in artifact path to submit review request"
}

$FoundFailure = $False
# Check if package config file is present. This file has package version, SDK type etc info.
if (-not $ConfigFileDir)
{
$ConfigFileDir = Join-Path -Path $ArtifactPath "PackageInfo"
}
foreach ($pkgName in $responses.Keys)
{
$respCode = $responses[$pkgName]
if ($respCode -ne '200')

if ($packages)
{
foreach($pkgPath in $packages.Values)
{
$pkg = Split-Path -Leaf $pkgPath
$pkgPropPath = Join-Path -Path $ConfigFileDir "$PackageName.json"
if (-Not (Test-Path $pkgPropPath))
{
Write-Host " Package property file path $($pkgPropPath) is invalid."
continue
}
else
# Get package info from json file created before updating version to daily dev
$pkgInfo = Get-Content $pkgPropPath | ConvertFrom-Json
$version = [AzureEngSemanticVersion]::ParseVersionString($pkgInfo.Version)
if ($version -eq $null)
{
$pkgInfo = Get-Content $pkgPropPath | ConvertFrom-Json
$version = [AzureEngSemanticVersion]::ParseVersionString($pkgInfo.Version)
Write-Host "Package name: $($PackageName)"
Write-Host "Version: $($version)"
Write-Host "SDK Type: $($pkgInfo.SdkType)"
if ($version.IsPrerelease)
Write-Host "Version info is not available for package $PackageName, because version '$(pkgInfo.Version)' is invalid. Please check if the version follows Azure SDK package versioning guidelines."
exit 1
}

Write-Host "Version: $($version)"
Write-Host "SDK Type: $($pkgInfo.SdkType)"

# Run create review step only if build is triggered from master branch or if version is GA.
# This is to avoid invalidating review status by a build triggered from feature branch
if ( ($SourceBranch -eq $DefaultBranch) -or (-not $version.IsPrerelease))
{
Write-Host "Submitting API Review for package $($pkg)"
$respCode = Submit-APIReview -packagename $pkg -filePath $pkgPath -uri $APIViewUri -apiKey $APIKey -apiLabel $APILabel
Write-Host "HTTP Response code: $($respCode)"
# HTTP status 200 means API is in approved status
if ($respCode -eq '200')
{
Write-Host "API review is in approved status."
}
elseif ($version.IsPrerelease -or ($version.Major -eq 0))
{
# Ignore API review status for prerelease version
Write-Host "Package version is not GA. Ignoring API view approval status"
}
elseif ($pkgInfo.SdkType -eq "client" -and $pkgInfo.IsNewSdk)
else
{
$FoundFailure = $True
if ($respCode -eq '201')
# Return error code if status code is 201 for new data plane package
if ($pkgInfo.SdkType -eq "client" -and $pkgInfo.IsNewSdk)
{
Write-Host "Package version $($version) is GA and automatic API Review is not yet approved for package $($PackageName)."
Write-Host "Build and release is not allowed for GA package without API review approval."
Write-Host "You will need to queue another build to proceed further after API review is approved"
Write-Host "You can check http://aka.ms/azsdk/engsys/apireview/faq for more details on API Approval."
if ($respCode -eq '201')
{
Write-Host "Package version $($version) is GA and automatic API Review is not yet approved for package $($PackageName)."
Write-Host "Build and release is not allowed for GA package without API review approval."
Write-Host "You will need to queue another build to proceed further after API review is approved"
Write-Host "You can check http://aka.ms/azsdk/engsys/apireview/faq for more details on API Approval."
}
else
{
Write-Host "Failed to create API Review for package $($PackageName). Please reach out to Azure SDK engineering systems on teams channel and share this build details."
}
exit 1
}
else
{
Write-Host "Failed to create API Review for package $($PackageName). Please reach out to Azure SDK engineering systems on teams channel and share this build details."
Write-Host "API review is not approved for package $($PackageName), however it is not required for this package type so it can still be released without API review approval."
}
exit 1
}
else
{
Write-Host "API review is not approved for package $($PackageName). Management and track1 package can be released without API review approval."
}
}
}
else
{
Write-Host "Build is triggered from $($SourceBranch) with prerelease version. Skipping API review status check."
}
}
}
else
{
Write-Host "No package is found in artifact path to submit review request"
}