Sync eng/common directory with azure-sdk-tools for PR 9649 (#6353)

* Filter out Excludes for PR Pipelines

* Updates for feedback

---------

Co-authored-by: James Suplizio <jasupliz@microsoft.com>
This commit is contained in:
Azure SDK Bot 2025-01-16 12:23:05 -08:00 committed by GitHub
parent 938222b018
commit b0b69233ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 3 deletions

View File

@ -14,6 +14,9 @@ parameters:
- name: ScriptDirectory
type: string
default: eng/common/scripts
- name: ExcludePaths
type: object
default: []
steps:
# There will be transitory period for every language repo where the <language> - pullrequest build definition will run
@ -26,10 +29,12 @@ steps:
- task: Powershell@2
displayName: Generate PR Diff
inputs:
filePath: ${{ parameters.ScriptDirectory }}/Generate-PR-Diff.ps1
arguments: >
targetType: inline
script: >
${{ parameters.ScriptDirectory }}/Generate-PR-Diff.ps1
-TargetPath '${{ parameters.TargetPath }}'
-ArtifactPath '${{ parameters.DiffDirectory }}'
-ExcludePaths ('${{ convertToJson(parameters.ExcludePaths) }}' | ConvertFrom-Json)
pwsh: true
# When running in PR mode, we want the detected changed services to be attached to the build as tags.

View File

@ -16,7 +16,10 @@ Param (
[Parameter(Mandatory = $True)]
[string] $ArtifactPath,
[Parameter(Mandatory = $True)]
[string] $TargetPath
[string] $TargetPath,
[Parameter(Mandatory=$false)]
[AllowEmptyCollection()]
[array] $ExcludePaths
)
. (Join-Path $PSScriptRoot "Helpers" "git-helpers.ps1")
@ -45,13 +48,21 @@ $changedFiles = @()
$changedServices = @()
$changedFiles = Get-ChangedFiles -DiffPath $TargetPath
if ($changedFiles) {
$changedServices = Get-ChangedServices -ChangedFiles $changedFiles
}
# ExcludePaths is an object array with the default of [] which evaluates to null.
# If the value is null, set it to empty list to ensure that the empty list is
# stored in the json
if (-not $ExcludePaths) {
$ExcludePaths = @()
}
$result = [PSCustomObject]@{
"ChangedFiles" = $changedFiles
"ChangedServices" = $changedServices
"ExcludePaths" = $ExcludePaths
"PRNumber" = if ($env:SYSTEM_PULLREQUEST_PULLREQUESTNUMBER) { $env:SYSTEM_PULLREQUEST_PULLREQUESTNUMBER } else { "-1" }
}

View File

@ -162,6 +162,14 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
$allPackageProperties = Get-AllPkgProperties
$diff = Get-Content $InputDiffJson | ConvertFrom-Json
$targetedFiles = $diff.ChangedFiles
# The exclude paths and the targeted files paths aren't full OS paths, they're
# GitHub paths meaning they're relative to the repo root and slashes are forward
# slashes "/". The ExcludePaths need to have a trailing slash added in order
# correctly test for string matches without overmatching. For example, if a pr
# had files sdk/foo/file1 and sdk/foobar/file2 with the exclude of anything in
# sdk/foo, it should only exclude things under sdk/foo. The TrimEnd is just in
# case one of the paths ends with a slash, it doesn't add a second one.
$excludePaths = $diff.ExcludePaths | ForEach-Object { $_.TrimEnd("/") + "/" }
$additionalValidationPackages = @()
$lookup = @{}
@ -172,6 +180,16 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
$lookup[$lookupKey] = $pkg
foreach ($file in $targetedFiles) {
$shouldExclude = $false
foreach ($exclude in $excludePaths) {
if ($file.StartsWith($exclude,'CurrentCultureIgnoreCase')) {
$shouldExclude = $true
break
}
}
if ($shouldExclude) {
continue
}
$filePath = (Join-Path $RepoRoot $file)
$shouldInclude = $filePath -like (Join-Path "$pkgDirectory" "*")
if ($shouldInclude) {