Skip to content

Add concurrency cancellation to all PR-triggered workflows#4318

Merged
janhoy merged 2 commits intoapache:mainfrom
janhoy:add-concurrency-to-workflows
Apr 22, 2026
Merged

Add concurrency cancellation to all PR-triggered workflows#4318
janhoy merged 2 commits intoapache:mainfrom
janhoy:add-concurrency-to-workflows

Conversation

@janhoy
Copy link
Copy Markdown
Contributor

@janhoy janhoy commented Apr 22, 2026

I noticed that the PR check workflow queue was very long, and that a new commit to a PR would not cancel the queued checks for previous commits. This wastes resources and causes longer delay before e.g. Crave.io will test new PRs, since it is doing work noone cares about.

This PR adds a concurrency block to all 9 PR-triggered GitHub Actions workflows, so that when a new commit is pushed to a PR, any previously queued or in-progress runs for that same PR are automatically cancelled.

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

The group key is scoped per workflow + PR number, so cancellation is isolated: a new commit to PR #123 only cancels other runs of the same workflow for PR #123 — it does not affect other PRs or other workflows.

Workflows updated

All 9 PR-triggered workflows:

  • bin-solr-test.yml
  • docker-test.yml
  • gradle-extraction-check.yml
  • gradle-precommit.yml
  • labeler.yml
  • renovate-changelog.yml
  • solrj-test.yml
  • tests-via-crave.yml ← most impactful (Crave.io, 30+ min runs)
  • validate-changelog.yml

Impact

Without this change, every commit to a PR queues a fresh run of every workflow while old runs continue to hold resources. The Crave.io queue in particular can accumulate dozens of stale runs per active branch, adding hours of unnecessary wait time for everyone. With this change, only the run for the latest commit matters — older ones are cancelled
automatically by GitHub Actions before they consume any resources.

Each new commit to a PR now automatically cancels any queued or in-progress
CI runs for the same PR, preventing stale runs from blocking the queue.

Adds a top-level `concurrency` block to all 9 PR-triggered workflows:
- group key: workflow name + PR number (or ref as fallback)
- cancel-in-progress: true
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

Adds workflow-level GitHub Actions concurrency to cancel superseded runs for pull-request-triggered CI, reducing queued/stale work when new commits are pushed to the same PR.

Changes:

  • Added concurrency groups scoped by workflow name + PR number (fallback to ref) across PR-triggered workflows.
  • Enabled cancel-in-progress: true so older queued/running executions are canceled when newer PR commits arrive.

Reviewed changes

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

Show a summary per file
File Description
.github/workflows/bin-solr-test.yml Add concurrency/cancel-in-progress for PR script-test workflow runs.
.github/workflows/docker-test.yml Add concurrency/cancel-in-progress for PR Docker build/test runs.
.github/workflows/gradle-extraction-check.yml Add concurrency/cancel-in-progress for PR extraction module checks.
.github/workflows/gradle-precommit.yml Add concurrency/cancel-in-progress for PR Gradle precommit checks.
.github/workflows/labeler.yml Add concurrency/cancel-in-progress for PR labeler runs.
.github/workflows/renovate-changelog.yml Add concurrency/cancel-in-progress for Renovate PR changelog automation.
.github/workflows/solrj-test.yml Add concurrency/cancel-in-progress for PR SolrJ test runs.
.github/workflows/tests-via-crave.yml Add concurrency/cancel-in-progress for PR Crave-based test runs.
.github/workflows/validate-changelog.yml Add concurrency/cancel-in-progress for PR changelog validation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/tests-via-crave.yml
With cancel-in-progress: true, a cancelled run may not complete its Cleanup
step before being forcefully terminated, leaving orphaned Crave clones.

Switch the workspace path from run-scoped (GITHUB_RUN_ID_RUN_NUMBER) to
PR-scoped (prs/PR_NUMBER). The "Destroy previous clone" step at the start of
each new run now reliably destroys any leftover resources from a previous run
for that PR — whether it ended normally, failed, or was cancelled mid-flight.
Comment thread .github/workflows/tests-via-crave.yml
janhoy added a commit to janhoy/solr that referenced this pull request Apr 22, 2026
Replace the run-scoped workspace path (GITHUB_RUN_ID_GITHUB_RUN_NUMBER)
with a PR-scoped path (prs/<pr-number>) via a CRAVE_WORKSPACE env var.

When cancel-in-progress cancels a run, the cleanup step may not finish,
leaving a stale workspace. With a PR-scoped path, the next run's
"Destroy previous clone" step will always clean up any leftover resources
from a prior run for the same PR, regardless of how it ended.

Backport of apache#4318.
Copy link
Copy Markdown
Contributor

@gerlowskija gerlowskija left a comment

Choose a reason for hiding this comment

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

LGTM - nice cleanup @janhoy !

@janhoy janhoy merged commit 38c8768 into apache:main Apr 22, 2026
7 of 8 checks passed
@janhoy janhoy deleted the add-concurrency-to-workflows branch April 22, 2026 20:38
@janhoy
Copy link
Copy Markdown
Contributor Author

janhoy commented Apr 23, 2026

Proof of it working - earlier all commits would queue up, now they cancel:
Skjermbilde 2026-04-23 kl  10 16 15

Copy link
Copy Markdown
Contributor

@dsmiley dsmiley left a comment

Choose a reason for hiding this comment

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

Thanks for this!

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.

4 participants