Skip to content

Optimize Azure Pipelines with dynamic detection of DSC resource dependencies#2135

Merged
johlju merged 24 commits intomainfrom
copilot/fix-fdccc632-9ffe-4f0e-8c81-5dba10fa5a11
Aug 17, 2025
Merged

Optimize Azure Pipelines with dynamic detection of DSC resource dependencies#2135
johlju merged 24 commits intomainfrom
copilot/fix-fdccc632-9ffe-4f0e-8c81-5dba10fa5a11

Conversation

Copy link
Contributor

Copilot AI commented Aug 16, 2025

Problem

The current Azure Pipelines configuration runs all DSC resource integration tests for every change, regardless of whether the changes actually affect DSC resources. This leads to:

  • Unnecessary CI/CD time when changes only affect standalone public commands
  • Resource waste running expensive integration tests for documentation or unit test changes
  • Slower feedback loops for developers working on non-DSC functionality
  • Pipeline queue delays affecting other projects

Solution

This PR implements intelligent conditional logic to skip DSC resource integration tests when changes don't affect DSC resources, while preserving full test coverage when needed.

Key Components

Dynamic Detection Script (.build/Test-ShouldRunDscResourceIntegrationTests.ps1)

  • Analyzes git diff to identify relevant changes
  • Dynamically discovers public commands used by DSC resources/classes through string search of actual source files
  • Automatically detects 29 public commands currently used (vs. previous hardcoded 32)
  • Detects private functions used by class-based DSC resources (those with [DscResource(...)] decoration)
  • Checks for changes to DSC resources, classes, integration tests, and pipeline configuration
  • Uses safe defaults (runs tests when uncertain)
  • Uses named parameters throughout for code quality compliance
  • Enhanced Azure DevOps logging with proper color coding and collapsible sections

Pipeline Modifications (azure-pipelines.yml)

  • Added Determine_DSC_Resource_Test_Requirements job to detect if DSC tests should run
  • Applied conditional logic to 5 DSC resource integration test stages:
    • Integration_Test_Resources_SqlServer
    • Integration_Test_Resources_SqlServer_dbatools
    • Integration_Test_Resources_ReportingServices
    • Integration_Test_Resources_PowerBIReportServer
    • Integration_Test_Resources_ReportingServices_dbatools
  • Simplified Deploy stage condition to rely on Azure DevOps' built-in succeeded() logic for handling skipped dependencies

What Always Runs

  • Unit tests and QA tests (unchanged)
  • All command integration tests (3 stages)
  • Build and deployment stages

What Runs Conditionally

DSC resource integration tests only run when changes affect:

  • DSC resources (source/DSCResources/)
  • Classes (source/Classes/)
  • Public commands used by DSC resources (dynamically detected)
  • Private functions used by those public commands
  • Private functions used by class-based DSC resources (dynamically detected)
  • DSC resource integration test files
  • Pipeline configuration files

Benefits

  • Significant time savings for changes that don't affect DSC resources
  • Preserved quality - all relevant tests run when DSC functionality is modified
  • Faster developer feedback for standalone public commands and documentation changes
  • Resource efficiency in CI/CD pipeline usage
  • Automatic maintenance - no need to manually update lists of monitored commands or functions
  • Enhanced logging with color-coded Azure DevOps pipeline output

Example Scenarios

Will skip DSC resource tests:

# New standalone public command
source/Public/New-SqlDscBackupCommand.ps1

# Documentation updates
README.md, docs/

# Unit test changes only
tests/Unit/Public/SomeCommand.Tests.ps1

Will run DSC resource tests:

# DSC resource changes
source/DSCResources/DSC_SqlConfiguration/

# Public commands used by DSC resources
source/Public/Connect-SqlDscDatabaseEngine.ps1

# Class changes
source/Classes/020.SqlAudit.ps1

# Private functions used by class-based DSC resources
source/Private/SomePrivateFunction.ps1

Dynamic Discovery

The solution automatically discovers which public commands and private functions are used by DSC resources and classes by scanning the actual source files. This approach:

  • Eliminates maintenance overhead of hardcoded lists
  • Improves accuracy by reflecting actual current usage
  • Prevents false positives/negatives from outdated manual lists
  • Adapts automatically as DSC resources evolve
  • Covers all dependency types including private functions used directly by class-based resources

Enhanced Logging

The detection script now uses Azure DevOps logging commands for improved pipeline readability:

  • ##vso[section] for main sections
  • ##vso[task.logissue type=warning] for important decisions (yellow)
  • ##vso[task.logissue type=debug] for informational messages
  • ##vso[group] for collapsible file lists
  • Proper visual hierarchy and color coding

This optimization maintains the existing dependency order and test quality while providing substantial performance improvements for common development workflows.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


This change is Reviewable

Copilot AI and others added 3 commits August 16, 2025 09:42
Copilot AI changed the title [WIP] In this project there are extensive DSC resource integration tests that takes a long time to run. The tests are designed to ensure that the DSC resources function as expected and can be used effectively in a DSC configuration. The project also contains... Optimize Azure Pipelines to conditionally run DSC resource integration tests Aug 16, 2025
Copilot AI requested a review from johlju August 16, 2025 09:54
…and fix named parameter usage

Co-authored-by: johlju <7189721+johlju@users.noreply.github.com>
Copilot AI changed the title Optimize Azure Pipelines to conditionally run DSC resource integration tests Optimize Azure Pipelines with dynamic detection of DSC resource dependencies Aug 16, 2025
Copilot AI requested a review from johlju August 16, 2025 10:48
Co-authored-by: johlju <7189721+johlju@users.noreply.github.com>
…onTests.ps1 and update README.md

Co-authored-by: johlju <7189721+johlju@users.noreply.github.com>
Copilot AI requested a review from johlju August 16, 2025 11:20
@coderabbitai
Copy link

coderabbitai bot commented Aug 16, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Introduces a PowerShell script to decide when DSC resource integration tests should run based on git diffs, adds documentation, wires the decision into Azure Pipelines to conditionally run multiple integration-test stages, and updates the changelog to note the optimization.

Changes

Cohort / File(s) Summary
Build Docs
.build/README.md
New README describing DSC Resource Integration Test Optimization and usage of Test-ShouldRunDscResourceIntegrationTests.ps1 in CLI and Azure Pipelines. Defines monitored scopes and dynamic discovery of public commands.
Build Script
.build/Test-ShouldRunDscResourceIntegrationTests.ps1
New script adding functions to detect changed files and dependencies (public commands, private functions, class resources) and a main predicate Test-ShouldRunDscResourceIntegrationTests. Auto-exec path with defaults and structured output.
CI Pipeline
azure-pipelines.yml
Adds Determine_DSC_Resource_Test_Requirements job producing ShouldRunDscResourceIntegrationTests output. Gates several Integration_Test_Resources_* stages on this output; updates Deploy dependencies accordingly; handles PR target branch computation.
Changelog
CHANGELOG.md
Notes CI optimization: conditional DSC resource integration tests via new script; unaffected tests continue to run; documents scope of conditional execution.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant PR as PR Pipeline
  participant Job as Determine_DSC_Resource_Test_Requirements
  participant PS as Test-ShouldRunDscResourceIntegrationTests.ps1
  participant Git as Git Repo
  participant Stages as Integration_Test_Resources_* Stages
  participant Deploy as Deploy Stage

  PR->>Job: Start job
  Job->>PS: Invoke with -BaseBranch/-CurrentBranch
  PS->>Git: git diff to list changed files
  PS-->>Job: Return boolean ShouldRun
  Job-->>PR: Set output var ShouldRunDscResourceIntegrationTests

  PR->>Stages: Evaluate condition on output var
  alt ShouldRun == True
    Stages->>Stages: Run integration tests
  else ShouldRun == False
    Stages->>Stages: Skip stages
  end

  PR->>Deploy: Run when dependencies satisfied (incl. updated dependsOn)
Loading
sequenceDiagram
  autonumber
  participant Main as Test-ShouldRunDscResourceIntegrationTests
  participant Disc as Get-PublicCommandsUsedByDscResources
  participant Diff as Get-ChangedFiles
  participant DepCmd as Get-PrivateFunctionsUsedByCommand
  participant DepClass as Get-PrivateFunctionsUsedByClassResources

  Main->>Disc: Discover public commands used by DSC resources
  Main->>Diff: Get changed files between Base and Current
  alt No changes detected
    Main-->>Main: Default: run tests
  else Changes present
    Main-->>Main: Check DSCResources/Classes changes
    Main->>DepCmd: Resolve private functions for used commands
    Main->>DepClass: Resolve private functions for class resources
    Main-->>Main: Check if relevant public/private/test files changed
    Main-->>Main: Return True/False
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Join our Discord community for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Co-authored-by: johlju <7189721+johlju@users.noreply.github.com>
Copy link
Member

@johlju johlju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 2 files at r14, 2 of 2 files at r16, 1 of 1 files at r17, all commit messages.
Reviewable status: all files reviewed, 15 unresolved discussions (waiting on @copilot)

@johlju johlju merged commit d975c85 into main Aug 17, 2025
4 of 9 checks passed
@johlju johlju deleted the copilot/fix-fdccc632-9ffe-4f0e-8c81-5dba10fa5a11 branch August 17, 2025 12:48
@coderabbitai coderabbitai bot mentioned this pull request Jan 18, 2026
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments