@@ -91,6 +91,7 @@ class PackageProps {
91
91
$result = [PSCustomObject ]@ {
92
92
ArtifactConfig = [HashTable ]$artifactForCurrentPackage
93
93
ParsedYml = $content
94
+ Location = $ymlPath
94
95
}
95
96
96
97
return $result
@@ -126,6 +127,14 @@ class PackageProps {
126
127
127
128
if ($ciArtifactResult ) {
128
129
$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
+
129
138
$this.CIParameters [" CIMatrixConfigs" ] = @ ()
130
139
131
140
# 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) {
207
216
}
208
217
209
218
foreach ($file in $targetedFiles ) {
219
+ $pathComponents = $file -split " /"
210
220
$shouldExclude = $false
211
221
foreach ($exclude in $excludePaths ) {
212
222
if ($file.StartsWith ($exclude , ' CurrentCultureIgnoreCase' )) {
@@ -219,12 +229,12 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
219
229
}
220
230
$filePath = (Join-Path $RepoRoot $file )
221
231
232
+ # handle direct changes to packages
222
233
$shouldInclude = $filePath -like (Join-Path " $pkgDirectory " " *" )
223
234
224
- # this implementation guesses the working directory of the ci.yml
235
+ # handle changes to files that are RELATED to each package
225
236
foreach ($triggerPath in $triggeringPaths ) {
226
237
$resolvedRelativePath = (Join-Path $RepoRoot $triggerPath )
227
- # utilize the various trigger paths against the targeted file here
228
238
if (! $triggerPath.StartsWith (" /" )){
229
239
$resolvedRelativePath = (Join-Path $RepoRoot " sdk" " $ ( $pkg.ServiceDirectory ) " $triggerPath )
230
240
}
@@ -237,6 +247,36 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
237
247
if ($includedForValidation ) {
238
248
$pkg.IncludedForValidation = $true
239
249
}
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 `" "
240
280
}
241
281
}
242
282
@@ -280,6 +320,7 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
280
320
# packages. We should never return NO validation.
281
321
if ($packagesWithChanges.Count -eq 0 ) {
282
322
$packagesWithChanges += ($allPackageProperties | Where-Object { $_.ServiceDirectory -eq " template" })
323
+ $packagesWithChanges [0 ].IncludedForValidation = $true
283
324
}
284
325
285
326
return $packagesWithChanges
0 commit comments