@@ -380,10 +380,12 @@ function Get-PrivateFunctionsUsedByClassResources
380380 . DESCRIPTION
381381 This function analyzes the changes between two git references and determines
382382 if DSC resource integration tests should run based on the files that have
383- been modified. It checks for changes to DSC resources, classes, public
384- commands used by DSC resources, private functions used by those public commands,
385- private functions used by class-based DSC resources, and integration
386- tests.
383+ been modified. It performs an optimized analysis by first checking if any
384+ changes exist under the source/ folder. If no source changes are detected,
385+ it skips the expensive analysis and returns false. Otherwise, it checks for
386+ changes to DSC resources, classes, public commands used by DSC resources,
387+ private functions used by those public commands, private functions used by
388+ class-based DSC resources, and integration tests.
387389 . PARAMETER BaseBranch
388390 The base branch to compare against. Default is 'origin/main'.
389391
@@ -443,11 +445,6 @@ function Test-ShouldRunDscResourceIntegrationTests
443445 }
444446 Write-Host " "
445447
446- # Get list of public commands used by DSC resources dynamically
447- $PublicCommandsUsedByDscResources = Get-PublicCommandsUsedByDscResources - SourcePath $SourcePath
448- Write-Host " Discovered $ ( $PublicCommandsUsedByDscResources.Count ) public commands used by DSC resources and classes."
449- Write-Host " "
450-
451448 $changedFiles = Get-ChangedFiles - From $BaseBranch - To $CurrentBranch - UseMergeBase:$UseMergeBase
452449
453450 if (-not $changedFiles )
@@ -462,6 +459,20 @@ function Test-ShouldRunDscResourceIntegrationTests
462459 Write-Host " ##[endgroup]"
463460 Write-Host " "
464461
462+ # Early optimization: Check if any changes are under the source folder
463+ $changedSourceFiles = $changedFiles | Where-Object - FilterScript { $_ -match ' ^source/' }
464+ if (-not $changedSourceFiles )
465+ {
466+ Write-Host " No changes detected under the source folder. DSC resource integration tests can be skipped."
467+ Write-Host " "
468+ return $false
469+ }
470+
471+ # Get list of public commands used by DSC resources dynamically (only when needed)
472+ $PublicCommandsUsedByDscResources = Get-PublicCommandsUsedByDscResources - SourcePath $SourcePath
473+ Write-Host " Discovered $ ( $PublicCommandsUsedByDscResources.Count ) public commands used by DSC resources and classes."
474+ Write-Host " "
475+
465476 # Check if any DSC resources are directly changed
466477 $changedDscResources = $changedFiles | Where-Object - FilterScript { $_ -match ' ^source/DSCResources/' -or $_ -match ' ^source/Classes/' }
467478 if ($changedDscResources )
0 commit comments