Skip to content

Commit 23b603e

Browse files
authored
Sync eng/common directory with azure-sdk-tools for PR 1508 (Azure#20035)
* Skip API create step when running from feature branch with non GA version
1 parent df7f86c commit 23b603e

File tree

2 files changed

+70
-42
lines changed

2 files changed

+70
-42
lines changed

eng/common/pipelines/templates/steps/create-apireview.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ parameters:
44
ConfigFileDir: $(Build.ArtifactStagingDirectory)/PackageInfo
55

66
steps:
7+
# ideally this should be done as initial step of a job in caller template
8+
# We can remove this step later once it is added in caller
9+
- template: /eng/common/pipelines/templates/steps/set-default-branch.yml
10+
711
- ${{ each artifact in parameters.Artifacts }}:
812
- task: Powershell@2
913
inputs:
@@ -14,6 +18,8 @@ steps:
1418
-APIKey $(azuresdk-apiview-apikey)
1519
-APILabel "Auto Review - $(Build.SourceVersion)"
1620
-PackageName ${{artifact.name}}
21+
-SourceBranch $(Build.SourceBranch)
22+
-DefaultBranch $(DefaultBranch)
1723
-ConfigFileDir '${{parameters.ConfigFileDir}}'
1824
pwsh: true
1925
workingDirectory: $(Pipeline.Workspace)

eng/common/scripts/Create-APIReview.ps1

Lines changed: 64 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ Param (
99
[Parameter(Mandatory=$True)]
1010
[string] $APILabel,
1111
[string] $PackageName,
12+
[string] $SourceBranch,
13+
[string] $DefaultBranch,
1214
[string] $ConfigFileDir = ""
1315
)
1416

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

5657

5758
. (Join-Path $PSScriptRoot common.ps1)
59+
60+
Write-Host "Artifact path: $($ArtifactPath)"
61+
Write-Host "Package Name: $($PackageName)"
62+
Write-Host "Source branch: $($SourceBranch)"
63+
Write-Host "Config File directory: $($ConfigFileDir)"
64+
5865
$packages = @{}
5966
if ($FindArtifactForApiReviewFn -and (Test-Path "Function:$FindArtifactForApiReviewFn"))
6067
{
@@ -68,67 +75,82 @@ else
6875
exit(1)
6976
}
7077

71-
$responses = @{}
72-
if ($packages)
73-
{
74-
foreach($pkg in $packages.Keys)
75-
{
76-
Write-Host "Submitting API Review for package $($pkg)"
77-
Write-Host $packages[$pkg]
78-
$responses[$pkg] = Submit-APIReview -packagename $pkg -filePath $packages[$pkg] -uri $APIViewUri -apiKey $APIKey -apiLabel $APILabel
79-
}
80-
}
81-
else
82-
{
83-
Write-Host "No package is found in artifact path to submit review request"
84-
}
85-
86-
$FoundFailure = $False
78+
# Check if package config file is present. This file has package version, SDK type etc info.
8779
if (-not $ConfigFileDir)
8880
{
8981
$ConfigFileDir = Join-Path -Path $ArtifactPath "PackageInfo"
9082
}
91-
foreach ($pkgName in $responses.Keys)
92-
{
93-
$respCode = $responses[$pkgName]
94-
if ($respCode -ne '200')
83+
84+
if ($packages)
85+
{
86+
foreach($pkgPath in $packages.Values)
9587
{
88+
$pkg = Split-Path -Leaf $pkgPath
9689
$pkgPropPath = Join-Path -Path $ConfigFileDir "$PackageName.json"
9790
if (-Not (Test-Path $pkgPropPath))
9891
{
9992
Write-Host " Package property file path $($pkgPropPath) is invalid."
93+
continue
10094
}
101-
else
95+
# Get package info from json file created before updating version to daily dev
96+
$pkgInfo = Get-Content $pkgPropPath | ConvertFrom-Json
97+
$version = [AzureEngSemanticVersion]::ParseVersionString($pkgInfo.Version)
98+
if ($version -eq $null)
10299
{
103-
$pkgInfo = Get-Content $pkgPropPath | ConvertFrom-Json
104-
$version = [AzureEngSemanticVersion]::ParseVersionString($pkgInfo.Version)
105-
Write-Host "Package name: $($PackageName)"
106-
Write-Host "Version: $($version)"
107-
Write-Host "SDK Type: $($pkgInfo.SdkType)"
108-
if ($version.IsPrerelease)
100+
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."
101+
exit 1
102+
}
103+
104+
Write-Host "Version: $($version)"
105+
Write-Host "SDK Type: $($pkgInfo.SdkType)"
106+
107+
# Run create review step only if build is triggered from master branch or if version is GA.
108+
# This is to avoid invalidating review status by a build triggered from feature branch
109+
if ( ($SourceBranch -eq $DefaultBranch) -or (-not $version.IsPrerelease))
110+
{
111+
Write-Host "Submitting API Review for package $($pkg)"
112+
$response = Submit-APIReview -packagename $pkg -filePath $pkgPath -uri $APIViewUri -apiKey $APIKey -apiLabel $APILabel
113+
# HTTP status 200 means API is in approved status
114+
if ($respCode -eq '200')
109115
{
116+
Write-Host "API review is in approved status."
117+
}
118+
elseif ($version.IsPrerelease -or ($version.Major -eq 0))
119+
{
120+
# Ignore API review status for prerelease version
110121
Write-Host "Package version is not GA. Ignoring API view approval status"
111122
}
112-
elseif ($pkgInfo.SdkType -eq "client" -and $pkgInfo.IsNewSdk)
123+
else
113124
{
114-
$FoundFailure = $True
115-
if ($respCode -eq '201')
125+
# Return error code if status code is 201 for new data plane package
126+
if ($pkgInfo.SdkType -eq "client" -and $pkgInfo.IsNewSdk)
116127
{
117-
Write-Host "Package version $($version) is GA and automatic API Review is not yet approved for package $($PackageName)."
118-
Write-Host "Build and release is not allowed for GA package without API review approval."
119-
Write-Host "You will need to queue another build to proceed further after API review is approved"
120-
Write-Host "You can check http://aka.ms/azsdk/engsys/apireview/faq for more details on API Approval."
128+
if ($respCode -eq '201')
129+
{
130+
Write-Host "Package version $($version) is GA and automatic API Review is not yet approved for package $($PackageName)."
131+
Write-Host "Build and release is not allowed for GA package without API review approval."
132+
Write-Host "You will need to queue another build to proceed further after API review is approved"
133+
Write-Host "You can check http://aka.ms/azsdk/engsys/apireview/faq for more details on API Approval."
134+
}
135+
else
136+
{
137+
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."
138+
}
139+
exit 1
121140
}
122141
else
123142
{
124-
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."
143+
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."
125144
}
126-
exit 1
127-
}
128-
else
129-
{
130-
Write-Host "API review is not approved for package $($PackageName). Management and track1 package can be released without API review approval."
131-
}
145+
}
146+
}
147+
else
148+
{
149+
Write-Host "Build is triggered from $($SourceBranch) with prerelease version. Skipping API review status check."
132150
}
133151
}
134152
}
153+
else
154+
{
155+
Write-Host "No package is found in artifact path to submit review request"
156+
}

0 commit comments

Comments
 (0)