From f6fa235697077a21a87a205fb5bc6cf5c2cb3d56 Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Tue, 4 Mar 2025 12:17:08 -0800 Subject: [PATCH] Optimize Service-Level change detection, update ordering of targeted files during impacted package detection (#6446) Co-authored-by: Scott Beddall --- eng/common/scripts/Package-Properties.ps1 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/eng/common/scripts/Package-Properties.ps1 b/eng/common/scripts/Package-Properties.ps1 index 940982661..9d08a1a0c 100644 --- a/eng/common/scripts/Package-Properties.ps1 +++ b/eng/common/scripts/Package-Properties.ps1 @@ -199,6 +199,14 @@ function Get-PrPkgProperties([string]$InputDiffJson) { $additionalValidationPackages = @() $lookup = @{} + # Sort so that we very quickly find any directly changed packages before hitting service level changes. + # This is important because due to the way we traverse the changed files, the instant we evaluate a pkg + # as directly or indirectly changed, we exit the file loop and move on to the next pkg. + # The problem is, a package may be detected as indirectly changed _before_ we get to the file that directly changed it! + # To avoid this without wonky changes to the detection algorithm, we simply sort our files by their depth, so we will always + # detect direct package changes first! + $targetedFiles = $targetedFiles | Sort-Object { ($_.Split("/").Count) } -Descending + # this is the primary loop that identifies the packages that have changes foreach ($pkg in $allPackageProperties) { $pkgDirectory = Resolve-Path "$($pkg.DirectoryPath)" @@ -263,9 +271,15 @@ function Get-PrPkgProperties([string]$InputDiffJson) { # we can assume that the path to the ci.yml will successfully resolve. $ciYml = Join-Path $RepoRoot $yml # ensure we terminate the service directory with a / - $directory = [System.IO.Path]::GetDirectoryName($ciYml).Replace("`\", "/") + "/" + $directory = [System.IO.Path]::GetDirectoryName($ciYml).Replace("`\", "/") $soleCIYml = (Get-ChildItem -Path $directory -Filter "ci*.yml" -File).Count -eq 1 + # we should only continue with this check if the file being changed is "in the service directory" + $serviceDirectoryChange = (Split-Path $filePath -Parent).Replace("`\", "/") -eq $directory + if (!$serviceDirectoryChange) { + break + } + if ($soleCIYml -and $filePath.Replace("`\", "/").StartsWith($directory)) { if (-not $shouldInclude) { $pkg.IncludedForValidation = $true