Skip to content

Commit 6514663

Browse files
azure-sdkraych1
andauthored
Sync eng/common directory with azure-sdk-tools for PR 12416 (#3157)
Sync eng/common directory with azure-sdk-tools for PR Azure/azure-sdk-tools#12416 See [eng/common workflow](https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/README.md#workflow) --------- Co-authored-by: ray chen <[email protected]>
1 parent b15e2f1 commit 6514663

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

eng/common/scripts/Detect-Api-Changes.ps1

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,13 @@ function Submit-Request($filePath, $packageName)
8080
return $StatusCode
8181
}
8282

83-
function Should-Process-Package($pkgPath, $packageName)
83+
function Should-Process-Package($packageInfo)
8484
{
85-
$pkg = Split-Path -Leaf $pkgPath
86-
$pkgPropPath = Join-Path -Path $configFileDir "$packageName.json"
87-
if (!(Test-Path $pkgPropPath))
88-
{
89-
LogWarning "Package property file path $($pkgPropPath) is invalid."
90-
return $False
91-
}
92-
# Get package info from json file created before updating version to daily dev
93-
$pkgInfo = Get-Content $pkgPropPath | ConvertFrom-Json
94-
$packagePath = $pkgInfo.DirectoryPath
85+
$packagePath = $packageInfo.DirectoryPath
9586
$modifiedFiles = @(Get-ChangedFiles -DiffPath "$packagePath/*" -DiffFilterType '')
9687
$filteredFileCount = $modifiedFiles.Count
9788
LogInfo "Number of modified files for package: $filteredFileCount"
98-
return ($filteredFileCount -gt 0 -and $pkgInfo.IsNewSdk)
89+
return ($filteredFileCount -gt 0 -and $packageInfo.IsNewSdk)
9990
}
10091

10192
function Log-Input-Params()
@@ -126,24 +117,42 @@ $responses = @{}
126117

127118
LogInfo "Processing PackageInfo at $configFileDir"
128119

129-
$packageProperties = Get-ChildItem -Recurse -Force "$configFileDir" `
130-
| Where-Object {
120+
$packageInfoFiles = Get-ChildItem -Recurse -Force "$configFileDir" `
121+
| Where-Object {
131122
$_.Extension -eq '.json' -and ($_.FullName.Substring($configFileDir.Length + 1) -notmatch '^_.*?[\\\/]')
132123
}
133124

134-
foreach ($packagePropFile in $packageProperties)
125+
foreach ($packageInfoFile in $packageInfoFiles)
135126
{
136-
$packageMetadata = Get-Content $packagePropFile | ConvertFrom-Json
137-
$pkgArtifactName = $packageMetadata.ArtifactName ?? $packageMetadata.Name
127+
$packageInfo = Get-Content $packageInfoFile | ConvertFrom-Json
128+
$pkgArtifactName = $packageInfo.ArtifactName ?? $packageInfo.Name
138129

139130
LogInfo "Processing $($pkgArtifactName)"
140131

141-
$packages = &$FindArtifactForApiReviewFn $ArtifactPath $pkgArtifactName
132+
# Check if the function supports the packageInfo parameter
133+
$functionInfo = Get-Command $FindArtifactForApiReviewFn -ErrorAction SilentlyContinue
134+
$supportsPackageInfoParam = $false
135+
136+
if ($functionInfo -and $functionInfo.Parameters) {
137+
# Check if function specifically supports packageInfo parameter
138+
$parameterNames = $functionInfo.Parameters.Keys
139+
$supportsPackageInfoParam = $parameterNames -contains 'packageInfo'
140+
}
141+
142+
# Call function with appropriate parameters
143+
if ($supportsPackageInfoParam) {
144+
LogInfo "Calling $FindArtifactForApiReviewFn with packageInfo parameter"
145+
$packages = &$FindArtifactForApiReviewFn $ArtifactPath $pkgArtifactName $packageInfo
146+
}
147+
else {
148+
LogInfo "Calling $FindArtifactForApiReviewFn with legacy parameters"
149+
$packages = &$FindArtifactForApiReviewFn $ArtifactPath $pkgArtifactName
150+
}
142151

143152
if ($packages)
144153
{
145154
$pkgPath = $packages.Values[0]
146-
$isRequired = Should-Process-Package -pkgPath $pkgPath -packageName $pkgArtifactName
155+
$isRequired = Should-Process-Package $packageInfo
147156
LogInfo "Is API change detect required for $($pkgArtifactName):$($isRequired)"
148157
if ($isRequired -eq $True)
149158
{
@@ -156,7 +165,7 @@ foreach ($packagePropFile in $packageProperties)
156165
}
157166
else
158167
{
159-
LogInfo "Pull request does not have any change for $($pkgArtifactName)). Skipping API change detect."
168+
LogInfo "Pull request does not have any change for $($pkgArtifactName). Skipping API change detect."
160169
}
161170
}
162171
else

0 commit comments

Comments
 (0)