Skip to content

[POC] Conditional PR test execution - exploring test time reduction#54314

Draft
MichaelSimons wants to merge 5 commits into
dotnet:mainfrom
MichaelSimons:dev/conditional-pr-tests
Draft

[POC] Conditional PR test execution - exploring test time reduction#54314
MichaelSimons wants to merge 5 commits into
dotnet:mainfrom
MichaelSimons:dev/conditional-pr-tests

Conversation

@MichaelSimons
Copy link
Copy Markdown
Member

⚠️ Proof of Concept — Not intended for merge

This PR is exploratory. The goal is to validate timing improvements from conditional test execution in PR builds.

What this does

Reduces PR validation time by only running tests relevant to changed source paths:

  • Detects which src/ areas changed via git diff
  • Skips unrelated test groups (Analyzers, Blazor/SWA, Templates, Containers, Watch, ILLink)
  • Always runs full tests for: CI builds, codeflow PRs (darc-* branches), dependency updates

Safety guarantees

  • CI pipeline unchanged — always full coverage
  • Detection failure → run all tests (fail-open)
  • Manual override via runAllTests pipeline parameter

Expected impact

For targeted PRs: ~43% reduction in Helix work items per leg (146 of 336 skippable)
Estimated time: 75 min → 40-50 min

Open questions (see docs/conditional-pr-tests-design.md)

  1. Override mechanism for auto-triggered PR builds (PR description keyword vs comment trigger)
  2. Configuration-driven design to reduce touchpoints when adding new scopes
  3. Platform coverage reduction (skip macOS for non-platform changes)
  4. AoT leg optimization

Files changed

File Purpose
.vsts-pr.yml Added runAllTests parameter
eng/pipelines/scripts/detect-test-scope.sh Path detection (linux/macOS)
eng/pipelines/scripts/detect-test-scope.ps1 Path detection (Windows)
eng/pipelines/templates/jobs/sdk-build.yml Wires detection + passes properties
test/UnitTests.proj Conditional test removal
docs/conditional-pr-tests-design.md Design doc with analysis

Proof of concept for reducing PR validation time by only running tests
relevant to the changed source paths. This is exploratory - not intended
for merge in current form.

Changes:
- Add path-based test scope detection scripts (bash + PowerShell)
- Wire detection into sdk-build.yml with /p: properties
- Add conditional test removal to UnitTests.proj
- Add runAllTests pipeline parameter for manual override
- Add design document with open questions and future work

Safety: CI builds always run all tests. Codeflow PRs (darc-* branches)
and dependency updates (eng/Versions.props) also run all tests.
Detection failures default to running everything (fail-open).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
PowerShell with ErrorActionPreference=Stop treats git's stderr progress
output ('From https://...') as a terminating error. Fix by temporarily
setting ErrorActionPreference to Continue around git calls and piping
stderr through Out-Null.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
MichaelSimons and others added 3 commits May 15, 2026 09:43
- Use two-arg git diff (tree comparison) instead of three-dot syntax
  which requires merge-base computation that fails in shallow clones
- Use SilentlyContinue for ErrorActionPreference around git commands
  in PowerShell to prevent stderr output from becoming terminating
  errors in PS 5.1

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant