Cancel superseded CI runs with a concurrency group - #52
Conversation
📝 WalkthroughWalkthroughThe macOS, Ubuntu, and wheel-test GitHub Actions workflows now cancel superseded runs on non- ChangesCI concurrency controls
Estimated code review effort: 1 (Trivial) | ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/cicd-mac.yml:
- Around line 21-23: Use a unique concurrency group for main runs by updating
the concurrency.group expressions in .github/workflows/cicd-mac.yml lines 21-23,
.github/workflows/cicd-ubuntu.yml lines 19-21, and
.github/workflows/cicd-wheel-test.yml lines 24-26 to incorporate github.run_id
for the main branch, while preserving the existing grouping and cancellation
behavior for non-main runs.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 71a22ccf-ae6d-4ebc-99cd-bc818ac9dc9d
📒 Files selected for processing (3)
.github/workflows/cicd-mac.yml.github/workflows/cicd-ubuntu.yml.github/workflows/cicd-wheel-test.yml
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== workflow concurrency sections =="
for f in .github/workflows/cicd-mac.yml .github/workflows/cicd-ubuntu.yml .github/workflows/cicd-wheel-test.yml; do
if [ -f "$f" ]; then
echo "--- $f"
nl -ba "$f" | sed -n '1,60p'
else
echo "MISSING $f"
fi
done
echo
echo "== all workflow concurrency usages =="
rg -n "concurrency:|group:|cancel-in-progress:" .github/workflows || true
echo
echo "== expression parser/runtime hints from installed tooling =="
command -v gh || true
command -v python3 || true
python3 - <<'PY'
try:
from asteval import Interpreter
print("asteval available")
except Exception as e:
print("asteval unavailable:", type(e).__name__)
PY
node - <<'JS'
console.log("github.ref != refs/heads/main for main:", 'refs/heads/main' != 'refs/heads/main');
console.log("github.ref != refs/heads/main for pr:", 'refs/pull/123/head' != 'refs/heads/main');
console.log("main run_id branch expression:", ('refs/heads/main' === 'refs/heads/main' ? 'unique:' + 123 : 'refs/heads/main'));
console.log("pr branch expression:", ('refs/pull/123/head' === 'refs/heads/main' ? 'unique:' + 456 : 'refs/pull/123/head'));
JSRepository: icppWorld/icpp-pro
Length of output: 267
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== workflow concurrency sections =="
for f in .github/workflows/cicd-mac.yml .github/workflows/cicd-ubuntu.yml .github/workflows/cicd-wheel-test.yml; do
if [ -f "$f" ]; then
echo "--- $f"
python3 - "$f" <<'PY'
import sys
path = sys.argv[1]
with open(path, encoding="utf-8") as fh:
for i, line in enumerate(fh, 1):
if 1 <= i <= 55:
print(f"{i}\t{line.rstrip()}")
PY
else
echo "MISSING $f"
fi
done
echo
echo "== all workflow concurrency usages =="
rg -n "concurrency:|group:|cancel-in-progress:" .github/workflows || true
echo
echo "== expression runtime semantics probe =="
node - <<'JS'
const cases = {
main: 'refs/heads/main',
pr: 'refs/pull/123/head',
tag: 'refs/tags/v1.0.0',
};
for (const [name, gref] of Object.entries(cases)) {
const expressions = {
defaultGroup: `${{ github.workflow }}-${{ github.ref }}`,
currentGroupPr: `mac-${gref}`,
canceled: gref !== 'refs/heads/main',
uniqueMainGroup: `${${{ gref === 'refs/heads/main' ? 999 : gref }}`,
};
console.log(`${name}:`, { currentGroupPr, canceled, uniqueMainGroup });
}
console.log("node", process.version);
JSRepository: icppWorld/icpp-pro
Length of output: 8268
Use a unique concurrency group for main runs.
A non-zero cancel-in-progress value still cancels pending runs in the same group. These workflows keep main in ${{ github.workflow }}-${{ github.ref }}, so a new main run can cancel an older pending main run in the same concurrency group.
Use github.run_id for the main group instead:
- group: ${{ github.workflow }}-${{ github.ref }}
+ group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_id || github.ref }}Apply this to cicd-mac.yml, cicd-ubuntu.yml, and cicd-wheel-test.yml.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_id || github.ref }} | |
| cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} |
📍 Affects 3 files
.github/workflows/cicd-mac.yml#L21-L23(this comment).github/workflows/cicd-ubuntu.yml#L19-L21.github/workflows/cicd-wheel-test.yml#L24-L26
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/workflows/cicd-mac.yml around lines 21 - 23, Use a unique
concurrency group for main runs by updating the concurrency.group expressions in
.github/workflows/cicd-mac.yml lines 21-23, .github/workflows/cicd-ubuntu.yml
lines 19-21, and .github/workflows/cicd-wheel-test.yml lines 24-26 to
incorporate github.run_id for the main branch, while preserving the existing
grouping and cancellation behavior for non-main runs.
Pushing to a branch does not cancel the previous run, so a superseded matrix keeps going.
That is not just wasted minutes: the macOS runner pool is small, so the stale run holds
runners and the new one sits queued behind it. This happened during #51 — the mac matrix on
the superseded commit had to be cancelled by hand before the new one could start.
Added to all three workflows.
Why
mainis excludedNot the usual
cancel-in-progress: true. The release process pushes a version commit tomainand then waits on its CI before publishing. With unconditional cancellation, a secondpush to
main— say apyproject.tomldependency bump landing right after the versioncommit, which is exactly what 6.0.0 did — would silently kill the run being waited on.
Superseded branch runs are waste. Superseded main runs are release evidence.
Verified
All three files parse with
yaml.safe_load, and each workflow lists its own path in itstrigger filter, so this PR exercises the new config on itself.
Summary by CodeRabbit