Skip to content

Commit 80fcfb5

Browse files
authored
Enhance performance and documentation for DSC resource integration tests (#2141)
1 parent 2953123 commit 80fcfb5

File tree

4 files changed

+74
-10
lines changed

4 files changed

+74
-10
lines changed

.build/README.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ resources and classes, then checks if any relevant files have been modified.
1616

1717
### How It Works
1818

19-
The script checks for changes to:
19+
The script performs an optimized analysis by checking for changes in this order:
2020

21+
1. **Early Source Check**: First checks if any files under `source/` have changed
22+
- If no source changes, skips integration tests immediately
2123
1. **DSC Resources**: Files under `source/DSCResources/`
2224
1. **Classes**: Files under `source/Classes/`
2325
1. **Public Commands**: Commands that are actually used by DSC resources or
@@ -27,6 +29,47 @@ The script checks for changes to:
2729
1. **Integration Tests**: DSC resource integration test files under
2830
`tests/Integration/Resources/`
2931

32+
### Flow Diagram
33+
34+
The following diagram illustrates the decision flow of the script:
35+
36+
<!-- markdownlint-disable MD013 - Mermaid diagram has long lines -->
37+
```mermaid
38+
flowchart TD
39+
Start([Start Script]) --> Init[Initialize Parameters<br/>BaseBranch, CurrentBranch, UseMergeBase]
40+
Init --> GetChanges[Get Changed Files<br/>git diff between branches]
41+
42+
GetChanges --> HasChanges{Any Changed<br/>Files?}
43+
HasChanges -->|No| RunTrue[Return TRUE<br/>Run integration tests]
44+
45+
HasChanges -->|Yes| CheckSource{Any Changes<br/>Under source/?}
46+
CheckSource -->|No| Skip[Return FALSE<br/>Skip integration tests]
47+
48+
CheckSource -->|Yes| Discover[Discover Public Commands<br/>Used by DSC Resources]
49+
Discover --> CheckDscRes{DSC Resources or<br/>Classes Changed?<br/>source/DSCResources/<br/>source/Classes/}
50+
CheckDscRes -->|Yes| RunTrue
51+
52+
CheckDscRes -->|No| CheckPublic{Public Commands<br/>Used by DSC<br/>Resources Changed?<br/>source/Public/}
53+
CheckPublic -->|Yes| RunTrue
54+
55+
CheckPublic -->|No| CheckPrivate{Private Functions<br/>Used by DSC-related<br/>Commands Changed?<br/>source/Private/}
56+
CheckPrivate -->|Yes| RunTrue
57+
58+
CheckPrivate -->|No| CheckTests{Integration Test<br/>Files Changed?<br/>tests/Integration/Resources/}
59+
CheckTests -->|Yes| RunTrue
60+
61+
CheckTests -->|No| Skip
62+
63+
RunTrue --> End([End])
64+
Skip --> End
65+
66+
style Start fill:#e1f5fe
67+
style End fill:#e8f5e8
68+
style RunTrue fill:#fff3e0
69+
style Skip fill:#f3e5f5
70+
```
71+
<!-- markdownlint-enable MD013 -->
72+
3073
### Parameters
3174

3275
| Parameter | Type | Default | Purpose |

.build/Test-ShouldRunDscResourceIntegrationTests.ps1

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

.github/instructions/dsc-community-style-guidelines.instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ applyTo: "**"
2323
- Integration tests: `tests/Integration/Commands/{CommandName}.Integration.Tests.ps1`
2424

2525
## Requirements
26+
- Follow guidelines over existing code patterns
2627
- Always update CHANGELOG.md Unreleased section
2728
- Localize all strings using string keys
2829
- Check DscResource.Common before creating private functions

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7878
resources, public commands used by resources, or related components.
7979
- Unit tests, QA tests, and command integration tests continue to run for
8080
all changes.
81+
- `.build/Test-ShouldRunDscResourceIntegrationTests.ps1`
82+
- Improved performance by adding early optimization to check for changes
83+
under source folder before expensive analysis.
84+
- Moved public command discovery to only run when source changes are detected.
85+
- `.build/README.md`
86+
- Added flow diagram showing decision process for DSC resource integration tests.
87+
- Improved documentation with optimized analysis workflow description.
88+
- DSC community style guidelines
89+
- Added requirement to follow guidelines over existing code patterns.
8190

8291
## [17.1.0] - 2025-05-22
8392

0 commit comments

Comments
 (0)