From 0a008d02cc67a377e21d2354d63feecf1a5b5925 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 19 Aug 2025 12:35:12 +0200 Subject: [PATCH 01/23] Update .build README --- .build/README.md | 24 +++++++++++------------- CHANGELOG.md | 1 - 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/.build/README.md b/.build/README.md index 536da28a9d..65ea0a68a6 100644 --- a/.build/README.md +++ b/.build/README.md @@ -1,16 +1,20 @@ -# DSC Resource Integration Test Optimization +# Scripts -This document describes the script used to dynamically determine whether DSC +Documentation for the specific SqlServerDsc module pipeline scripts. + +## `Test-ShouldRunDscResourceIntegrationTests.ps1` + +The script is used to dynamically determine whether DSC resource integration tests should run in Azure Pipelines. -## What the Script Does +### What the Script Does The `Test-ShouldRunDscResourceIntegrationTests.ps1` script analyzes git changes between two references and determines if DSC resource integration tests need to run. It automatically discovers which public commands are used by DSC resources and classes, then checks if any relevant files have been modified. -## How It Works +### How It Works The script checks for changes to: @@ -23,9 +27,9 @@ The script checks for changes to: 1. **Integration Tests**: DSC resource integration test files under `tests/Integration/Resources/` -## Usage +### Usage -### Azure Pipelines +#### Azure Pipelines The Azure Pipelines task sets an output variable that downstream stages can use to conditionally run DSC resource integration tests. The script returns @@ -42,7 +46,7 @@ Downstream stages reference this output variable using the pattern: `dependencies.JobName.outputs['StepName.VariableName']` to gate their execution based on whether DSC resource tests should run. -### Command Line +#### Command Line ```powershell # Basic usage (compares current HEAD with origin/main) @@ -52,9 +56,3 @@ execution based on whether DSC resource tests should run. .build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch 'origin/dev' \ -CurrentBranch 'feature-branch' ``` - -## Dynamic Discovery - -The script automatically discovers public commands used by DSC resources by -scanning source files, eliminating the need to maintain hardcoded lists. -This ensures accuracy and reduces maintenance overhead. diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ac71a55cd..c61dafd5c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,7 +75,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 resources, public commands used by resources, or related components. - Unit tests, QA tests, and command integration tests continue to run for all changes. - - Provides time savings for non-DSC changes while maintaining coverage. ## [17.1.0] - 2025-05-22 From 38dd2c4c052feffa1e7db31e3156bd1569c2f42f Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 19 Aug 2025 12:43:58 +0200 Subject: [PATCH 02/23] Update .build/README.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .build/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.build/README.md b/.build/README.md index 65ea0a68a6..55e5c141a0 100644 --- a/.build/README.md +++ b/.build/README.md @@ -1,4 +1,4 @@ -# Scripts +# .build scripts Documentation for the specific SqlServerDsc module pipeline scripts. From 15733798bc5e354672d4f5235f76ad682a5aff0c Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 19 Aug 2025 12:44:23 +0200 Subject: [PATCH 03/23] Update .build/README.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .build/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.build/README.md b/.build/README.md index 55e5c141a0..364ba0cbc4 100644 --- a/.build/README.md +++ b/.build/README.md @@ -1,6 +1,6 @@ # .build scripts -Documentation for the specific SqlServerDsc module pipeline scripts. +Documentation for the SqlServerDsc module build/pipeline scripts. ## `Test-ShouldRunDscResourceIntegrationTests.ps1` From 7ed6f43d33f6497bb2aceb322484c203e97d7505 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 19 Aug 2025 12:44:37 +0200 Subject: [PATCH 04/23] Update .build/README.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .build/README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.build/README.md b/.build/README.md index 364ba0cbc4..c3cd581013 100644 --- a/.build/README.md +++ b/.build/README.md @@ -4,9 +4,7 @@ Documentation for the SqlServerDsc module build/pipeline scripts. ## `Test-ShouldRunDscResourceIntegrationTests.ps1` -The script is used to dynamically determine whether DSC -resource integration tests should run in Azure Pipelines. - +This script dynamically determines whether DSC resource integration tests should run in Azure Pipelines. ### What the Script Does The `Test-ShouldRunDscResourceIntegrationTests.ps1` script analyzes git From 924c240ec140f78077a277cfcf269db1a5823c7d Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 19 Aug 2025 13:26:41 +0200 Subject: [PATCH 05/23] Refactor integration test conditions to improve branch logic handling and normalize output variable for DSC resource tests --- azure-pipelines.yml | 48 +++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 24bdf700ee..6d4198f862 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -91,28 +91,30 @@ stages: inputs: targetType: 'inline' script: | - # Set the target branch for comparison - if ($env:SYSTEM_PULLREQUEST_TARGETBRANCH) { + # Determine if we should run DSC resource integration tests based on branch logic + $shouldRun = $false + + if ($env:SYSTEM_PULLREQUEST_TARGETBRANCH) + { $targetBranch = "origin/$env:SYSTEM_PULLREQUEST_TARGETBRANCH" - } else { - $targetBranch = "origin/$(defaultBranch)" + Write-Host "Pull request detected, branch $targetBranch. Using script analysis to determine test requirements." + $shouldRun = ./.build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch $targetBranch -CurrentBranch 'HEAD' + } + elseif ($env:BUILD.SOURCEBRANCHNAME) -eq '$(defaultBranch)'') + { + Write-Host "Target is default branch ($(defaultBranch)). Always running DSC resource integration tests." + $shouldRun = $true + } + else + { + Write-Host "Target is non-default branch ($env:BUILD.SOURCEBRANCH). Using script analysis to determine test requirements against default branch." + $shouldRun = ./.build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch 'origin/main' -CurrentBranch $env:BUILD.SOURCEBRANCH } - - Write-Output "Target branch: $targetBranch" - Write-Output "Current branch: HEAD" - - # Run the script to determine if DSC resource integration tests should run - $shouldRun = ./.build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch $targetBranch -CurrentBranch HEAD - - # Debug: print computed value before exporting as output - Write-Host "Computed ShouldRunDscResourceIntegrationTests: $shouldRun" - - # Normalize to lowercase string so conditions can use a simple string comparison - $shouldRunNormalized = ([string] $shouldRun).ToLower() - Write-Host "Normalized ShouldRunDscResourceIntegrationTests: $shouldRunNormalized" # Set Azure DevOps output variable for pipeline conditions - Write-Host "##vso[task.setvariable variable=ShouldRunDscResourceIntegrationTests;isOutput=true]$shouldRunNormalized" + Write-Host "##vso[task.setvariable variable=ShouldRunDscResourceIntegrationTests;isOutput=true]$shouldRun" + + Write-Host "Variable ShouldRunDscResourceIntegrationTests is set to: $shouldRun" pwsh: true - job: Test_HQRM @@ -447,7 +449,7 @@ stages: condition: | and( succeeded(), - eq(dependencies.Quality_Test_and_Unit_Test.outputs['Determine_DSC_Resource_Test_Requirements.determineDscResourceTests.ShouldRunDscResourceIntegrationTests'], 'true') + eq(lower(dependencies.Quality_Test_and_Unit_Test.outputs['Determine_DSC_Resource_Test_Requirements.determineDscResourceTests.ShouldRunDscResourceIntegrationTests']), 'true') ) jobs: - job: Test_Integration @@ -545,7 +547,7 @@ stages: condition: | and( succeeded(), - eq(dependencies.Quality_Test_and_Unit_Test.outputs['Determine_DSC_Resource_Test_Requirements.determineDscResourceTests.ShouldRunDscResourceIntegrationTests'], 'true') + eq(lower(dependencies.Quality_Test_and_Unit_Test.outputs['Determine_DSC_Resource_Test_Requirements.determineDscResourceTests.ShouldRunDscResourceIntegrationTests']), 'true') ) jobs: - job: Test_Integration @@ -640,7 +642,7 @@ stages: condition: | and( succeeded(), - eq(dependencies.Quality_Test_and_Unit_Test.outputs['Determine_DSC_Resource_Test_Requirements.determineDscResourceTests.ShouldRunDscResourceIntegrationTests'], 'true') + eq(lower(dependencies.Quality_Test_and_Unit_Test.outputs['Determine_DSC_Resource_Test_Requirements.determineDscResourceTests.ShouldRunDscResourceIntegrationTests']), 'true') ) jobs: - job: Test_Integration @@ -716,7 +718,7 @@ stages: condition: | and( succeeded(), - eq(dependencies.Quality_Test_and_Unit_Test.outputs['Determine_DSC_Resource_Test_Requirements.determineDscResourceTests.ShouldRunDscResourceIntegrationTests'], 'true') + eq(lower(dependencies.Quality_Test_and_Unit_Test.outputs['Determine_DSC_Resource_Test_Requirements.determineDscResourceTests.ShouldRunDscResourceIntegrationTests']), 'true') ) jobs: - job: Test_Integration @@ -783,7 +785,7 @@ stages: condition: | and( succeeded(), - eq(dependencies.Quality_Test_and_Unit_Test.outputs['Determine_DSC_Resource_Test_Requirements.determineDscResourceTests.ShouldRunDscResourceIntegrationTests'], 'true') + eq(lower(dependencies.Quality_Test_and_Unit_Test.outputs['Determine_DSC_Resource_Test_Requirements.determineDscResourceTests.ShouldRunDscResourceIntegrationTests']), 'true') ) jobs: - job: Test_Integration From 71828422194d4dc8e7815396b912cb7c03722b3a Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 19 Aug 2025 13:26:48 +0200 Subject: [PATCH 06/23] Update README.md for improved formatting and clarity in DSC resource integration test script documentation --- .build/README.md | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/.build/README.md b/.build/README.md index c3cd581013..116b6a98b3 100644 --- a/.build/README.md +++ b/.build/README.md @@ -4,7 +4,9 @@ Documentation for the SqlServerDsc module build/pipeline scripts. ## `Test-ShouldRunDscResourceIntegrationTests.ps1` -This script dynamically determines whether DSC resource integration tests should run in Azure Pipelines. +This script dynamically determines whether DSC resource integration tests +should run in Azure Pipelines. + ### What the Script Does The `Test-ShouldRunDscResourceIntegrationTests.ps1` script analyzes git @@ -33,16 +35,27 @@ The Azure Pipelines task sets an output variable that downstream stages can use to conditionally run DSC resource integration tests. The script returns a boolean value that the pipeline captures, e.g.: + ```yaml - powershell: | $shouldRun = ./.build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch $targetBranch -CurrentBranch HEAD Write-Host "##vso[task.setvariable variable=ShouldRunDscResourceIntegrationTests;isOutput=true]$shouldRun" displayName: 'Determine if DSC resource tests should run' ``` + + +Downstream stages reference this output variable in a stage `condition:` +using the pattern: + +```yaml +condition: | +and( + succeeded(), + eq(lower(dependencies.stageName.outputs['jobName.taskName.ShouldRunDscResourceIntegrationTests']), 'true')` -Downstream stages reference this output variable using the pattern: -`dependencies.JobName.outputs['StepName.VariableName']` to gate their -execution based on whether DSC resource tests should run. +) +``` + #### Command Line From 3c1138936fa217e797fc7c41ce866a459077595b Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 19 Aug 2025 13:26:54 +0200 Subject: [PATCH 07/23] Add additional words to cSpell dictionary for improved spell checking --- .vscode/settings.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 6c1387be60..1e6fedf669 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -86,7 +86,10 @@ "sqlps", "securestring", "encryptorname", - "wsfc" + "wsfc", + "SOURCEBRANCH", + "SOURCEBRANCHNAME", + "setvariable" ], "cSpell.ignorePaths": [ ".git" From 95471e071b8397f764f11da36d76ac5cb5b7a5a5 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 19 Aug 2025 13:59:01 +0200 Subject: [PATCH 08/23] Update .build/README.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .build/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.build/README.md b/.build/README.md index 116b6a98b3..5de231711e 100644 --- a/.build/README.md +++ b/.build/README.md @@ -1,6 +1,6 @@ # .build scripts -Documentation for the SqlServerDsc module build/pipeline scripts. +Documentation for the SqlServerDsc module build and pipeline scripts. ## `Test-ShouldRunDscResourceIntegrationTests.ps1` From d347a57ba244e53a7520df786be91fe52b2d6176 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 19 Aug 2025 13:59:17 +0200 Subject: [PATCH 09/23] Update .build/README.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .build/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.build/README.md b/.build/README.md index 5de231711e..17049000b1 100644 --- a/.build/README.md +++ b/.build/README.md @@ -9,11 +9,10 @@ should run in Azure Pipelines. ### What the Script Does -The `Test-ShouldRunDscResourceIntegrationTests.ps1` script analyzes git +The [`Test-ShouldRunDscResourceIntegrationTests.ps1`](./.build/Test-ShouldRunDscResourceIntegrationTests.ps1) script analyzes git changes between two references and determines if DSC resource integration tests need to run. It automatically discovers which public commands are used by DSC resources and classes, then checks if any relevant files have been modified. - ### How It Works The script checks for changes to: From b1ec7252903a0b80d173d7b5e1b6ba70eb11c790 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 19 Aug 2025 14:00:20 +0200 Subject: [PATCH 10/23] Fix invocation of PowerShell script for determining test requirements in integration tests --- azure-pipelines.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 6d4198f862..e209ed234c 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -98,7 +98,7 @@ stages: { $targetBranch = "origin/$env:SYSTEM_PULLREQUEST_TARGETBRANCH" Write-Host "Pull request detected, branch $targetBranch. Using script analysis to determine test requirements." - $shouldRun = ./.build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch $targetBranch -CurrentBranch 'HEAD' + $shouldRun = & ./.build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch $targetBranch -CurrentBranch 'HEAD' } elseif ($env:BUILD.SOURCEBRANCHNAME) -eq '$(defaultBranch)'') { @@ -108,7 +108,7 @@ stages: else { Write-Host "Target is non-default branch ($env:BUILD.SOURCEBRANCH). Using script analysis to determine test requirements against default branch." - $shouldRun = ./.build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch 'origin/main' -CurrentBranch $env:BUILD.SOURCEBRANCH + $shouldRun = & ./.build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch 'origin/main' -CurrentBranch $env:BUILD.SOURCEBRANCH } # Set Azure DevOps output variable for pipeline conditions From 848af0d81fe12a473827705c0adaf05e5f91ef47 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 19 Aug 2025 14:04:05 +0200 Subject: [PATCH 11/23] Enhance README.md by adding parameters section for clarity on script usage --- .build/README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.build/README.md b/.build/README.md index 17049000b1..20e9d996ca 100644 --- a/.build/README.md +++ b/.build/README.md @@ -8,11 +8,12 @@ This script dynamically determines whether DSC resource integration tests should run in Azure Pipelines. ### What the Script Does - + The [`Test-ShouldRunDscResourceIntegrationTests.ps1`](./.build/Test-ShouldRunDscResourceIntegrationTests.ps1) script analyzes git changes between two references and determines if DSC resource integration tests need to run. It automatically discovers which public commands are used by DSC resources and classes, then checks if any relevant files have been modified. + ### How It Works The script checks for changes to: @@ -26,6 +27,13 @@ The script checks for changes to: 1. **Integration Tests**: DSC resource integration test files under `tests/Integration/Resources/` +### Parameters + +| Parameter | Type | Default | Purpose | +|-----------|------|---------|---------| +| `BaseBranch` | String | `'origin/main'` | Base branch to compare against | +| `CurrentBranch` | String | `'HEAD'` | Current branch or commit to compare | + ### Usage #### Azure Pipelines From b0834f8995edbdccb1e0a17999b965b21da4140f Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 19 Aug 2025 16:24:32 +0200 Subject: [PATCH 12/23] Fix syntax error in condition for default branch check in Azure Pipelines --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e209ed234c..2b68af0a5b 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -100,7 +100,7 @@ stages: Write-Host "Pull request detected, branch $targetBranch. Using script analysis to determine test requirements." $shouldRun = & ./.build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch $targetBranch -CurrentBranch 'HEAD' } - elseif ($env:BUILD.SOURCEBRANCHNAME) -eq '$(defaultBranch)'') + elseif ($env:BUILD.SOURCEBRANCHNAME -eq '$(defaultBranch)'') { Write-Host "Target is default branch ($(defaultBranch)). Always running DSC resource integration tests." $shouldRun = $true From 7398aacbaca64e3f237c6fd9eb5f95840ec06421 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 19 Aug 2025 16:59:13 +0200 Subject: [PATCH 13/23] Fix syntax error in condition for default branch check in Azure Pipelines --- azure-pipelines.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 2b68af0a5b..5e93d4c0fc 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -100,7 +100,7 @@ stages: Write-Host "Pull request detected, branch $targetBranch. Using script analysis to determine test requirements." $shouldRun = & ./.build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch $targetBranch -CurrentBranch 'HEAD' } - elseif ($env:BUILD.SOURCEBRANCHNAME -eq '$(defaultBranch)'') + elseif ($env:BUILD.SOURCEBRANCHNAME -eq '$(defaultBranch)') { Write-Host "Target is default branch ($(defaultBranch)). Always running DSC resource integration tests." $shouldRun = $true @@ -108,7 +108,7 @@ stages: else { Write-Host "Target is non-default branch ($env:BUILD.SOURCEBRANCH). Using script analysis to determine test requirements against default branch." - $shouldRun = & ./.build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch 'origin/main' -CurrentBranch $env:BUILD.SOURCEBRANCH + $shouldRun = & ./.build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch 'origin/$(defaultBranch)' -CurrentBranch $env:BUILD.SOURCEBRANCH } # Set Azure DevOps output variable for pipeline conditions From 669ec4ff33531be7334c8035f52060393168510c Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 19 Aug 2025 18:11:27 +0200 Subject: [PATCH 14/23] Improve logging for pull request detection and refine branch handling in test requirements script --- azure-pipelines.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 5e93d4c0fc..f527e226e1 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -97,7 +97,7 @@ stages: if ($env:SYSTEM_PULLREQUEST_TARGETBRANCH) { $targetBranch = "origin/$env:SYSTEM_PULLREQUEST_TARGETBRANCH" - Write-Host "Pull request detected, branch $targetBranch. Using script analysis to determine test requirements." + Write-Host "Pull request detected, targeting branch $targetBranch. Using script analysis to determine test requirements." $shouldRun = & ./.build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch $targetBranch -CurrentBranch 'HEAD' } elseif ($env:BUILD.SOURCEBRANCHNAME -eq '$(defaultBranch)') @@ -108,7 +108,7 @@ stages: else { Write-Host "Target is non-default branch ($env:BUILD.SOURCEBRANCH). Using script analysis to determine test requirements against default branch." - $shouldRun = & ./.build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch 'origin/$(defaultBranch)' -CurrentBranch $env:BUILD.SOURCEBRANCH + $shouldRun = & ./.build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch "origin/$env:BUILD.SOURCEBRANCH" -CurrentBranch 'HEAD' } # Set Azure DevOps output variable for pipeline conditions From b36c108732fb3c252c05d2cd70c642f7ff3128df Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 19 Aug 2025 18:11:34 +0200 Subject: [PATCH 15/23] Fix link to PowerShell script and update outputs section in README.md --- .build/README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.build/README.md b/.build/README.md index 20e9d996ca..c59868dda8 100644 --- a/.build/README.md +++ b/.build/README.md @@ -9,7 +9,7 @@ should run in Azure Pipelines. ### What the Script Does -The [`Test-ShouldRunDscResourceIntegrationTests.ps1`](./.build/Test-ShouldRunDscResourceIntegrationTests.ps1) script analyzes git +The [`Test-ShouldRunDscResourceIntegrationTests.ps1`](./Test-ShouldRunDscResourceIntegrationTests.ps1) script analyzes git changes between two references and determines if DSC resource integration tests need to run. It automatically discovers which public commands are used by DSC resources and classes, then checks if any relevant files have been modified. @@ -34,6 +34,12 @@ The script checks for changes to: | `BaseBranch` | String | `'origin/main'` | Base branch to compare against | | `CurrentBranch` | String | `'HEAD'` | Current branch or commit to compare | +### Outputs + +| Output | Type | Description | +|--------|------|-------------| +| Return value | Boolean | `$true` if branches differ, `$false` otherwise | + ### Usage #### Azure Pipelines @@ -58,8 +64,7 @@ using the pattern: condition: | and( succeeded(), - eq(lower(dependencies.stageName.outputs['jobName.taskName.ShouldRunDscResourceIntegrationTests']), 'true')` - + eq(lower(dependencies.stageName.outputs['jobName.taskName.ShouldRunDscResourceIntegrationTests']), 'true') ) ``` From bc080acd059863b5aeb15e8123d8889d2b045fca Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 19 Aug 2025 18:11:38 +0200 Subject: [PATCH 16/23] Update Markdown style guidelines to clarify line wrapping and disable MD013 for long tables/code blocks --- .../dsc-community-style-guidelines-markdown.instructions.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/instructions/dsc-community-style-guidelines-markdown.instructions.md b/.github/instructions/dsc-community-style-guidelines-markdown.instructions.md index d473d9fded..a210f8bab0 100644 --- a/.github/instructions/dsc-community-style-guidelines-markdown.instructions.md +++ b/.github/instructions/dsc-community-style-guidelines-markdown.instructions.md @@ -5,7 +5,8 @@ applyTo: "**/*.md" # Markdown Style Guidelines -- Wrap lines at word boundaries when over 80 characters +- Wrap lines at word boundaries when over 80 characters (except tables/code blocks) - Use 2 spaces for indentation - Use '1.' for all items in ordered lists (1/1/1 numbering style) - Surround fenced code blocks with blank lines +- Disable `MD013` rule for tables/code blocks exceeding 80 characters From 44938aff8dd809fa39186cdb620b0edc8a4e1a55 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 19 Aug 2025 18:28:55 +0200 Subject: [PATCH 17/23] Clarify instruction for disabling `MD013` rule in Markdown style guidelines --- .../dsc-community-style-guidelines-markdown.instructions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/instructions/dsc-community-style-guidelines-markdown.instructions.md b/.github/instructions/dsc-community-style-guidelines-markdown.instructions.md index a210f8bab0..d6564beccb 100644 --- a/.github/instructions/dsc-community-style-guidelines-markdown.instructions.md +++ b/.github/instructions/dsc-community-style-guidelines-markdown.instructions.md @@ -9,4 +9,4 @@ applyTo: "**/*.md" - Use 2 spaces for indentation - Use '1.' for all items in ordered lists (1/1/1 numbering style) - Surround fenced code blocks with blank lines -- Disable `MD013` rule for tables/code blocks exceeding 80 characters +- Disable `MD013` rule by adding a comment for tables/code blocks exceeding 80 characters From 11c7af0fb026a60d6552501b9fe876ed73d6141b Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 19 Aug 2025 18:29:01 +0200 Subject: [PATCH 18/23] Update output description in README.md for clarity on return value of the script --- .build/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.build/README.md b/.build/README.md index c59868dda8..cf5eff95c9 100644 --- a/.build/README.md +++ b/.build/README.md @@ -36,9 +36,11 @@ The script checks for changes to: ### Outputs + | Output | Type | Description | |--------|------|-------------| -| Return value | Boolean | `$true` if branches differ, `$false` otherwise | +| Return value | Boolean | `$true` when the monitored categories have relevant changes between the specified refs, `$false` when no such changes are detected | + ### Usage From f1a12010a48a533c0838d15ce590ccd1eea722d0 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 19 Aug 2025 18:41:21 +0200 Subject: [PATCH 19/23] Update integration test script to use default branch variable for base branch determination --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index f527e226e1..ec32615048 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -108,7 +108,7 @@ stages: else { Write-Host "Target is non-default branch ($env:BUILD.SOURCEBRANCH). Using script analysis to determine test requirements against default branch." - $shouldRun = & ./.build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch "origin/$env:BUILD.SOURCEBRANCH" -CurrentBranch 'HEAD' + $shouldRun = & ./.build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch "origin/$(defaultBranch)" -CurrentBranch 'HEAD' -UseMergeBase } # Set Azure DevOps output variable for pipeline conditions From 9db498501974c3cf8848f4483e9ab8f07b1e25c6 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 19 Aug 2025 18:41:24 +0200 Subject: [PATCH 20/23] Add UseMergeBase parameter to integration test functions for improved comparison --- ...t-ShouldRunDscResourceIntegrationTests.ps1 | 80 ++++++++++++++++--- 1 file changed, 71 insertions(+), 9 deletions(-) diff --git a/.build/Test-ShouldRunDscResourceIntegrationTests.ps1 b/.build/Test-ShouldRunDscResourceIntegrationTests.ps1 index 64e1e4ecb4..aee27fb986 100644 --- a/.build/Test-ShouldRunDscResourceIntegrationTests.ps1 +++ b/.build/Test-ShouldRunDscResourceIntegrationTests.ps1 @@ -17,12 +17,20 @@ .PARAMETER CurrentBranch The current branch or commit to compare. Default is 'HEAD'. + .PARAMETER UseMergeBase + When specified, compares the current branch against the merge-base with the base branch + instead of directly comparing against the base branch. This is useful for comparing + only the changes introduced by the current branch. + .EXAMPLE Test-ShouldRunDscResourceIntegrationTests .EXAMPLE Test-ShouldRunDscResourceIntegrationTests -BaseBranch 'origin/main' -CurrentBranch 'HEAD' + .EXAMPLE + Test-ShouldRunDscResourceIntegrationTests -BaseBranch 'origin/main' -CurrentBranch 'HEAD' -UseMergeBase + .OUTPUTS System.Boolean. Returns $true if DSC resource integration tests should run, $false otherwise. #> @@ -35,7 +43,11 @@ param [Parameter()] [System.String] - $CurrentBranch = 'HEAD' + $CurrentBranch = 'HEAD', + + [Parameter()] + [System.Management.Automation.SwitchParameter] + $UseMergeBase ) <# @@ -137,7 +149,8 @@ function Get-PublicCommandsUsedByDscResources .DESCRIPTION This function retrieves the list of files that have been modified between two git references using git diff. It handles various scenarios including - different diff syntax and untracked files. + different diff syntax and untracked files. Optionally can compare against + the merge-base of the two references. .PARAMETER From The source git reference (branch, commit, tag). @@ -145,9 +158,16 @@ function Get-PublicCommandsUsedByDscResources .PARAMETER To The target git reference (branch, commit, tag). + .PARAMETER UseMergeBase + When specified, finds the merge-base between From and To references and + compares To against that merge-base instead of directly against From. + .EXAMPLE Get-ChangedFiles -From 'origin/main' -To 'HEAD' + .EXAMPLE + Get-ChangedFiles -From 'origin/main' -To 'HEAD' -UseMergeBase + .OUTPUTS System.String[]. Array of file paths that have been changed. #> @@ -162,23 +182,46 @@ function Get-ChangedFiles [Parameter(Mandatory = $true)] [System.String] - $To + $To, + + [Parameter()] + [System.Management.Automation.SwitchParameter] + $UseMergeBase ) try { + $compareFrom = $From + + # If UseMergeBase is specified, find the merge-base between From and To + if ($UseMergeBase) + { + Write-Verbose "Finding merge-base between $From and $To" + $mergeBase = & git merge-base $From $To 2>&1 + if ($LASTEXITCODE -eq 0 -and $mergeBase) + { + $compareFrom = $mergeBase.Trim() + Write-Verbose "Using merge-base: $compareFrom" + } + else + { + Write-Warning "Failed to find merge-base between $From and $To. Falling back to direct comparison. Exit code: $LASTEXITCODE. Output: $mergeBase" + $compareFrom = $From + } + } + # Try different git diff approaches $gitDiffOutput = $null # First, try the standard diff - $gitDiffOutput = & git diff --name-only "$From..$To" 2>&1 + $gitDiffOutput = & git diff --name-only "$compareFrom..$To" 2>&1 if ($LASTEXITCODE -eq 0 -and $gitDiffOutput) { return $gitDiffOutput | Where-Object -FilterScript { $_ -and $_.Trim() } } # If that fails, try without the range syntax - $gitDiffOutput = & git diff --name-only $From $To 2>&1 + $gitDiffOutput = & git diff --name-only $compareFrom $To 2>&1 if ($LASTEXITCODE -eq 0 -and $gitDiffOutput) { return $gitDiffOutput | Where-Object -FilterScript { $_ -and $_.Trim() } @@ -194,7 +237,7 @@ function Get-ChangedFiles } } - Write-Warning "Failed to get git diff between $From and $To. Exit code: $LASTEXITCODE. Output: $gitDiffOutput" + Write-Warning "Failed to get git diff between $compareFrom and $To. Exit code: $LASTEXITCODE. Output: $gitDiffOutput" return @() } catch @@ -347,6 +390,11 @@ function Get-PrivateFunctionsUsedByClassResources .PARAMETER CurrentBranch The current branch or commit to compare. Default is 'HEAD'. + .PARAMETER UseMergeBase + When specified, compares the current branch against the merge-base with the base branch + instead of directly comparing against the base branch. This is useful for comparing + only the changes introduced by the current branch. + .PARAMETER SourcePath The source path containing the source code directories. Default is 'source'. @@ -356,6 +404,9 @@ function Get-PrivateFunctionsUsedByClassResources .EXAMPLE Test-ShouldRunDscResourceIntegrationTests -BaseBranch 'origin/main' -CurrentBranch 'feature-branch' + .EXAMPLE + Test-ShouldRunDscResourceIntegrationTests -BaseBranch 'origin/main' -CurrentBranch 'feature-branch' -UseMergeBase + .OUTPUTS System.Boolean. Returns $true if DSC resource integration tests should run, $false otherwise. #> @@ -372,13 +423,24 @@ function Test-ShouldRunDscResourceIntegrationTests [System.String] $CurrentBranch = 'HEAD', + [Parameter()] + [System.Management.Automation.SwitchParameter] + $UseMergeBase, + [Parameter()] [System.String] $SourcePath = 'source' ) Write-Host "##[section]Analyzing DSC Resource Integration Test Requirements" - Write-Host "Analyzing changes between $BaseBranch and $CurrentBranch..." + if ($UseMergeBase) + { + Write-Host "Analyzing changes between $BaseBranch (merge-base) and $CurrentBranch..." + } + else + { + Write-Host "Analyzing changes between $BaseBranch and $CurrentBranch..." + } Write-Host "" # Get list of public commands used by DSC resources dynamically @@ -386,7 +448,7 @@ function Test-ShouldRunDscResourceIntegrationTests Write-Host "Discovered $($PublicCommandsUsedByDscResources.Count) public commands used by DSC resources and classes." Write-Host "" - $changedFiles = Get-ChangedFiles -From $BaseBranch -To $CurrentBranch + $changedFiles = Get-ChangedFiles -From $BaseBranch -To $CurrentBranch -UseMergeBase:$UseMergeBase if (-not $changedFiles) { @@ -477,7 +539,7 @@ function Test-ShouldRunDscResourceIntegrationTests # If script is run directly (not imported), execute the main function if ($MyInvocation.InvocationName -ne '.') { - $shouldRun = Test-ShouldRunDscResourceIntegrationTests -BaseBranch $BaseBranch -CurrentBranch $CurrentBranch + $shouldRun = Test-ShouldRunDscResourceIntegrationTests -BaseBranch $BaseBranch -CurrentBranch $CurrentBranch -UseMergeBase:$UseMergeBase # Provide clear final result with appropriate color coding Write-Host "##[section]Test Requirements Decision" From 7cbe0fd8ead320f8150fb25be8c214c2a6ec4766 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 19 Aug 2025 18:43:05 +0200 Subject: [PATCH 21/23] Add name parameter to Azure Pipelines task for clarity in output variable --- .build/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.build/README.md b/.build/README.md index cf5eff95c9..eaa678c5b5 100644 --- a/.build/README.md +++ b/.build/README.md @@ -56,6 +56,7 @@ a boolean value that the pipeline captures, e.g.: $shouldRun = ./.build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch $targetBranch -CurrentBranch HEAD Write-Host "##vso[task.setvariable variable=ShouldRunDscResourceIntegrationTests;isOutput=true]$shouldRun" displayName: 'Determine if DSC resource tests should run' + name: determineShouldRun ``` From 005293cd5d28e4716c346cc1797c7fabb57efa72 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 19 Aug 2025 19:17:17 +0200 Subject: [PATCH 22/23] Clarify output message for DSC Resource Integration Test analysis to specify changes since merge-base --- .build/Test-ShouldRunDscResourceIntegrationTests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.build/Test-ShouldRunDscResourceIntegrationTests.ps1 b/.build/Test-ShouldRunDscResourceIntegrationTests.ps1 index aee27fb986..75c8d11664 100644 --- a/.build/Test-ShouldRunDscResourceIntegrationTests.ps1 +++ b/.build/Test-ShouldRunDscResourceIntegrationTests.ps1 @@ -435,7 +435,7 @@ function Test-ShouldRunDscResourceIntegrationTests Write-Host "##[section]Analyzing DSC Resource Integration Test Requirements" if ($UseMergeBase) { - Write-Host "Analyzing changes between $BaseBranch (merge-base) and $CurrentBranch..." + Write-Host "Analyzing changes introduced by $CurrentBranch since merge-base with $BaseBranch..." } else { From bc784e254720b33c8ef856d02b028ba446dfcda4 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 19 Aug 2025 19:17:29 +0200 Subject: [PATCH 23/23] Update README.md to include UseMergeBase parameter in usage example --- .build/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.build/README.md b/.build/README.md index eaa678c5b5..29bd640692 100644 --- a/.build/README.md +++ b/.build/README.md @@ -33,6 +33,7 @@ The script checks for changes to: |-----------|------|---------|---------| | `BaseBranch` | String | `'origin/main'` | Base branch to compare against | | `CurrentBranch` | String | `'HEAD'` | Current branch or commit to compare | +| `UseMergeBase` | Switch | `$false` | Use merge-base to compute diff base | ### Outputs @@ -53,7 +54,7 @@ a boolean value that the pipeline captures, e.g.: ```yaml - powershell: | - $shouldRun = ./.build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch $targetBranch -CurrentBranch HEAD + $shouldRun = & ./.build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch $targetBranch -CurrentBranch HEAD -UseMergeBase Write-Host "##vso[task.setvariable variable=ShouldRunDscResourceIntegrationTests;isOutput=true]$shouldRun" displayName: 'Determine if DSC resource tests should run' name: determineShouldRun