Skip to content

Commit

Permalink
update apiview scripts to support sdk automation (#24152)
Browse files Browse the repository at this point in the history
Co-authored-by: Chidozie Ononiwu <chononiw@microsoft.com>
  • Loading branch information
azure-sdk and chidozieononiwu authored Feb 22, 2025
1 parent bb7663b commit 6ebff76
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
3 changes: 2 additions & 1 deletion eng/common/pipelines/templates/steps/detect-api-changes.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
parameters:
ArtifactPath: $(Build.ArtifactStagingDirectory)
ArtifactName: 'packages'
RepoRoot: $(Build.SourcesDirectory)

steps:
- pwsh: |
Expand All @@ -11,7 +12,7 @@ steps:
- task: Powershell@2
inputs:
filePath: $(Build.SourcesDirectory)/eng/common/scripts/Detect-Api-Changes.ps1
filePath: ${{ parameters.RepoRoot }}/eng/common/scripts/Detect-Api-Changes.ps1
arguments: >
-ArtifactPath ${{parameters.ArtifactPath}}
-CommitSha '$(Build.SourceVersion)'
Expand Down
40 changes: 22 additions & 18 deletions eng/common/scripts/Detect-Api-Changes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ function Submit-Request($filePath, $packageName)
}
$uri = [System.UriBuilder]$APIViewUri
$uri.query = $query.toString()
Write-Host "Request URI: $($uri.Uri.OriginalString)"
LogInfo "Request URI: $($uri.Uri.OriginalString)"
try
{
$Response = Invoke-WebRequest -Method 'GET' -Uri $uri.Uri -MaximumRetryCount 3
$StatusCode = $Response.StatusCode
}
catch
{
Write-Host "Error $StatusCode - Exception details: $($_.Exception.Response)"
LogError "Error $StatusCode - Exception details: $($_.Exception.Response)"
$StatusCode = $_.Exception.Response.StatusCode
}

Expand All @@ -67,42 +67,46 @@ function Should-Process-Package($pkgPath, $packageName)
$pkgPropPath = Join-Path -Path $configFileDir "$packageName.json"
if (!(Test-Path $pkgPropPath))
{
Write-Host " Package property file path $($pkgPropPath) is invalid."
LogWarning "Package property file path $($pkgPropPath) is invalid."
return $False
}
# Get package info from json file created before updating version to daily dev
$pkgInfo = Get-Content $pkgPropPath | ConvertFrom-Json
$packagePath = $pkgInfo.DirectoryPath
$modifiedFiles = @(Get-ChangedFiles -DiffPath "$packagePath/*" -DiffFilterType '')
$filteredFileCount = $modifiedFiles.Count
Write-Host "Number of modified files for package: $filteredFileCount"
LogInfo "Number of modified files for package: $filteredFileCount"
return ($filteredFileCount -gt 0 -and $pkgInfo.IsNewSdk)
}

function Log-Input-Params()
{
Write-Host "Artifact Path: $($ArtifactPath)"
Write-Host "Artifact Name: $($ArtifactName)"
Write-Host "PullRequest Number: $($PullRequestNumber)"
Write-Host "BuildId: $($BuildId)"
Write-Host "Language: $($Language)"
Write-Host "Commit SHA: $($CommitSha)"
Write-Host "Repo Name: $($RepoFullName)"
Write-Host "Project: $($DevopsProject)"
LogGroupStart "Input Parameters for $($ArtifactName)"
LogInfo "Artifact Path: $($ArtifactPath)"
LogInfo "Artifact Name: $($ArtifactName)"
LogInfo "PullRequest Number: $($PullRequestNumber)"
LogInfo "BuildId: $($BuildId)"
LogInfo "Language: $($Language)"
LogInfo "Commit SHA: $($CommitSha)"
LogInfo "Repo Name: $($RepoFullName)"
LogInfo "Project: $($DevopsProject)"
LogGroupEnd
}

Log-Input-Params

if (!($FindArtifactForApiReviewFn -and (Test-Path "Function:$FindArtifactForApiReviewFn")))
{
Write-Host "The function for 'FindArtifactForApiReviewFn' was not found.`
LogError "The function for 'FindArtifactForApiReviewFn' was not found.`
Make sure it is present in eng/scripts/Language-Settings.ps1 and referenced in eng/common/scripts/common.ps1.`
See https://github.com/Azure/azure-sdk-tools/blob/main/doc/common/common_engsys.md#code-structure"
exit 1
}

$responses = @{}

LogInfo "Processing PackageInfo at $configFileDir"

$packageProperties = Get-ChildItem -Recurse -Force "$configFileDir" `
| Where-Object {
$_.Extension -eq '.json' -and ($_.FullName.Substring($configFileDir.Length + 1) -notmatch '^_.*?[\\\/]')
Expand All @@ -113,15 +117,15 @@ foreach ($packagePropFile in $packageProperties)
$packageMetadata = Get-Content $packagePropFile | ConvertFrom-Json
$pkgArtifactName = $packageMetadata.ArtifactName ?? $packageMetadata.Name

Write-Host "Processing $($pkgArtifactName)"
LogInfo "Processing $($pkgArtifactName)"

$packages = &$FindArtifactForApiReviewFn $ArtifactPath $pkgArtifactName

if ($packages)
{
$pkgPath = $packages.Values[0]
$isRequired = Should-Process-Package -pkgPath $pkgPath -packageName $pkgArtifactName
Write-Host "Is API change detect required for $($pkgArtifactName):$($isRequired)"
LogInfo "Is API change detect required for $($pkgArtifactName):$($isRequired)"
if ($isRequired -eq $True)
{
$filePath = $pkgPath.Replace($ArtifactPath , "").Replace("\", "/")
Expand All @@ -133,16 +137,16 @@ foreach ($packagePropFile in $packageProperties)
}
else
{
Write-Host "Pull request does not have any change for $($pkgArtifactName)). Skipping API change detect."
LogInfo "Pull request does not have any change for $($pkgArtifactName)). Skipping API change detect."
}
}
else
{
Write-Host "No package is found in artifact path to find API changes for $($pkgArtifactName)"
LogInfo "No package is found in artifact path to find API changes for $($pkgArtifactName)"
}
}

foreach($pkg in $responses.keys)
{
Write-Host "API detection request status for $($pkg) : $($responses[$pkg])"
LogInfo "API detection request status for $($pkg) : $($responses[$pkg])"
}

0 comments on commit 6ebff76

Please sign in to comment.