Skip to content

Commit 26d734c

Browse files
update apiview scripts to support sdk automation (Azure#2215)
Co-authored-by: Chidozie Ononiwu <[email protected]>
1 parent afea03d commit 26d734c

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

eng/common/pipelines/templates/steps/detect-api-changes.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
parameters:
22
ArtifactPath: $(Build.ArtifactStagingDirectory)
33
ArtifactName: 'packages'
4+
RepoRoot: $(Build.SourcesDirectory)
45

56
steps:
67
- pwsh: |
@@ -11,7 +12,7 @@ steps:
1112
1213
- task: Powershell@2
1314
inputs:
14-
filePath: $(Build.SourcesDirectory)/eng/common/scripts/Detect-Api-Changes.ps1
15+
filePath: ${{ parameters.RepoRoot }}/eng/common/scripts/Detect-Api-Changes.ps1
1516
arguments: >
1617
-ArtifactPath ${{parameters.ArtifactPath}}
1718
-CommitSha '$(Build.SourceVersion)'

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ function Submit-Request($filePath, $packageName)
4646
}
4747
$uri = [System.UriBuilder]$APIViewUri
4848
$uri.query = $query.toString()
49-
Write-Host "Request URI: $($uri.Uri.OriginalString)"
49+
LogInfo "Request URI: $($uri.Uri.OriginalString)"
5050
try
5151
{
5252
$Response = Invoke-WebRequest -Method 'GET' -Uri $uri.Uri -MaximumRetryCount 3
5353
$StatusCode = $Response.StatusCode
5454
}
5555
catch
5656
{
57-
Write-Host "Error $StatusCode - Exception details: $($_.Exception.Response)"
57+
LogError "Error $StatusCode - Exception details: $($_.Exception.Response)"
5858
$StatusCode = $_.Exception.Response.StatusCode
5959
}
6060

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

8282
function Log-Input-Params()
8383
{
84-
Write-Host "Artifact Path: $($ArtifactPath)"
85-
Write-Host "Artifact Name: $($ArtifactName)"
86-
Write-Host "PullRequest Number: $($PullRequestNumber)"
87-
Write-Host "BuildId: $($BuildId)"
88-
Write-Host "Language: $($Language)"
89-
Write-Host "Commit SHA: $($CommitSha)"
90-
Write-Host "Repo Name: $($RepoFullName)"
91-
Write-Host "Project: $($DevopsProject)"
84+
LogGroupStart "Input Parameters for $($ArtifactName)"
85+
LogInfo "Artifact Path: $($ArtifactPath)"
86+
LogInfo "Artifact Name: $($ArtifactName)"
87+
LogInfo "PullRequest Number: $($PullRequestNumber)"
88+
LogInfo "BuildId: $($BuildId)"
89+
LogInfo "Language: $($Language)"
90+
LogInfo "Commit SHA: $($CommitSha)"
91+
LogInfo "Repo Name: $($RepoFullName)"
92+
LogInfo "Project: $($DevopsProject)"
93+
LogGroupEnd
9294
}
9395

9496
Log-Input-Params
9597

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

104106
$responses = @{}
105107

108+
LogInfo "Processing PackageInfo at $configFileDir"
109+
106110
$packageProperties = Get-ChildItem -Recurse -Force "$configFileDir" `
107111
| Where-Object {
108112
$_.Extension -eq '.json' -and ($_.FullName.Substring($configFileDir.Length + 1) -notmatch '^_.*?[\\\/]')
@@ -113,15 +117,15 @@ foreach ($packagePropFile in $packageProperties)
113117
$packageMetadata = Get-Content $packagePropFile | ConvertFrom-Json
114118
$pkgArtifactName = $packageMetadata.ArtifactName ?? $packageMetadata.Name
115119

116-
Write-Host "Processing $($pkgArtifactName)"
120+
LogInfo "Processing $($pkgArtifactName)"
117121

118122
$packages = &$FindArtifactForApiReviewFn $ArtifactPath $pkgArtifactName
119123

120124
if ($packages)
121125
{
122126
$pkgPath = $packages.Values[0]
123127
$isRequired = Should-Process-Package -pkgPath $pkgPath -packageName $pkgArtifactName
124-
Write-Host "Is API change detect required for $($pkgArtifactName):$($isRequired)"
128+
LogInfo "Is API change detect required for $($pkgArtifactName):$($isRequired)"
125129
if ($isRequired -eq $True)
126130
{
127131
$filePath = $pkgPath.Replace($ArtifactPath , "").Replace("\", "/")
@@ -133,16 +137,16 @@ foreach ($packagePropFile in $packageProperties)
133137
}
134138
else
135139
{
136-
Write-Host "Pull request does not have any change for $($pkgArtifactName)). Skipping API change detect."
140+
LogInfo "Pull request does not have any change for $($pkgArtifactName)). Skipping API change detect."
137141
}
138142
}
139143
else
140144
{
141-
Write-Host "No package is found in artifact path to find API changes for $($pkgArtifactName)"
145+
LogInfo "No package is found in artifact path to find API changes for $($pkgArtifactName)"
142146
}
143147
}
144148

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

0 commit comments

Comments
 (0)