|
| 1 | +# DSC Resource Integration Test Optimization |
| 2 | + |
| 3 | +This document describes the script used to dynamically determine whether DSC |
| 4 | +resource integration tests should run in Azure Pipelines. |
| 5 | + |
| 6 | +## What the Script Does |
| 7 | + |
| 8 | +The `Test-ShouldRunDscResourceIntegrationTests.ps1` script analyzes git |
| 9 | +changes between two references and determines if DSC resource integration tests |
| 10 | +need to run. It automatically discovers which public commands are used by DSC |
| 11 | +resources and classes, then checks if any relevant files have been modified. |
| 12 | + |
| 13 | +## How It Works |
| 14 | + |
| 15 | +The script checks for changes to: |
| 16 | + |
| 17 | +1. **DSC Resources**: Files under `source/DSCResources/` |
| 18 | +1. **Classes**: Files under `source/Classes/` |
| 19 | +1. **Public Commands**: Commands that are actually used by DSC resources or |
| 20 | + classes (dynamically discovered) |
| 21 | +1. **Private Functions**: Functions used by the monitored public commands or |
| 22 | + class-based DSC resources |
| 23 | +1. **Integration Tests**: DSC resource integration test files under |
| 24 | + `tests/Integration/Resources/` |
| 25 | + |
| 26 | +## Usage |
| 27 | + |
| 28 | +### Azure Pipelines |
| 29 | + |
| 30 | +The Azure Pipelines task sets an output variable that downstream stages can |
| 31 | +use to conditionally run DSC resource integration tests. The script returns |
| 32 | +a boolean value that the pipeline captures, e.g.: |
| 33 | + |
| 34 | +```yaml |
| 35 | +- powershell: | |
| 36 | + $shouldRun = ./.build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch $targetBranch -CurrentBranch HEAD |
| 37 | + Write-Host "##vso[task.setvariable variable=ShouldRunDscResourceIntegrationTests;isOutput=true]$shouldRun" |
| 38 | + displayName: 'Determine if DSC resource tests should run' |
| 39 | +``` |
| 40 | +
|
| 41 | +Downstream stages reference this output variable using the pattern: |
| 42 | +`dependencies.JobName.outputs['StepName.VariableName']` to gate their |
| 43 | +execution based on whether DSC resource tests should run. |
| 44 | + |
| 45 | +### Command Line |
| 46 | + |
| 47 | +```powershell |
| 48 | +# Basic usage (compares current HEAD with origin/main) |
| 49 | +.build/Test-ShouldRunDscResourceIntegrationTests.ps1 |
| 50 | +
|
| 51 | +# Custom branches |
| 52 | +.build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch 'origin/dev' \ |
| 53 | + -CurrentBranch 'feature-branch' |
| 54 | +``` |
| 55 | + |
| 56 | +## Dynamic Discovery |
| 57 | + |
| 58 | +The script automatically discovers public commands used by DSC resources by |
| 59 | +scanning source files, eliminating the need to maintain hardcoded lists. |
| 60 | +This ensures accuracy and reduces maintenance overhead. |
0 commit comments