|
| 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