Skip to content

Commit 7ac451c

Browse files
azure-sdkscbedd
andauthored
Sync eng/common directory with azure-sdk-tools for PR 9862 (Azure#2203)
* Get-PRPkgProperties now honors artifact-list specific absolute/relative paths to other triggering folders. This will supplant the common "if eng/ changes include template and core" in a follow-up PR. --------- Co-authored-by: Scott Beddall <[email protected]>
1 parent 66a457d commit 7ac451c

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

eng/common/scripts/Helpers/Package-Helpers.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ function GetValueSafelyFrom-Yaml {
155155
)
156156
$current = $YamlContentAsHashtable
157157
foreach ($key in $Keys) {
158-
if ($current.ContainsKey($key) -or $current[$key]) {
158+
if ($current -is [HashTable] -and ($current.ContainsKey($key) -or $current[$key])) {
159159
$current = $current[$key]
160160
}
161161
else {

eng/common/scripts/Package-Properties.ps1

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class PackageProps {
126126

127127
if ($ciArtifactResult) {
128128
$this.ArtifactDetails = [Hashtable]$ciArtifactResult.ArtifactConfig
129+
$this.CIParameters["CIMatrixConfigs"] = @()
129130

130131
# if we know this is the matrix for our file, we should now see if there is a custom matrix config for the package
131132
$matrixConfigList = GetValueSafelyFrom-Yaml $ciArtifactResult.ParsedYml @("extends", "parameters", "MatrixConfigs")
@@ -196,11 +197,22 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
196197
$additionalValidationPackages = @()
197198
$lookup = @{}
198199

200+
# this is the primary loop that identifies the packages that have changes
199201
foreach ($pkg in $allPackageProperties) {
200202
$pkgDirectory = Resolve-Path "$($pkg.DirectoryPath)"
201203
$lookupKey = ($pkg.DirectoryPath).Replace($RepoRoot, "").TrimStart('\/')
202204
$lookup[$lookupKey] = $pkg
203205

206+
# we only honor the individual artifact triggers
207+
# if we were to honor the ci-level triggers, we would simply
208+
# end up in a situation where any change to a service would
209+
# still trigger every package in that service. individual package triggers
210+
# must be added to handle this.
211+
$triggeringPaths = @()
212+
if ($pkg.ArtifactDetails -and $pkg.ArtifactDetails["triggeringPaths"]) {
213+
$triggeringPaths = $pkg.ArtifactDetails["triggeringPaths"]
214+
}
215+
204216
foreach ($file in $targetedFiles) {
205217
$shouldExclude = $false
206218
foreach ($exclude in $excludePaths) {
@@ -213,7 +225,28 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
213225
continue
214226
}
215227
$filePath = (Join-Path $RepoRoot $file)
228+
216229
$shouldInclude = $filePath -like (Join-Path "$pkgDirectory" "*")
230+
231+
# this implementation guesses the working directory of the ci.yml
232+
foreach($triggerPath in $triggeringPaths) {
233+
$resolvedRelativePath = (Join-Path $RepoRoot $triggerPath)
234+
# utilize the various trigger paths against the targeted file here
235+
if (!$triggerPath.StartsWith("/")){
236+
$resolvedRelativePath = (Join-Path $RepoRoot "sdk" "$($pkg.ServiceDirectory)" $triggerPath)
237+
}
238+
239+
# if we are including this package due to one of its additional trigger paths, we need
240+
# to ensure we're counting it as included for validation, not as an actual package change
241+
if ($resolvedRelativePath) {
242+
$includedForValidation = $filePath -like (Join-Path "$resolvedRelativePath" "*")
243+
$shouldInclude = $shouldInclude -or $includedForValidation
244+
if ($includedForValidation) {
245+
$pkg.IncludedForValidation = $true
246+
}
247+
}
248+
}
249+
217250
if ($shouldInclude) {
218251
$packagesWithChanges += $pkg
219252

@@ -227,6 +260,9 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
227260
}
228261
}
229262

263+
# add all of the packages that were added purely for validation purposes
264+
# this is executed separately because we need to identify packages added this way as only included for validation
265+
# we don't actually need to build or analyze them. only test them.
230266
$existingPackageNames = @($packagesWithChanges | ForEach-Object { $_.Name })
231267
foreach ($addition in $additionalValidationPackages) {
232268
$key = $addition.Replace($RepoRoot, "").TrimStart('\/')
@@ -241,10 +277,18 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
241277
}
242278
}
243279

280+
# now pass along the set of packages we've identified, the diff itself, and the full set of package properties
281+
# to locate any additional packages that should be included for validation
244282
if ($AdditionalValidationPackagesFromPackageSetFn -and (Test-Path "Function:$AdditionalValidationPackagesFromPackageSetFn")) {
245283
$packagesWithChanges += &$AdditionalValidationPackagesFromPackageSetFn $packagesWithChanges $diff $allPackageProperties
246284
}
247285

286+
# finally, if we have gotten all the way here and we still don't have any packages, we should include the template service
287+
# packages. We should never return NO validation.
288+
if ($packagesWithChanges.Count -eq 0) {
289+
$packagesWithChanges += ($allPackageProperties | Where-Object { $_.ServiceDirectory -eq "template" })
290+
}
291+
248292
return $packagesWithChanges
249293
}
250294

0 commit comments

Comments
 (0)