diff --git a/eng/common/pipelines/templates/steps/save-package-properties.yml b/eng/common/pipelines/templates/steps/save-package-properties.yml index 172191c272dc..5ac89da9cdee 100644 --- a/eng/common/pipelines/templates/steps/save-package-properties.yml +++ b/eng/common/pipelines/templates/steps/save-package-properties.yml @@ -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 - 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. diff --git a/eng/common/scripts/Generate-PR-Diff.ps1 b/eng/common/scripts/Generate-PR-Diff.ps1 index 355ef612540f..e010e176399d 100644 --- a/eng/common/scripts/Generate-PR-Diff.ps1 +++ b/eng/common/scripts/Generate-PR-Diff.ps1 @@ -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" } } diff --git a/eng/common/scripts/Package-Properties.ps1 b/eng/common/scripts/Package-Properties.ps1 index 1784521252df..bc7b5738e2d3 100644 --- a/eng/common/scripts/Package-Properties.ps1 +++ b/eng/common/scripts/Package-Properties.ps1 @@ -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) {