Sync eng/common directory with azure-sdk-tools for PR 10411 (#6540)
* when processing a PR diff, treat packages added via their triggeringPaths as directly changed (used to be indirect) --------- Co-authored-by: Scott Beddall <scbedd@microsoft.com>
This commit is contained in:
parent
92246a2d90
commit
a0f10e318e
@ -288,7 +288,11 @@ function Update-TargetedFilesForTriggerPaths([string[]]$TargetedFiles, [string[]
|
||||
|
||||
for ($i = 0; $i -lt $Triggers.Count; $i++) {
|
||||
$triggerPath = $Triggers[$i]
|
||||
if ($triggerPath -and $file -eq "$triggerPath") {
|
||||
# targeted files comes from the `changedPaths` property of the diff, which is
|
||||
# a list of relative file paths from root. Not starting with a /.
|
||||
# However, the triggerPaths are absolute paths, so we need to resolve the targeted file
|
||||
# to the same format
|
||||
if ($triggerPath -and "/$file" -eq "$triggerPath") {
|
||||
$isExistingTriggerPath = $true
|
||||
break
|
||||
}
|
||||
@ -365,8 +369,8 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
|
||||
# this is the primary loop that identifies the packages that have changes
|
||||
foreach ($pkg in $allPackageProperties) {
|
||||
Write-Host "Processing changed files against $($pkg.Name). $pkgCounter of $($allPackageProperties.Count)."
|
||||
$pkgDirectory = Resolve-Path "$($pkg.DirectoryPath)"
|
||||
$lookupKey = ($pkg.DirectoryPath).Replace($RepoRoot, "").TrimStart('\/')
|
||||
$pkgDirectory = (Resolve-Path "$($pkg.DirectoryPath)").Path.Replace("`\", "/")
|
||||
$lookupKey = $pkgDirectory.Replace($RepoRoot, "").TrimStart('\/')
|
||||
$lookup[$lookupKey] = $pkg
|
||||
|
||||
# we only honor the individual artifact triggers
|
||||
@ -380,22 +384,21 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
|
||||
}
|
||||
|
||||
foreach ($file in $targetedFiles) {
|
||||
$filePath = (Join-Path $RepoRoot $file)
|
||||
$filePath = (Join-Path $RepoRoot $file).Replace("`\", "/")
|
||||
|
||||
# handle direct changes to packages
|
||||
$shouldInclude = $filePath -eq $pkgDirectory -or $filePath -like (Join-Path "$pkgDirectory" "*")
|
||||
$shouldInclude = $filePath -eq $pkgDirectory -or $filePath -like "$pkgDirectory/*"
|
||||
|
||||
# we only need to do additional work for indirect packages if we haven't already decided
|
||||
# to include this package due to this file
|
||||
if (-not $shouldInclude) {
|
||||
# handle changes to files that are RELATED to each package
|
||||
foreach($triggerPath in $triggeringPaths) {
|
||||
$resolvedRelativePath = (Join-Path $RepoRoot $triggerPath)
|
||||
$resolvedRelativePath = (Join-Path $RepoRoot $triggerPath).Replace("`\", "/")
|
||||
# triggerPaths can be direct files, so we need to check both startswith and direct equality
|
||||
$includedForValidation = ($filePath -like (Join-Path "$resolvedRelativePath" "*") -or $filePath -eq $resolvedRelativePath)
|
||||
$includedForValidation = ($filePath -like ("$resolvedRelativePath/*") -or $filePath -eq $resolvedRelativePath)
|
||||
$shouldInclude = $shouldInclude -or $includedForValidation
|
||||
if ($includedForValidation) {
|
||||
$pkg.IncludedForValidation = $true
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -406,7 +409,6 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
|
||||
# there is a single ci.yml in that directory, we can assume that any file change in that directory
|
||||
# will apply to all packages that exist in that directory.
|
||||
$triggeringCIYmls = $triggeringPaths | Where-Object { $_ -like "*ci*.yml" }
|
||||
|
||||
foreach($yml in $triggeringCIYmls) {
|
||||
# given that this path is coming from the populated triggering paths in the artifact,
|
||||
# we can assume that the path to the ci.yml will successfully resolve.
|
||||
@ -414,12 +416,15 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
|
||||
# ensure we terminate the service directory with a /
|
||||
$directory = [System.IO.Path]::GetDirectoryName($ciYml).Replace("`\", "/")
|
||||
|
||||
# we should only continue with this check if the file being changed is "in the service directory"
|
||||
# files that are directly included in triggerPaths will kept in full form, but otherwise we pre-process the targetedFiles to the
|
||||
# directory containing the change. Given that pre-process, we should check both direct equality (when not triggeringPath) and parent directory
|
||||
# for the case where the full form of the file has been left behind (because it was a triggeringPath)
|
||||
$serviceDirectoryChange = (Split-Path $filePath -Parent).Replace("`\", "/") -eq $directory -or $filePath.Replace("`\", "/") -eq $directory
|
||||
if (!$serviceDirectoryChange) {
|
||||
# this filepath doesn't apply to this service directory at all, so we can break out of this loop
|
||||
if (-not $filePath.StartsWith("$directory/")) {
|
||||
break
|
||||
}
|
||||
|
||||
$relative = $filePath.SubString($directory.Length + 1)
|
||||
|
||||
if ($relative.Contains("/") -or -not [IO.Path]::GetExtension($relative)){
|
||||
# this is a bare folder OR exists deeper than the service directory, so we can skip
|
||||
break
|
||||
}
|
||||
|
||||
@ -433,18 +438,12 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
|
||||
$directoryIndex[$directory] = $soleCIYml
|
||||
}
|
||||
|
||||
if ($soleCIYml -and $filePath.Replace("`\", "/").StartsWith($directory)) {
|
||||
if ($soleCIYml -and $filePath.StartsWith($directory)) {
|
||||
if (-not $shouldInclude) {
|
||||
$pkg.IncludedForValidation = $true
|
||||
$shouldInclude = $true
|
||||
}
|
||||
break
|
||||
}
|
||||
else {
|
||||
# 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
|
||||
# should trigger this package
|
||||
Write-Host "Skipping adding package for file `"$file`" because the ci yml `"$yml`" is not the only file in the service directory `"$directory`""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -483,7 +482,8 @@ 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
|
||||
$additionalPackages = &$AdditionalValidationPackagesFromPackageSetFn $packagesWithChanges $diff $allPackageProperties
|
||||
$packagesWithChanges += $additionalPackages
|
||||
}
|
||||
|
||||
# finally, if we have gotten all the way here and we still don't have any packages, we should include the template service
|
||||
|
||||
Loading…
Reference in New Issue
Block a user