diff --git a/eng/common/scripts/Helpers/Package-Helpers.ps1 b/eng/common/scripts/Helpers/Package-Helpers.ps1 index a8537e22a..084bc34ab 100644 --- a/eng/common/scripts/Helpers/Package-Helpers.ps1 +++ b/eng/common/scripts/Helpers/Package-Helpers.ps1 @@ -155,7 +155,7 @@ function GetValueSafelyFrom-Yaml { ) $current = $YamlContentAsHashtable foreach ($key in $Keys) { - if ($current.ContainsKey($key) -or $current[$key]) { + if ($current -is [HashTable] -and ($current.ContainsKey($key) -or $current[$key])) { $current = $current[$key] } else { diff --git a/eng/common/scripts/Package-Properties.ps1 b/eng/common/scripts/Package-Properties.ps1 index 5f5657508..d64e671d1 100644 --- a/eng/common/scripts/Package-Properties.ps1 +++ b/eng/common/scripts/Package-Properties.ps1 @@ -126,6 +126,7 @@ class PackageProps { if ($ciArtifactResult) { $this.ArtifactDetails = [Hashtable]$ciArtifactResult.ArtifactConfig + $this.CIParameters["CIMatrixConfigs"] = @() # if we know this is the matrix for our file, we should now see if there is a custom matrix config for the package $matrixConfigList = GetValueSafelyFrom-Yaml $ciArtifactResult.ParsedYml @("extends", "parameters", "MatrixConfigs") @@ -196,11 +197,22 @@ function Get-PrPkgProperties([string]$InputDiffJson) { $additionalValidationPackages = @() $lookup = @{} + # this is the primary loop that identifies the packages that have changes foreach ($pkg in $allPackageProperties) { $pkgDirectory = Resolve-Path "$($pkg.DirectoryPath)" $lookupKey = ($pkg.DirectoryPath).Replace($RepoRoot, "").TrimStart('\/') $lookup[$lookupKey] = $pkg + # we only honor the individual artifact triggers + # if we were to honor the ci-level triggers, we would simply + # end up in a situation where any change to a service would + # still trigger every package in that service. individual package triggers + # must be added to handle this. + $triggeringPaths = @() + if ($pkg.ArtifactDetails -and $pkg.ArtifactDetails["triggeringPaths"]) { + $triggeringPaths = $pkg.ArtifactDetails["triggeringPaths"] + } + foreach ($file in $targetedFiles) { $shouldExclude = $false foreach ($exclude in $excludePaths) { @@ -213,7 +225,28 @@ function Get-PrPkgProperties([string]$InputDiffJson) { continue } $filePath = (Join-Path $RepoRoot $file) + $shouldInclude = $filePath -like (Join-Path "$pkgDirectory" "*") + + # this implementation guesses the working directory of the ci.yml + foreach($triggerPath in $triggeringPaths) { + $resolvedRelativePath = (Join-Path $RepoRoot $triggerPath) + # utilize the various trigger paths against the targeted file here + if (!$triggerPath.StartsWith("/")){ + $resolvedRelativePath = (Join-Path $RepoRoot "sdk" "$($pkg.ServiceDirectory)" $triggerPath) + } + + # if we are including this package due to one of its additional trigger paths, we need + # to ensure we're counting it as included for validation, not as an actual package change + if ($resolvedRelativePath) { + $includedForValidation = $filePath -like (Join-Path "$resolvedRelativePath" "*") + $shouldInclude = $shouldInclude -or $includedForValidation + if ($includedForValidation) { + $pkg.IncludedForValidation = $true + } + } + } + if ($shouldInclude) { $packagesWithChanges += $pkg @@ -227,6 +260,9 @@ function Get-PrPkgProperties([string]$InputDiffJson) { } } + # add all of the packages that were added purely for validation purposes + # this is executed separately because we need to identify packages added this way as only included for validation + # we don't actually need to build or analyze them. only test them. $existingPackageNames = @($packagesWithChanges | ForEach-Object { $_.Name }) foreach ($addition in $additionalValidationPackages) { $key = $addition.Replace($RepoRoot, "").TrimStart('\/') @@ -241,10 +277,18 @@ function Get-PrPkgProperties([string]$InputDiffJson) { } } + # now pass along the set of packages we've identified, the diff itself, and the full set of package properties + # to locate any additional packages that should be included for validation if ($AdditionalValidationPackagesFromPackageSetFn -and (Test-Path "Function:$AdditionalValidationPackagesFromPackageSetFn")) { $packagesWithChanges += &$AdditionalValidationPackagesFromPackageSetFn $packagesWithChanges $diff $allPackageProperties } + # finally, if we have gotten all the way here and we still don't have any packages, we should include the template service + # packages. We should never return NO validation. + if ($packagesWithChanges.Count -eq 0) { + $packagesWithChanges += ($allPackageProperties | Where-Object { $_.ServiceDirectory -eq "template" }) + } + return $packagesWithChanges }