Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync eng/common directory with azure-sdk-tools for PR 9902 #32794

Merged
merged 6 commits into from
Feb 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions eng/common/scripts/Package-Properties.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class PackageProps {
$result = [PSCustomObject]@{
ArtifactConfig = [HashTable]$artifactForCurrentPackage
ParsedYml = $content
Location = $ymlPath
}

return $result
Expand Down Expand Up @@ -126,6 +127,14 @@ class PackageProps {

if ($ciArtifactResult) {
$this.ArtifactDetails = [Hashtable]$ciArtifactResult.ArtifactConfig

if (-not $this.ArtifactDetails["triggeringPaths"]) {
$this.ArtifactDetails["triggeringPaths"] = @()
}
$RepoRoot = Resolve-Path (Join-Path $PSScriptRoot ".." ".." "..")
$relativePath = (Resolve-Path -Path $ciArtifactResult.Location -Relative -RelativeBasePath $RepoRoot).TrimStart(".").Replace("`\", "/")
$this.ArtifactDetails["triggeringPaths"] += $relativePath

$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
Expand Down Expand Up @@ -207,6 +216,7 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
}

foreach ($file in $targetedFiles) {
$pathComponents = $file -split "/"
$shouldExclude = $false
foreach ($exclude in $excludePaths) {
if ($file.StartsWith($exclude,'CurrentCultureIgnoreCase')) {
Expand All @@ -219,12 +229,12 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
}
$filePath = (Join-Path $RepoRoot $file)

# handle direct changes to packages
$shouldInclude = $filePath -like (Join-Path "$pkgDirectory" "*")

# this implementation guesses the working directory of the ci.yml
# handle changes to files that are RELATED to each package
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)
}
Expand All @@ -237,6 +247,36 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
if ($includedForValidation) {
$pkg.IncludedForValidation = $true
}
break
}
}

# handle service-level changes to the ci.yml files
# we are using the ci.yml file being added automatically to each artifactdetails as the input
# for this task. This is because we can resolve a service directory from the ci.yml, and if
# 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.
$ciYml = Join-Path $RepoRoot $yml
# ensure we terminate the service directory with a /
$directory = [System.IO.Path]::GetDirectoryName($ciYml).Replace("`\", "/") + "/"
$soleCIYml = (Get-ChildItem -Path $directory -Filter "ci*.yml" -File).Count -eq 1

if ($soleCIYml -and $filePath.Replace("`\", "/").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`""
}
}

Expand Down Expand Up @@ -280,6 +320,7 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
# packages. We should never return NO validation.
if ($packagesWithChanges.Count -eq 0) {
$packagesWithChanges += ($allPackageProperties | Where-Object { $_.ServiceDirectory -eq "template" })
$packagesWithChanges[0].IncludedForValidation = $true
}

return $packagesWithChanges
Expand Down
Loading