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 filter out excludes for pr pipelines 9649 #1984

Merged
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
13 changes: 12 additions & 1 deletion eng/common/scripts/Generate-PR-Diff.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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" }
}

Expand Down
18 changes: 18 additions & 0 deletions eng/common/scripts/Package-Properties.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @{}
Expand All @@ -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) {
Expand Down
Loading