From d92a43b16b77347554a48e93a3789556a5c0f57d Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Tue, 30 Mar 2021 11:06:12 -0700 Subject: [PATCH 1/8] Add API status check --- eng/common/scripts/Prepare-Release.ps1 | 58 +++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/eng/common/scripts/Prepare-Release.ps1 b/eng/common/scripts/Prepare-Release.ps1 index 2c7b61522048..3751ee1ecf21 100644 --- a/eng/common/scripts/Prepare-Release.ps1 +++ b/eng/common/scripts/Prepare-Release.ps1 @@ -64,6 +64,55 @@ function Get-ReleaseDay($baseDate) return $baseDate; } +function Check-ApiReviewStatus($packageName, $language) +{ + # Get API view URL and API Key to check status + Login-AzAccount + $url = Get-AzKeyvaultSecret -VaultName "AzureSDKPrepRelease-KV" -Name APIURL -AsPlainText + $apiKey = Get-AzKeyvaultSecret -VaultName "AzureSDKPrepRelease-KV" -Name APIKEY -AsPlainText + + $lang = $language + # Update language name to match those in API cosmos DB. Cosmos SQL is case sensitive and handling this within the query makes it slow. + if($lang -eq 'javascript'){ + $lang = "JavaScript" + } + elseif ($lang -eq "dotnet"){ + $lang = "C#" + } + elseif ($lang -eq "java"){ + $lang = "Java" + } + elseif ($lang -eq "python"){ + $lang = "Python" + } + + $headers = @{ "ApiKey" = $apiKey } + $body = @{ + language = $lang + packageName = $packageName + } + + try + { + $Response = Invoke-WebRequest $url -Method 'GET' -Headers $headers -Body $body + Write-Host "Response: $($Response.Content)" + if ($Response.StatusCode -eq '200') + { + Write-Host "API Review is approved for package $($packageName)" + } + else + { + Write-Error "API Review is not approved for package $($packageName). Please get automatic API review approved by architects." + Write-Host "You can check http://aka.ms/azsdk/engsys/apireview/faq for more details on API Approval." + } + } + catch + { + Write-Host "Exception details: $($_.Exception.Response)" + Write-Host "Failed to check API review status for package $($PackageName). You can check http://aka.ms/azsdk/engsys/apireview/faq for more details on API Approval." + } +} + $ErrorPreference = 'Stop' $packageProperties = $null @@ -127,7 +176,14 @@ if ($null -eq $newVersionParsed) exit 1 } -&$EngCommonScriptsDir/Update-DevOps-Release-WorkItem.ps1 ` +# Check API status if version is GA +if (-not $newVersionParsed.IsPrerelease) +{ + Check-ApiReviewStatus -PackageName $packageProperties.Name -Language $LanguageDisplayName +} + +exit 0 +##&$EngCommonScriptsDir/Update-DevOps-Release-WorkItem.ps1 ` -language $LanguageDisplayName ` -packageName $packageProperties.Name ` -version $newVersion ` From c10870b3aa3557222f8cd86c53cd334639100e51 Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Wed, 19 May 2021 12:24:37 -0400 Subject: [PATCH 2/8] Revert temp change --- eng/common/scripts/Prepare-Release.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/eng/common/scripts/Prepare-Release.ps1 b/eng/common/scripts/Prepare-Release.ps1 index 3751ee1ecf21..4dd24190d5e4 100644 --- a/eng/common/scripts/Prepare-Release.ps1 +++ b/eng/common/scripts/Prepare-Release.ps1 @@ -182,8 +182,7 @@ if (-not $newVersionParsed.IsPrerelease) Check-ApiReviewStatus -PackageName $packageProperties.Name -Language $LanguageDisplayName } -exit 0 -##&$EngCommonScriptsDir/Update-DevOps-Release-WorkItem.ps1 ` +&$EngCommonScriptsDir/Update-DevOps-Release-WorkItem.ps1 ` -language $LanguageDisplayName ` -packageName $packageProperties.Name ` -version $newVersion ` From e4ecd4e54cade42e6fbac27113c2b8cdf0d0bd9a Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Thu, 20 May 2021 10:13:21 -0400 Subject: [PATCH 3/8] Update as per review comments --- eng/common/scripts/Prepare-Release.ps1 | 56 ++++---------------------- eng/common/scripts/apiview-helper.ps1 | 56 ++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 49 deletions(-) create mode 100644 eng/common/scripts/apiview-helper.ps1 diff --git a/eng/common/scripts/Prepare-Release.ps1 b/eng/common/scripts/Prepare-Release.ps1 index 4dd24190d5e4..4155109b1444 100644 --- a/eng/common/scripts/Prepare-Release.ps1 +++ b/eng/common/scripts/Prepare-Release.ps1 @@ -49,6 +49,7 @@ param( Set-StrictMode -Version 3 . ${PSScriptRoot}\common.ps1 +. ${PSScriptRoot}\apiview-helper.ps1 function Get-ReleaseDay($baseDate) { @@ -64,54 +65,6 @@ function Get-ReleaseDay($baseDate) return $baseDate; } -function Check-ApiReviewStatus($packageName, $language) -{ - # Get API view URL and API Key to check status - Login-AzAccount - $url = Get-AzKeyvaultSecret -VaultName "AzureSDKPrepRelease-KV" -Name APIURL -AsPlainText - $apiKey = Get-AzKeyvaultSecret -VaultName "AzureSDKPrepRelease-KV" -Name APIKEY -AsPlainText - - $lang = $language - # Update language name to match those in API cosmos DB. Cosmos SQL is case sensitive and handling this within the query makes it slow. - if($lang -eq 'javascript'){ - $lang = "JavaScript" - } - elseif ($lang -eq "dotnet"){ - $lang = "C#" - } - elseif ($lang -eq "java"){ - $lang = "Java" - } - elseif ($lang -eq "python"){ - $lang = "Python" - } - - $headers = @{ "ApiKey" = $apiKey } - $body = @{ - language = $lang - packageName = $packageName - } - - try - { - $Response = Invoke-WebRequest $url -Method 'GET' -Headers $headers -Body $body - Write-Host "Response: $($Response.Content)" - if ($Response.StatusCode -eq '200') - { - Write-Host "API Review is approved for package $($packageName)" - } - else - { - Write-Error "API Review is not approved for package $($packageName). Please get automatic API review approved by architects." - Write-Host "You can check http://aka.ms/azsdk/engsys/apireview/faq for more details on API Approval." - } - } - catch - { - Write-Host "Exception details: $($_.Exception.Response)" - Write-Host "Failed to check API review status for package $($PackageName). You can check http://aka.ms/azsdk/engsys/apireview/faq for more details on API Approval." - } -} $ErrorPreference = 'Stop' @@ -179,7 +132,12 @@ if ($null -eq $newVersionParsed) # Check API status if version is GA if (-not $newVersionParsed.IsPrerelease) { - Check-ApiReviewStatus -PackageName $packageProperties.Name -Language $LanguageDisplayName + $isApproved = Check-ApiReviewStatus -PackageName $packageProperties.Name -Language $LanguageDisplayName + if (-not $isApproved) + { + Write-Error "API review is not approved in APIView system." + exit 1 + } } &$EngCommonScriptsDir/Update-DevOps-Release-WorkItem.ps1 ` diff --git a/eng/common/scripts/apiview-helper.ps1 b/eng/common/scripts/apiview-helper.ps1 new file mode 100644 index 000000000000..2cfec18904f5 --- /dev/null +++ b/eng/common/scripts/apiview-helper.ps1 @@ -0,0 +1,56 @@ + + +function Map-LanguageToAPiview-Filter($language) +{ + $lang = $language + # Update language name to match those in API cosmos DB. Cosmos SQL is case sensitive and handling this within the query makes it slow. + if($lang -eq 'javascript'){ + $lang = "JavaScript" + } + elseif ($lang -eq "dotnet"){ + $lang = "C#" + } + elseif ($lang -eq "java"){ + $lang = "Java" + } + elseif ($lang -eq "python"){ + $lang = "Python" + } + return $lang +} + +function Check-ApiReviewStatus($packageName, $language) +{ + # Get API view URL and API Key to check status + Login-AzAccount + $url = Get-AzKeyvaultSecret -VaultName "AzureSDKPrepRelease-KV" -Name APIURL -AsPlainText + $apiKey = Get-AzKeyvaultSecret -VaultName "AzureSDKPrepRelease-KV" -Name APIKEY -AsPlainText + + $lang = Map-LanguageToAPiview-Filter -language $language + $headers = @{ "ApiKey" = $apiKey } + $body = @{ + language = $lang + packageName = $packageName + } + + try + { + $Response = Invoke-WebRequest $url -Method 'GET' -Headers $headers -Body $body + if ($Response.StatusCode -eq '200') + { + Write-Host "API Review is approved for package $($packageName)" + return $true + } + else + { + Write-Host "API Review is not approved for package $($packageName). Please get automatic API review approved by architects." + Write-Host "You can check http://aka.ms/azsdk/engsys/apireview/faq for more details on API Approval." + } + } + catch + { + Write-Host "Exception details: $($_.Exception.Response)" + Write-Host "Failed to check API review status for package $($PackageName). You can check http://aka.ms/azsdk/engsys/apireview/faq for more details on API Approval." + } + return $false +} \ No newline at end of file From 1acaf4b648e91cca07866aa1b8906066b3b3823b Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Thu, 20 May 2021 12:00:09 -0400 Subject: [PATCH 4/8] Removed blank line --- eng/common/scripts/Prepare-Release.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/eng/common/scripts/Prepare-Release.ps1 b/eng/common/scripts/Prepare-Release.ps1 index 4155109b1444..81d03d0b3bf4 100644 --- a/eng/common/scripts/Prepare-Release.ps1 +++ b/eng/common/scripts/Prepare-Release.ps1 @@ -65,7 +65,6 @@ function Get-ReleaseDay($baseDate) return $baseDate; } - $ErrorPreference = 'Stop' $packageProperties = $null From 536f562eed599f7ec662a3c344814a7923a5eb65 Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Mon, 24 May 2021 12:58:03 -0400 Subject: [PATCH 5/8] Review comments to use az cli --- .../ApiView-Helpers.ps1} | 22 +++++++++++------ eng/common/scripts/Prepare-Release.ps1 | 24 +++++++++---------- 2 files changed, 27 insertions(+), 19 deletions(-) rename eng/common/scripts/{apiview-helper.ps1 => Helpers/ApiView-Helpers.ps1} (67%) diff --git a/eng/common/scripts/apiview-helper.ps1 b/eng/common/scripts/Helpers/ApiView-Helpers.ps1 similarity index 67% rename from eng/common/scripts/apiview-helper.ps1 rename to eng/common/scripts/Helpers/ApiView-Helpers.ps1 index 2cfec18904f5..fdeac61677c2 100644 --- a/eng/common/scripts/apiview-helper.ps1 +++ b/eng/common/scripts/Helpers/ApiView-Helpers.ps1 @@ -1,5 +1,3 @@ - - function Map-LanguageToAPiview-Filter($language) { $lang = $language @@ -19,18 +17,28 @@ function Map-LanguageToAPiview-Filter($language) return $lang } -function Check-ApiReviewStatus($packageName, $language) +function Check-ApiReviewStatus($packageName, $packageVersion, $language) { # Get API view URL and API Key to check status - Login-AzAccount - $url = Get-AzKeyvaultSecret -VaultName "AzureSDKPrepRelease-KV" -Name APIURL -AsPlainText - $apiKey = Get-AzKeyvaultSecret -VaultName "AzureSDKPrepRelease-KV" -Name APIKEY -AsPlainText - + Write-Host "Checking API review status" + try + { + az login -o none + $url = az keyvault secret show --name "APIURL" --vault-name "AzureSDKPrepRelease-KV" --query "value" --output "tsv" + $apiKey = az keyvault secret show --name "APIKEY" --vault-name "AzureSDKPrepRelease-KV" --query "value" --output "tsv" + } + catch + { + Write-Host "Failed to get APIView URL and API Key from Keyvault AzureSDKPrepRelease-KV. Please check and ensure you have access to this Keyvault as reader." + Write-Host "You can check http://aka.ms/azsdk/engsys/apireview/faq for more details." + } + $lang = Map-LanguageToAPiview-Filter -language $language $headers = @{ "ApiKey" = $apiKey } $body = @{ language = $lang packageName = $packageName + packageVersion = $packageVersion } try diff --git a/eng/common/scripts/Prepare-Release.ps1 b/eng/common/scripts/Prepare-Release.ps1 index 81d03d0b3bf4..5485b6c7eac2 100644 --- a/eng/common/scripts/Prepare-Release.ps1 +++ b/eng/common/scripts/Prepare-Release.ps1 @@ -49,7 +49,7 @@ param( Set-StrictMode -Version 3 . ${PSScriptRoot}\common.ps1 -. ${PSScriptRoot}\apiview-helper.ps1 +. ${PSScriptRoot}\Helpers\ApiView-Helpers.ps1 function Get-ReleaseDay($baseDate) { @@ -128,17 +128,6 @@ if ($null -eq $newVersionParsed) exit 1 } -# Check API status if version is GA -if (-not $newVersionParsed.IsPrerelease) -{ - $isApproved = Check-ApiReviewStatus -PackageName $packageProperties.Name -Language $LanguageDisplayName - if (-not $isApproved) - { - Write-Error "API review is not approved in APIView system." - exit 1 - } -} - &$EngCommonScriptsDir/Update-DevOps-Release-WorkItem.ps1 ` -language $LanguageDisplayName ` -packageName $packageProperties.Name ` @@ -153,6 +142,17 @@ if ($LASTEXITCODE -ne 0) { exit 1 } +# Check API status if version is GA +if (!$newVersionParsed.IsPrerelease) +{ + $isApproved = Check-ApiReviewStatus -PackageName $packageProperties.Name -packageVersion $newVersion -Language $LanguageDisplayName + if (!$isApproved) + { + Write-Error "API review is not approved in APIView system." + exit 1 + } +} + if ($releaseTrackingOnly) { Write-Host From 65b284392075a1034e8ae3adc0ea10812b608c91 Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Tue, 25 May 2021 09:40:20 -0400 Subject: [PATCH 6/8] Changes to move az cli commands to caller script and other review comments --- .../scripts/Helpers/ApiView-Helpers.ps1 | 28 +++++-------------- eng/common/scripts/Prepare-Release.ps1 | 19 +++++++++---- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/eng/common/scripts/Helpers/ApiView-Helpers.ps1 b/eng/common/scripts/Helpers/ApiView-Helpers.ps1 index fdeac61677c2..63b126ad2c87 100644 --- a/eng/common/scripts/Helpers/ApiView-Helpers.ps1 +++ b/eng/common/scripts/Helpers/ApiView-Helpers.ps1 @@ -1,4 +1,4 @@ -function Map-LanguageToAPiview-Filter($language) +function MapLanguageName($language) { $lang = $language # Update language name to match those in API cosmos DB. Cosmos SQL is case sensitive and handling this within the query makes it slow. @@ -17,23 +17,11 @@ function Map-LanguageToAPiview-Filter($language) return $lang } -function Check-ApiReviewStatus($packageName, $packageVersion, $language) +function Check-ApiReviewStatus($packageName, $packageVersion, $language, $url, $apiKey) { # Get API view URL and API Key to check status Write-Host "Checking API review status" - try - { - az login -o none - $url = az keyvault secret show --name "APIURL" --vault-name "AzureSDKPrepRelease-KV" --query "value" --output "tsv" - $apiKey = az keyvault secret show --name "APIKEY" --vault-name "AzureSDKPrepRelease-KV" --query "value" --output "tsv" - } - catch - { - Write-Host "Failed to get APIView URL and API Key from Keyvault AzureSDKPrepRelease-KV. Please check and ensure you have access to this Keyvault as reader." - Write-Host "You can check http://aka.ms/azsdk/engsys/apireview/faq for more details." - } - - $lang = Map-LanguageToAPiview-Filter -language $language + $lang = MapLanguageName -language $language $headers = @{ "ApiKey" = $apiKey } $body = @{ language = $lang @@ -43,22 +31,20 @@ function Check-ApiReviewStatus($packageName, $packageVersion, $language) try { - $Response = Invoke-WebRequest $url -Method 'GET' -Headers $headers -Body $body - if ($Response.StatusCode -eq '200') + $response = Invoke-WebRequest $url -Method 'GET' -Headers $headers -Body $body + if ($response.StatusCode -eq '200') { Write-Host "API Review is approved for package $($packageName)" - return $true } else { - Write-Host "API Review is not approved for package $($packageName). Please get automatic API review approved by architects." + Write-Warning "API Review is not approved for package $($packageName). Release pipeline will fail if API review is not approved." Write-Host "You can check http://aka.ms/azsdk/engsys/apireview/faq for more details on API Approval." } } catch { Write-Host "Exception details: $($_.Exception.Response)" - Write-Host "Failed to check API review status for package $($PackageName). You can check http://aka.ms/azsdk/engsys/apireview/faq for more details on API Approval." + Write-Warning "Failed to check API review status for package $($PackageName). You can check http://aka.ms/azsdk/engsys/apireview/faq for more details on API Approval." } - return $false } \ No newline at end of file diff --git a/eng/common/scripts/Prepare-Release.ps1 b/eng/common/scripts/Prepare-Release.ps1 index 5485b6c7eac2..eed113299a2e 100644 --- a/eng/common/scripts/Prepare-Release.ps1 +++ b/eng/common/scripts/Prepare-Release.ps1 @@ -144,12 +144,21 @@ if ($LASTEXITCODE -ne 0) { # Check API status if version is GA if (!$newVersionParsed.IsPrerelease) -{ - $isApproved = Check-ApiReviewStatus -PackageName $packageProperties.Name -packageVersion $newVersion -Language $LanguageDisplayName - if (!$isApproved) +{ + try + { + az account show *> $null + if (!$?) { + Write-Host 'Running az login...' + az login *> $null + } + $url = az keyvault secret show --name "APIURL" --vault-name "AzureSDKPrepRelease-KV" --query "value" --output "tsv" + $apiKey = az keyvault secret show --name "APIKEY" --vault-name "AzureSDKPrepRelease-KV" --query "value" --output "tsv" + Check-ApiReviewStatus -PackageName $packageProperties.Name -packageVersion $newVersion -Language $LanguageDisplayName -url $url -apiKey $apiKey + } + catch { - Write-Error "API review is not approved in APIView system." - exit 1 + Write-Warning "Failed to get APIView URL and API Key from Keyvault AzureSDKPrepRelease-KV. Please check and ensure you have access to this Keyvault as reader." } } From c317599aff8869eb80e514d5ea67ec6f9c004f2d Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Wed, 26 May 2021 22:10:47 -0400 Subject: [PATCH 7/8] Skip languages that's not supported in APIView --- eng/common/scripts/Helpers/ApiView-Helpers.ps1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/eng/common/scripts/Helpers/ApiView-Helpers.ps1 b/eng/common/scripts/Helpers/ApiView-Helpers.ps1 index 63b126ad2c87..c9d9b1c07e33 100644 --- a/eng/common/scripts/Helpers/ApiView-Helpers.ps1 +++ b/eng/common/scripts/Helpers/ApiView-Helpers.ps1 @@ -14,7 +14,7 @@ function MapLanguageName($language) elseif ($lang -eq "python"){ $lang = "Python" } - return $lang + return $null } function Check-ApiReviewStatus($packageName, $packageVersion, $language, $url, $apiKey) @@ -22,6 +22,9 @@ function Check-ApiReviewStatus($packageName, $packageVersion, $language, $url, $ # Get API view URL and API Key to check status Write-Host "Checking API review status" $lang = MapLanguageName -language $language + if ($lang -eq $null) { + return + } $headers = @{ "ApiKey" = $apiKey } $body = @{ language = $lang @@ -44,7 +47,6 @@ function Check-ApiReviewStatus($packageName, $packageVersion, $language, $url, $ } catch { - Write-Host "Exception details: $($_.Exception.Response)" Write-Warning "Failed to check API review status for package $($PackageName). You can check http://aka.ms/azsdk/engsys/apireview/faq for more details on API Approval." } } \ No newline at end of file From d441c7bc7cba974a22feb187ae939079bc925ee4 Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Thu, 27 May 2021 17:00:16 -0400 Subject: [PATCH 8/8] Fix bug in language mapping --- eng/common/scripts/Helpers/ApiView-Helpers.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/eng/common/scripts/Helpers/ApiView-Helpers.ps1 b/eng/common/scripts/Helpers/ApiView-Helpers.ps1 index c9d9b1c07e33..3be12566e239 100644 --- a/eng/common/scripts/Helpers/ApiView-Helpers.ps1 +++ b/eng/common/scripts/Helpers/ApiView-Helpers.ps1 @@ -14,7 +14,10 @@ function MapLanguageName($language) elseif ($lang -eq "python"){ $lang = "Python" } - return $null + else{ + $lang = $null + } + return $lang } function Check-ApiReviewStatus($packageName, $packageVersion, $language, $url, $apiKey)