Skip to content

Commit 3c2ffb1

Browse files
Sync eng/common directory with azure-sdk-tools for PR 9649 (Azure#47867)
* Filter out Excludes for PR Pipelines * Updates for feedback --------- Co-authored-by: James Suplizio <[email protected]>
1 parent 4a3da7b commit 3c2ffb1

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

eng/common/pipelines/templates/steps/save-package-properties.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ parameters:
1414
- name: ScriptDirectory
1515
type: string
1616
default: eng/common/scripts
17+
- name: ExcludePaths
18+
type: object
19+
default: []
1720

1821
steps:
1922
# There will be transitory period for every language repo where the <language> - pullrequest build definition will run
@@ -26,10 +29,12 @@ steps:
2629
- task: Powershell@2
2730
displayName: Generate PR Diff
2831
inputs:
29-
filePath: ${{ parameters.ScriptDirectory }}/Generate-PR-Diff.ps1
30-
arguments: >
32+
targetType: inline
33+
script: >
34+
${{ parameters.ScriptDirectory }}/Generate-PR-Diff.ps1
3135
-TargetPath '${{ parameters.TargetPath }}'
3236
-ArtifactPath '${{ parameters.DiffDirectory }}'
37+
-ExcludePaths ('${{ convertToJson(parameters.ExcludePaths) }}' | ConvertFrom-Json)
3338
pwsh: true
3439

3540
# When running in PR mode, we want the detected changed services to be attached to the build as tags.

eng/common/scripts/Generate-PR-Diff.ps1

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ Param (
1616
[Parameter(Mandatory = $True)]
1717
[string] $ArtifactPath,
1818
[Parameter(Mandatory = $True)]
19-
[string] $TargetPath
19+
[string] $TargetPath,
20+
[Parameter(Mandatory=$false)]
21+
[AllowEmptyCollection()]
22+
[array] $ExcludePaths
2023
)
2124

2225
. (Join-Path $PSScriptRoot "Helpers" "git-helpers.ps1")
@@ -45,13 +48,21 @@ $changedFiles = @()
4548
$changedServices = @()
4649

4750
$changedFiles = Get-ChangedFiles -DiffPath $TargetPath
51+
4852
if ($changedFiles) {
4953
$changedServices = Get-ChangedServices -ChangedFiles $changedFiles
5054
}
5155

56+
# ExcludePaths is an object array with the default of [] which evaluates to null.
57+
# If the value is null, set it to empty list to ensure that the empty list is
58+
# stored in the json
59+
if (-not $ExcludePaths) {
60+
$ExcludePaths = @()
61+
}
5262
$result = [PSCustomObject]@{
5363
"ChangedFiles" = $changedFiles
5464
"ChangedServices" = $changedServices
65+
"ExcludePaths" = $ExcludePaths
5566
"PRNumber" = if ($env:SYSTEM_PULLREQUEST_PULLREQUESTNUMBER) { $env:SYSTEM_PULLREQUEST_PULLREQUESTNUMBER } else { "-1" }
5667
}
5768

eng/common/scripts/Package-Properties.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
162162
$allPackageProperties = Get-AllPkgProperties
163163
$diff = Get-Content $InputDiffJson | ConvertFrom-Json
164164
$targetedFiles = $diff.ChangedFiles
165+
# The exclude paths and the targeted files paths aren't full OS paths, they're
166+
# GitHub paths meaning they're relative to the repo root and slashes are forward
167+
# slashes "/". The ExcludePaths need to have a trailing slash added in order
168+
# correctly test for string matches without overmatching. For example, if a pr
169+
# had files sdk/foo/file1 and sdk/foobar/file2 with the exclude of anything in
170+
# sdk/foo, it should only exclude things under sdk/foo. The TrimEnd is just in
171+
# case one of the paths ends with a slash, it doesn't add a second one.
172+
$excludePaths = $diff.ExcludePaths | ForEach-Object { $_.TrimEnd("/") + "/" }
165173

166174
$additionalValidationPackages = @()
167175
$lookup = @{}
@@ -172,6 +180,16 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
172180
$lookup[$lookupKey] = $pkg
173181

174182
foreach ($file in $targetedFiles) {
183+
$shouldExclude = $false
184+
foreach ($exclude in $excludePaths) {
185+
if ($file.StartsWith($exclude,'CurrentCultureIgnoreCase')) {
186+
$shouldExclude = $true
187+
break
188+
}
189+
}
190+
if ($shouldExclude) {
191+
continue
192+
}
175193
$filePath = (Join-Path $RepoRoot $file)
176194
$shouldInclude = $filePath -like (Join-Path "$pkgDirectory" "*")
177195
if ($shouldInclude) {

0 commit comments

Comments
 (0)