Skip to content

ci: Cancel in-progress CI jobs when a PR is closed or merged#5725

Open
antonis wants to merge 2 commits intomainfrom
antonis/cancel-pr-workflows-on-close
Open

ci: Cancel in-progress CI jobs when a PR is closed or merged#5725
antonis wants to merge 2 commits intomainfrom
antonis/cancel-pr-workflows-on-close

Conversation

@antonis
Copy link
Contributor

@antonis antonis commented Feb 26, 2026

Summary

  • When a PR is merged (or closed), all in-progress and queued CI workflow runs for that PR's branch are now automatically cancelled

Problem

The existing concurrency groups use github.ref, which for PRs resolves to refs/pull/<number>/merge. When a PR is merged, the push to main creates a different concurrency group (refs/heads/main), so the still-running PR workflows are never cancelled. This wastes CI resources, especially for expensive jobs like native tests, E2E, and sample app builds.

Solution

A new lightweight workflow that:

  1. Triggers on pull_request: closed (fires on both merge and manual close)
  2. Lists all in_progress and queued workflow runs for the PR's head branch
  3. Cancels each one via the GitHub API

The workflow uses actions/github-script with the default GITHUB_TOKEN — no extra permissions needed.

🤖 Generated with Claude Code

The existing concurrency groups use `github.ref` which for PRs resolves
to `refs/pull/<number>/merge`. When a PR is merged, the push to main
creates a different concurrency group (`refs/heads/main`), so the
still-running PR workflows are never cancelled, wasting CI resources.

This adds a new workflow that triggers on `pull_request: closed` (fired
on both merge and manual close) and cancels all in-progress and queued
workflow runs for the PR's head branch via the GitHub API.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

github-actions bot commented Feb 26, 2026

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


  • ci: Cancel in-progress CI jobs when a PR is closed or merged by antonis in #5725
  • chore: add THIRD_PARTY_NOTICES.md for vendored third-party libraries by antonis in #5722
  • chore(changelog): Add version mismatch between Sentry Android SDK and Sentry Android Gradle Plugin entry by antonis in #5726
  • chore(deps): bump basic-ftp from 5.0.5 to 5.2.0 by dependabot in #5723
  • Fix(CI): Ignore folder path fix for typescript 3.8 test by lucas-zimerman in #5720
  • feat(tooling): add Cursor BUGBOT.md review guidelines by antonis in #5716
  • chore(ci): Use runner group 10 by itaybre in #5717
  • chore(deps): bump qs to ^6.14.2 by antonis in #5707
  • chore(deps): bump lodash to ^4.17.23 by antonis in #5702
  • chore(deps): bump getsentry/craft from 2.21.4 to 2.21.7 by dependabot in #5694
  • chore(deps): bump getsentry/craft/.github/workflows/changelog-preview.yml from 2.21.4 to 2.21.7 by dependabot in #5695
  • chore(deps): update CLI to v3.2.2 by github-actions in #5692
  • chore(deps): bump github/codeql-action from 4.32.3 to 4.32.4 by dependabot in #5693
  • chore(deps): update Maestro to v2.2.0 by github-actions in #5691
  • chore(deps): update Cocoa SDK to v9.5.0 by github-actions in #5685
  • chore(deps): update Android SDK Stubs to v8.33.0 by github-actions in #5697
  • chore(deps): update Android SDK to v8.33.0 by github-actions in #5684
  • chore(deps): update Sentry Android Gradle Plugin to v6.1.0 by github-actions in #5687
  • Ref(CI): Add android sdk version check by lucas-zimerman in #5686

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 26, 2026

Fails
🚫 Pull request is not ready for merge, please add the "ready-to-merge" label to the pull request

Generated by 🚫 dangerJS against ccbff33

@antonis antonis marked this pull request as ready for review February 26, 2026 09:45
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 4 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable autofix in the Cursor dashboard.

Wrap the cancelWorkflowRun call in try/catch so that if a run
completes between the list and cancel calls, the error doesn't
abort cancellation of the remaining runs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Collaborator

@lucas-zimerman lucas-zimerman left a comment

Choose a reason for hiding this comment

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

LGTM!

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