Skip to content

Skip redundant PR triggers (Draft<->Open state transitions)#4303

Draft
paulmedynski wants to merge 2 commits into
mainfrom
dev/paul/pr-checks
Draft

Skip redundant PR triggers (Draft<->Open state transitions)#4303
paulmedynski wants to merge 2 commits into
mainfrom
dev/paul/pr-checks

Conversation

@paulmedynski
Copy link
Copy Markdown
Contributor

@paulmedynski paulmedynski commented May 21, 2026

Skip redundant PR pipeline triggers

Adds an optional gate stage to PR validation pipelines that short-circuits runs triggered by Draft ↔ Open state transitions (or similar non-code changes) when the merge commit SHA has not changed since the last successful build.

Problem

Azure DevOps PR triggers fire on every PR state change — including Draft/Open transitions that do not alter the code. This causes redundant pipeline runs that waste compute and clutter the build history.

Solution

A new Detect Redundant Trigger stage template queries the Azure DevOps Builds API:

  1. If Build.Reason is not PullRequest (e.g., manual queue), always proceeds
  2. Compares Build.SourceVersion (the PR merge commit) against the most recent successful build for the same PR/definition
  3. If the SHA matches → sets meaningful=false and downstream stages are skipped via implicit dependency cascade
  4. If the API call fails → defaults to meaningful=true (safe fallback — always builds)

Skipped pipeline runs still report a green ✓ status (Azure DevOps treats skipped stages as success).

Design

  • No-op intermediate stage exploits implicit dependency: when detect_redundant_trigger_stage outputs meaningful=false, the intermediate stage condition evaluates false → it is skipped → all downstream stages with default succeeded() condition are also skipped.
  • Merge commit captures both source and target changes — if the target branch advances, the merge commit SHA changes, so the build correctly proceeds.
  • Template parameter: Pipelines opt in via skipRedundantTrigger: true in extends parameters.

Files Changed

File Change
eng/pipelines/stages/detect-redundant-trigger-stage.yml New stage template
eng/pipelines/dotnet-sqlclient-ci-core.yml skipRedundantTrigger parameter + conditional gate stages
eng/pipelines/sqlclient-pr-project-ref-pipeline.yml Enables skipRedundantTrigger
eng/pipelines/sqlclient-pr-package-ref-pipeline.yml Enables skipRedundantTrigger

Safety & Robustness

  • API errors default to meaningful=true (build always proceeds on failure)
  • Non-PR triggers (manual queue) bypass the gate entirely
  • Uses mapped $SYSTEM_ACCESSTOKEN env var (avoids macro expansion in script)
  • Debug output via template-conditional step (${{ if eq(parameters.debug, true) }})

Add a gate stage to PR pipelines that detects when a build was triggered by
a state-only PR transition (Draft<->Open) rather than meaningful changes.
The gate queries the Azure DevOps builds API for the most recent successful
build of the same PR and compares the merge commit SHA.  If unchanged and a
prior build succeeded, downstream stages are skipped via condition cascade.

- New: eng/pipelines/stages/detect-redundant-trigger-stage.yml
- Modified: dotnet-sqlclient-ci-core.yml (skipRedundantTrigger parameter)
- Modified: both sqlclient-pr-*-pipeline.yml (pass skipRedundantTrigger: true)
Copilot AI review requested due to automatic review settings May 21, 2026 14:58
@github-project-automation github-project-automation Bot moved this to To triage in SqlClient Board May 21, 2026
@paulmedynski paulmedynski added the Area\Engineering Use this for issues that are targeted for changes in the 'eng' folder or build systems. label May 21, 2026
@paulmedynski paulmedynski moved this from To triage to In progress in SqlClient Board May 21, 2026
@paulmedynski paulmedynski added this to the 7.1.0-preview2 milestone May 21, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds an optional “redundant trigger” gate to PR validation pipelines to short-circuit runs that are triggered by Draft ↔ Open state transitions (or similar non-code changes) when the PR merge commit SHA hasn’t changed and a prior run already succeeded.

Changes:

  • Introduces a new gating stage template that queries the Azure DevOps Builds API and emits an output variable indicating whether the run is meaningful.
  • Adds a skipRedundantTrigger parameter to the shared CI core template and wires in an initial gate + no-op stage that cascades downstream stage skipping.
  • Enables this behavior in both PR validation pipelines (Project and Package reference modes).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
eng/pipelines/stages/detect-redundant-trigger-stage.yml New stage template that queries prior successful builds for the same PR merge ref and emits meaningful=true/false.
eng/pipelines/dotnet-sqlclient-ci-core.yml Adds skipRedundantTrigger parameter and prepends the gate stages when enabled.
eng/pipelines/sqlclient-pr-project-ref-pipeline.yml Enables skipRedundantTrigger for PR validation (Project reference mode).
eng/pipelines/sqlclient-pr-package-ref-pipeline.yml Enables skipRedundantTrigger for PR validation (Package reference mode).

Comment thread eng/pipelines/stages/detect-redundant-trigger-stage.yml Outdated
Comment thread eng/pipelines/stages/detect-redundant-trigger-stage.yml Outdated
Comment thread eng/pipelines/stages/detect-redundant-trigger-stage.yml Outdated
Comment thread eng/pipelines/stages/detect-redundant-trigger-stage.yml
- Use $SYSTEM_ACCESSTOKEN env var instead of $(System.AccessToken) macro
  expansion in curl to avoid accidental logging/expansion
- Add HTTP status code validation with safe fallback (meaningful=true)
  when the Builds API is unavailable or returns errors
- Add Build.Reason check to skip gate for non-PR triggers (manual reruns)
- Move debug output to a separate conditional step using template-time
  ${{ if eq(parameters.debug, true) }} instead of runtime string comparison
@paulmedynski
Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.69%. Comparing base (b700269) to head (ca98ab3).
⚠️ Report is 20 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4303      +/-   ##
==========================================
- Coverage   66.04%   64.69%   -1.35%     
==========================================
  Files         275      279       +4     
  Lines       42976    66219   +23243     
==========================================
+ Hits        28383    42843   +14460     
- Misses      14593    23376    +8783     
Flag Coverage Δ
CI-SqlClient ?
PR-SqlClient-Project 64.69% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@paulmedynski paulmedynski marked this pull request as ready for review May 21, 2026 23:08
@paulmedynski paulmedynski requested a review from a team as a code owner May 21, 2026 23:08
Copilot AI review requested due to automatic review settings May 21, 2026 23:08
@paulmedynski paulmedynski enabled auto-merge (squash) May 21, 2026 23:08
@paulmedynski paulmedynski moved this from In progress to In review in SqlClient Board May 21, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment on lines +86 to +92
HTTP_CODE=$(curl -s -o /tmp/api_response.json -w "%{http_code}" \
-H "Authorization: Bearer $SYSTEM_ACCESSTOKEN" "$API_URL")

if [[ "$HTTP_CODE" -lt 200 || "$HTTP_CODE" -ge 300 ]]; then
echo "##[warning]Builds API returned HTTP $HTTP_CODE — defaulting to meaningful build."
echo "##vso[task.setvariable variable=meaningful;isOutput=true]true"
exit 0
@paulmedynski paulmedynski marked this pull request as draft May 21, 2026 23:14
auto-merge was automatically disabled May 21, 2026 23:14

Pull request was converted to draft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area\Engineering Use this for issues that are targeted for changes in the 'eng' folder or build systems.

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

2 participants