From 59e620318e4dbcb8a56791553835cda1b879a724 Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Wed, 2 Mar 2022 09:03:02 -0800 Subject: [PATCH] Check API changes only if package is modified (#3385) Co-authored-by: praveenkuttappan --- .../templates/steps/detect-api-changes.yml | 1 - eng/common/scripts/Detect-Api-Changes.ps1 | 19 +++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/eng/common/pipelines/templates/steps/detect-api-changes.yml b/eng/common/pipelines/templates/steps/detect-api-changes.yml index de4dd5675..82669a631 100644 --- a/eng/common/pipelines/templates/steps/detect-api-changes.yml +++ b/eng/common/pipelines/templates/steps/detect-api-changes.yml @@ -14,6 +14,5 @@ steps: -PullRequestNumber $(System.PullRequest.PullRequestNumber) -RepoFullName $(Build.Repository.Name) pwsh: true - workingDirectory: $(Pipeline.Workspace) displayName: Detect API changes condition: and(succeededOrFailed(), eq(variables['Build.Reason'],'PullRequest')) diff --git a/eng/common/scripts/Detect-Api-Changes.ps1 b/eng/common/scripts/Detect-Api-Changes.ps1 index e5c054013..fd5cdb68b 100644 --- a/eng/common/scripts/Detect-Api-Changes.ps1 +++ b/eng/common/scripts/Detect-Api-Changes.ps1 @@ -12,7 +12,8 @@ Param ( [array] $ArtifactList, [string] $RepoFullName = "", [string] $ArtifactName = "packages", - [string] $APIViewUri = "https://apiview.dev/PullRequest/DetectApiChanges" + [string] $APIViewUri = "https://apiview.dev/PullRequest/DetectApiChanges", + [string] $TargetBranch = ("origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}" -replace "refs/heads/") ) # Submit API review request and return status whether current revision is approved or pending or failed to create review @@ -59,8 +60,12 @@ function Should-Process-Package($pkgPath, $packageName) } # Get package info from json file created before updating version to daily dev $pkgInfo = Get-Content $pkgPropPath | ConvertFrom-Json - Write-Host "SDK Type: $($pkgInfo.SdkType)" - return $pkgInfo.IsNewSdk + $packagePath = $pkgInfo.DirectoryPath + $modifiedFiles = git diff --name-only --relative $TargetBranch HEAD + $modifiedFiles = $modifiedFiles.Where({$_.startswith($packagePath)}) + $filteredFileCount = $modifiedFiles.Count + Write-Host "Number of modified files for package: $filteredFileCount" + return ($filteredFileCount -gt 0 -and $pkgInfo.IsNewSdk) } function Log-Input-Params() @@ -94,7 +99,9 @@ foreach ($artifact in $ArtifactList) if ($packages) { $pkgPath = $packages.Values[0] - if (Should-Process-Package -pkgPath $pkgPath -packageName $artifact.name) + $isRequired = Should-Process-Package -pkgPath $pkgPath -packageName $artifact.name + Write-Host "Is API change detect required for $($artifact.name):$($isRequired)" + if ($isRequired -eq $True) { $filePath = $pkgPath.Replace($ArtifactPath , "").Replace("\", "/") $respCode = Submit-Request -filePath $filePath -packageName $artifact.name @@ -103,6 +110,10 @@ foreach ($artifact in $ArtifactList) $responses[$artifact.name] = $respCode } } + else + { + Write-Host "Pull request does not have any change for $($artifact.name). Skipping API change detect." + } } else {