@@ -91,6 +91,7 @@ class PackageProps {
9191 $result = [PSCustomObject ]@ {
9292 ArtifactConfig = [HashTable ]$artifactForCurrentPackage
9393 ParsedYml = $content
94+ Location = $ymlPath
9495 }
9596
9697 return $result
@@ -126,6 +127,14 @@ class PackageProps {
126127
127128 if ($ciArtifactResult ) {
128129 $this.ArtifactDetails = [Hashtable ]$ciArtifactResult.ArtifactConfig
130+
131+ if (-not $this.ArtifactDetails [" triggeringPaths" ]) {
132+ $this.ArtifactDetails [" triggeringPaths" ] = @ ()
133+ }
134+ $RepoRoot = Resolve-Path (Join-Path $PSScriptRoot " .." " .." " .." )
135+ $relativePath = (Resolve-Path - Path $ciArtifactResult.Location - Relative - RelativeBasePath $RepoRoot ).TrimStart(" ." ).Replace(" `\" , " /" )
136+ $this.ArtifactDetails [" triggeringPaths" ] += $relativePath
137+
129138 $this.CIParameters [" CIMatrixConfigs" ] = @ ()
130139
131140 # if we know this is the matrix for our file, we should now see if there is a custom matrix config for the package
@@ -207,6 +216,7 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
207216 }
208217
209218 foreach ($file in $targetedFiles ) {
219+ $pathComponents = $file -split " /"
210220 $shouldExclude = $false
211221 foreach ($exclude in $excludePaths ) {
212222 if ($file.StartsWith ($exclude , ' CurrentCultureIgnoreCase' )) {
@@ -219,12 +229,12 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
219229 }
220230 $filePath = (Join-Path $RepoRoot $file )
221231
232+ # handle direct changes to packages
222233 $shouldInclude = $filePath -like (Join-Path " $pkgDirectory " " *" )
223234
224- # this implementation guesses the working directory of the ci.yml
235+ # handle changes to files that are RELATED to each package
225236 foreach ($triggerPath in $triggeringPaths ) {
226237 $resolvedRelativePath = (Join-Path $RepoRoot $triggerPath )
227- # utilize the various trigger paths against the targeted file here
228238 if (! $triggerPath.StartsWith (" /" )){
229239 $resolvedRelativePath = (Join-Path $RepoRoot " sdk" " $ ( $pkg.ServiceDirectory ) " $triggerPath )
230240 }
@@ -237,6 +247,36 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
237247 if ($includedForValidation ) {
238248 $pkg.IncludedForValidation = $true
239249 }
250+ break
251+ }
252+ }
253+
254+ # handle service-level changes to the ci.yml files
255+ # we are using the ci.yml file being added automatically to each artifactdetails as the input
256+ # for this task. This is because we can resolve a service directory from the ci.yml, and if
257+ # there is a single ci.yml in that directory, we can assume that any file change in that directory
258+ # will apply to all packages that exist in that directory.
259+ $triggeringCIYmls = $triggeringPaths | Where-Object { $_ -like " *ci*.yml" }
260+
261+ foreach ($yml in $triggeringCIYmls ) {
262+ # given that this path is coming from the populated triggering paths in the artifact,
263+ # we can assume that the path to the ci.yml will successfully resolve.
264+ $ciYml = Join-Path $RepoRoot $yml
265+ # ensure we terminate the service directory with a /
266+ $directory = [System.IO.Path ]::GetDirectoryName($ciYml ).Replace(" `\" , " /" ) + " /"
267+ $soleCIYml = (Get-ChildItem - Path $directory - Filter " ci*.yml" - File).Count -eq 1
268+
269+ if ($soleCIYml -and $filePath.Replace (" `\" , " /" ).StartsWith($directory )) {
270+ if (-not $shouldInclude ) {
271+ $pkg.IncludedForValidation = $true
272+ $shouldInclude = $true
273+ }
274+ break
275+ }
276+ else {
277+ # if the ci.yml is not the only file in the directory, we cannot assume that any file changed within the directory that isn't the ci.yml
278+ # should trigger this package
279+ Write-Host " Skipping adding package for file `" $file `" because the ci yml `" $yml `" is not the only file in the service directory `" $directory `" "
240280 }
241281 }
242282
@@ -280,6 +320,7 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
280320 # packages. We should never return NO validation.
281321 if ($packagesWithChanges.Count -eq 0 ) {
282322 $packagesWithChanges += ($allPackageProperties | Where-Object { $_.ServiceDirectory -eq " template" })
323+ $packagesWithChanges [0 ].IncludedForValidation = $true
283324 }
284325
285326 return $packagesWithChanges
0 commit comments