Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools for PR 9862 (#32716)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
azure-sdk and scbedd authored Feb 21, 2025
1 parent 5d6ba00 commit a119720
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion eng/common/scripts/Helpers/Package-Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
44 changes: 44 additions & 0 deletions eng/common/scripts/Package-Properties.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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) {
Expand All @@ -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

Expand All @@ -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('\/')
Expand All @@ -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
}

Expand Down

0 comments on commit a119720

Please sign in to comment.