Skip to content

Commit e116660

Browse files
azure-sdkpraveenkuttappanweshaggard
authored
Sync eng/common directory with azure-sdk-tools for PR 2011 (#20702)
* Common pipeline template and script to detect API changes * Cahnges as per review comments * Review comment changes * CCahgnes as per review comments * Show warning for list of failed packages to detect API changes * Apply suggestions from code review Co-authored-by: Wes Haggard <[email protected]> Co-authored-by: praveenkuttappan <[email protected]> Co-authored-by: praveenkuttappan <[email protected]> Co-authored-by: Wes Haggard <[email protected]>
1 parent 44e2acf commit e116660

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
parameters:
2+
ArtifactPath: $(Build.ArtifactStagingDirectory)
3+
Artifacts: []
4+
5+
steps:
6+
- task: Powershell@2
7+
inputs:
8+
filePath: $(Build.SourcesDirectory)/eng/common/scripts/Detect-Api-Changes.ps1
9+
arguments: >
10+
-ArtifactList ('${{ convertToJson(parameters.Artifacts) }}' | ConvertFrom-Json | Select-Object Name)
11+
-ArtifactPath ${{parameters.ArtifactPath}}
12+
-CommitSha '$(Build.SourceVersion)'
13+
-BuildId $(Build.BuildId)
14+
-PullRequestNumber $(System.PullRequest.PullRequestNumber)
15+
-RepoFullName $(Build.Repository.Name)
16+
pwsh: true
17+
workingDirectory: $(Pipeline.Workspace)
18+
displayName: Detect API changes
19+
condition: and(succeededOrFailed(), eq(variables['Build.Reason'],'PullRequest'))
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
[CmdletBinding()]
2+
Param (
3+
[Parameter(Mandatory=$True)]
4+
[string] $ArtifactPath,
5+
[Parameter(Mandatory=$True)]
6+
[string] $PullRequestNumber,
7+
[Parameter(Mandatory=$True)]
8+
[string] $BuildId,
9+
[Parameter(Mandatory=$True)]
10+
[string] $CommitSha,
11+
[Parameter(Mandatory=$True)]
12+
[array] $ArtifactList,
13+
[string] $RepoFullName = "",
14+
[string] $ArtifactName = "packages",
15+
[string] $APIViewUri = "https://apiview.dev/PullRequest/DetectApiChanges"
16+
)
17+
18+
# Submit API review request and return status whether current revision is approved or pending or failed to create review
19+
function Submit-Request($filePath)
20+
{
21+
$repoName = $RepoFullName
22+
if (!$repoName) {
23+
$repoName = "azure/azure-sdk-for-$LanguageShort"
24+
}
25+
$query = [System.Web.HttpUtility]::ParseQueryString('')
26+
$query.Add('artifactName', $ArtifactName)
27+
$query.Add('buildId', $BuildId)
28+
$query.Add('filePath', $filePath)
29+
$query.Add('commitSha', $CommitSha)
30+
$query.Add('repoName', $repoName)
31+
$query.Add('pullRequestNumber', $PullRequestNumber)
32+
$uri = [System.UriBuilder]$APIViewUri
33+
$uri.query = $query.toString()
34+
Write-Host "Request URI: $($uri.Uri.OriginalString)"
35+
try
36+
{
37+
$Response = Invoke-WebRequest -Method 'GET' -Uri $uri.Uri -MaximumRetryCount 3
38+
$StatusCode = $Response.StatusCode
39+
}
40+
catch
41+
{
42+
Write-Host "Error $StatusCode - Exception details: $($_.Exception.Response)"
43+
$StatusCode = $_.Exception.Response.StatusCode
44+
}
45+
46+
return $StatusCode
47+
}
48+
49+
function Should-Process-Package($pkgPath, $packageName)
50+
{
51+
$pkg = Split-Path -Leaf $pkgPath
52+
$configFileDir = Join-Path -Path $ArtifactPath "PackageInfo"
53+
$pkgPropPath = Join-Path -Path $configFileDir "$packageName.json"
54+
if (!(Test-Path $pkgPropPath))
55+
{
56+
Write-Host " Package property file path $($pkgPropPath) is invalid."
57+
return $False
58+
}
59+
# Get package info from json file created before updating version to daily dev
60+
$pkgInfo = Get-Content $pkgPropPath | ConvertFrom-Json
61+
Write-Host "SDK Type: $($pkgInfo.SdkType)"
62+
return ($pkgInfo.SdkType -eq "client" -and $pkgInfo.IsNewSdk)
63+
}
64+
65+
function Log-Input-Params()
66+
{
67+
Write-Host "Artifact Path: $($ArtifactPath)"
68+
Write-Host "Artifact Name: $($ArtifactName)"
69+
Write-Host "PullRequest Number: $($PullRequestNumber)"
70+
Write-Host "BuildId: $($BuildId)"
71+
Write-Host "Language: $($Language)"
72+
Write-Host "Commit SHA: $($CommitSha)"
73+
Write-Host "Repo Name: $($RepoFullName)"
74+
}
75+
76+
. (Join-Path $PSScriptRoot common.ps1)
77+
Log-Input-Params
78+
79+
if (!($FindArtifactForApiReviewFn -and (Test-Path "Function:$FindArtifactForApiReviewFn")))
80+
{
81+
Write-Host "The function for 'FindArtifactForApiReviewFn' was not found.`
82+
Make sure it is present in eng/scripts/Language-Settings.ps1 and referenced in eng/common/scripts/common.ps1.`
83+
See https://github.com/Azure/azure-sdk-tools/blob/main/doc/common/common_engsys.md#code-structure"
84+
exit 1
85+
}
86+
87+
$responses = @{}
88+
foreach ($artifact in $ArtifactList)
89+
{
90+
Write-Host "Processing $($artifact.name)"
91+
$packages = &$FindArtifactForApiReviewFn $ArtifactPath $artifact.name
92+
if ($packages)
93+
{
94+
$pkgPath = $packages.Values[0]
95+
if (Should-Process-Package -pkgPath $pkgPath -packageName $artifact.name)
96+
{
97+
$filePath = $pkgPath.Replace($ArtifactPath , "").Replace("\", "/")
98+
$respCode = Submit-Request -filePath $filePath
99+
if ($respCode -ne '200')
100+
{
101+
$responses[$artifact.name] = $respCode
102+
}
103+
}
104+
}
105+
else
106+
{
107+
Write-Host "No package is found in artifact path to find API changes for $($artifact.name)"
108+
}
109+
}
110+
111+
if ($responses)
112+
{
113+
# Will update this with a link to wiki on how to resolve
114+
Write-Warning "API change detection failed for following packages. Please check above for package level error details."
115+
foreach($pkg in $responses.keys)
116+
{
117+
Write-Host "$pkg failed with $($responses[$pkg]) code"
118+
}
119+
}

0 commit comments

Comments
 (0)