From 46fc706f39f4a2863cc904edf07ca9e2ba2d905a Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Mon, 22 Mar 2021 10:57:02 -0700 Subject: [PATCH 1/5] Skip API create step when running from feature branch with non GA version --- .../templates/steps/create-apireview.yml | 1 + eng/common/scripts/Create-APIReview.ps1 | 99 +++++++++++-------- 2 files changed, 58 insertions(+), 42 deletions(-) diff --git a/eng/common/pipelines/templates/steps/create-apireview.yml b/eng/common/pipelines/templates/steps/create-apireview.yml index 730bc2bb4c61..475e8e362f50 100644 --- a/eng/common/pipelines/templates/steps/create-apireview.yml +++ b/eng/common/pipelines/templates/steps/create-apireview.yml @@ -14,6 +14,7 @@ steps: -APIKey $(azuresdk-apiview-apikey) -APILabel "Auto Review - $(Build.SourceVersion)" -PackageName ${{artifact.name}} + -SourceBranch $(Build.SourceBranch) -ConfigFileDir '${{parameters.ConfigFileDir}}' pwsh: true workingDirectory: $(Pipeline.Workspace) diff --git a/eng/common/scripts/Create-APIReview.ps1 b/eng/common/scripts/Create-APIReview.ps1 index b0ecc542ffed..44e2116dcdeb 100644 --- a/eng/common/scripts/Create-APIReview.ps1 +++ b/eng/common/scripts/Create-APIReview.ps1 @@ -9,10 +9,10 @@ Param ( [Parameter(Mandatory=$True)] [string] $APILabel, [string] $PackageName, + [string] $SourceBranch, [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) { @@ -55,6 +55,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")) { @@ -68,67 +74,76 @@ 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) + 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 "master") -or (-not $version.IsPrerelease)) { - $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 "Submitting API Review for package $($pkg)" + $response = Submit-APIReview -packagename $pkg -filePath $pkgPath -uri $APIViewUri -apiKey $APIKey -apiLabel $APILabel + # 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 track2 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). Management and track1 package can 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" +} From 7c3bf669d052b71bd31824163310c39ea45b414a Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Mon, 22 Mar 2021 11:55:58 -0700 Subject: [PATCH 2/5] Use default branch variable instead of hardcoding master branch name --- .../pipelines/templates/steps/create-apireview.yml | 5 +++++ eng/common/scripts/Create-APIReview.ps1 | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/eng/common/pipelines/templates/steps/create-apireview.yml b/eng/common/pipelines/templates/steps/create-apireview.yml index 475e8e362f50..74a5872f47ba 100644 --- a/eng/common/pipelines/templates/steps/create-apireview.yml +++ b/eng/common/pipelines/templates/steps/create-apireview.yml @@ -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: @@ -15,6 +19,7 @@ steps: -APILabel "Auto Review - $(Build.SourceVersion)" -PackageName ${{artifact.name}} -SourceBranch $(Build.SourceBranch) + -DefaultBranch $(DefaultBranch) -ConfigFileDir '${{parameters.ConfigFileDir}}' pwsh: true workingDirectory: $(Pipeline.Workspace) diff --git a/eng/common/scripts/Create-APIReview.ps1 b/eng/common/scripts/Create-APIReview.ps1 index 44e2116dcdeb..bdb14e8e4487 100644 --- a/eng/common/scripts/Create-APIReview.ps1 +++ b/eng/common/scripts/Create-APIReview.ps1 @@ -10,6 +10,7 @@ Param ( [string] $APILabel, [string] $PackageName, [string] $SourceBranch, + [string] $DefaultBranch, [string] $ConfigFileDir = "" ) @@ -94,12 +95,18 @@ if ($packages) # 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) + { + Write-Host "Version info is not available for package. Please check if version follows Azure SDK package versioning guielines." + 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 "master") -or (-not $version.IsPrerelease)) + if ( ($SourceBranch -eq $DefaultBranch) -or (-not $version.IsPrerelease)) { Write-Host "Submitting API Review for package $($pkg)" $response = Submit-APIReview -packagename $pkg -filePath $pkgPath -uri $APIViewUri -apiKey $APIKey -apiLabel $APILabel From d0a4295f05bd3c01541deceb35a40c776db7ee3d Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Mon, 22 Mar 2021 23:15:58 -0700 Subject: [PATCH 3/5] Updated as per review comments --- eng/common/scripts/Create-APIReview.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eng/common/scripts/Create-APIReview.ps1 b/eng/common/scripts/Create-APIReview.ps1 index bdb14e8e4487..1c0bbfbccbc2 100644 --- a/eng/common/scripts/Create-APIReview.ps1 +++ b/eng/common/scripts/Create-APIReview.ps1 @@ -97,7 +97,7 @@ if ($packages) $version = [AzureEngSemanticVersion]::ParseVersionString($pkgInfo.Version) if ($version -eq $null) { - Write-Host "Version info is not available for package. Please check if version follows Azure SDK package versioning guielines." + 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 } @@ -122,7 +122,7 @@ if ($packages) } else { - # Return error code if status code is 201 for track2 data plane package + # Return error code if status code is 201 for new data plane package if ($pkgInfo.SdkType -eq "client" -and $pkgInfo.IsNewSdk) { if ($respCode -eq '201') @@ -140,7 +140,7 @@ if ($packages) } else { - Write-Host "API review is not approved for package $($PackageName). Management and track1 package can be released without API review approval." + 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." } } } From ed1368b1f9a9e14d3ce58479b84387fb06c03417 Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Wed, 24 Mar 2021 17:54:48 -0700 Subject: [PATCH 4/5] Use only branch name instead of path to check --- eng/common/pipelines/templates/steps/create-apireview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/pipelines/templates/steps/create-apireview.yml b/eng/common/pipelines/templates/steps/create-apireview.yml index 74a5872f47ba..cd658132dec0 100644 --- a/eng/common/pipelines/templates/steps/create-apireview.yml +++ b/eng/common/pipelines/templates/steps/create-apireview.yml @@ -18,7 +18,7 @@ steps: -APIKey $(azuresdk-apiview-apikey) -APILabel "Auto Review - $(Build.SourceVersion)" -PackageName ${{artifact.name}} - -SourceBranch $(Build.SourceBranch) + -SourceBranch $(Build.SourceBranchName) -DefaultBranch $(DefaultBranch) -ConfigFileDir '${{parameters.ConfigFileDir}}' pwsh: true From 17c532ce5e07d69776f405bff2080c2c9cc6bee2 Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Thu, 25 Mar 2021 10:18:22 -0700 Subject: [PATCH 5/5] Fix issue in response code check --- eng/common/scripts/Create-APIReview.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eng/common/scripts/Create-APIReview.ps1 b/eng/common/scripts/Create-APIReview.ps1 index 1c0bbfbccbc2..8b9007253274 100644 --- a/eng/common/scripts/Create-APIReview.ps1 +++ b/eng/common/scripts/Create-APIReview.ps1 @@ -109,7 +109,8 @@ if ($packages) if ( ($SourceBranch -eq $DefaultBranch) -or (-not $version.IsPrerelease)) { Write-Host "Submitting API Review for package $($pkg)" - $response = Submit-APIReview -packagename $pkg -filePath $pkgPath -uri $APIViewUri -apiKey $APIKey -apiLabel $APILabel + $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') {