Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools for PR 9649 (#32191)
Browse files Browse the repository at this point in the history
* Filter out Excludes for PR Pipelines

* Updates for feedback

---------

Co-authored-by: James Suplizio <jasupliz@microsoft.com>
  • Loading branch information
azure-sdk and JimSuplizio authored Jan 16, 2025
1 parent fcba952 commit cb78c45
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
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

0 comments on commit cb78c45

Please sign in to comment.