Skip to content

Commit 5d2828f

Browse files
azure-sdkscbedd
andauthored
Optimize Service-Level change detection, update ordering of targeted files during impacted package detection (Azure#39936)
Co-authored-by: Scott Beddall <[email protected]>
1 parent 230ab94 commit 5d2828f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

eng/common/scripts/Package-Properties.ps1

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
199199
$additionalValidationPackages = @()
200200
$lookup = @{}
201201

202+
# Sort so that we very quickly find any directly changed packages before hitting service level changes.
203+
# This is important because due to the way we traverse the changed files, the instant we evaluate a pkg
204+
# as directly or indirectly changed, we exit the file loop and move on to the next pkg.
205+
# The problem is, a package may be detected as indirectly changed _before_ we get to the file that directly changed it!
206+
# To avoid this without wonky changes to the detection algorithm, we simply sort our files by their depth, so we will always
207+
# detect direct package changes first!
208+
$targetedFiles = $targetedFiles | Sort-Object { ($_.Split("/").Count) } -Descending
209+
202210
# this is the primary loop that identifies the packages that have changes
203211
foreach ($pkg in $allPackageProperties) {
204212
$pkgDirectory = Resolve-Path "$($pkg.DirectoryPath)"
@@ -263,9 +271,15 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
263271
# we can assume that the path to the ci.yml will successfully resolve.
264272
$ciYml = Join-Path $RepoRoot $yml
265273
# ensure we terminate the service directory with a /
266-
$directory = [System.IO.Path]::GetDirectoryName($ciYml).Replace("`\", "/") + "/"
274+
$directory = [System.IO.Path]::GetDirectoryName($ciYml).Replace("`\", "/")
267275
$soleCIYml = (Get-ChildItem -Path $directory -Filter "ci*.yml" -File).Count -eq 1
268276

277+
# we should only continue with this check if the file being changed is "in the service directory"
278+
$serviceDirectoryChange = (Split-Path $filePath -Parent).Replace("`\", "/") -eq $directory
279+
if (!$serviceDirectoryChange) {
280+
break
281+
}
282+
269283
if ($soleCIYml -and $filePath.Replace("`\", "/").StartsWith($directory)) {
270284
if (-not $shouldInclude) {
271285
$pkg.IncludedForValidation = $true

0 commit comments

Comments
 (0)