A continuous integration workflow runs on every push to a pull request branch. When a developer pushes several commits quickly, multiple runs for the same branch execute at once and burn billable minutes, even though only the newest commit matters. The author wants each new push to cancel any earlier in-progress run for that same branch while never cancelling runs on other branches. Which configuration achieves this?
on: push
<target>:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true- AAdd a needs entry referencing the previous run and set cancel-in-progress: true, so each run waits for and then supersedes the prior run on the same branch before continuing.
- BAdd a concurrency block with a group keyed by the workflow and github.ref and set cancel-in-progress: true, so a new run in the same branch group cancels the earlier in-progress one. Correct
- CAdd an if condition comparing github.sha to the head commit so older runs evaluate to false and skip their jobs, leaving only the newest push to execute its steps to completion.
- DAdd a strategy block with max-parallel: 1 so the branch processes only one run at a time, queueing each new push behind the previous run until that earlier run finishes naturally.
Why A is wrong: Tempting because needs sequences work, but it only orders jobs inside one run and cannot reference a separate earlier run, so it cannot cancel an in-progress run on the branch.
Why B is correct: A concurrency group keyed on the branch ref keeps each branch isolated, and cancel-in-progress: true stops the running member when a newer run joins, so superseded runs end immediately.
Why C is wrong: Tempting because an if guard can skip jobs, but an already-running older run keeps consuming minutes until it finishes, and the condition cannot cancel a run that has already started.
Why D is wrong: Tempting because max-parallel limits simultaneity, but it is a matrix setting that only throttles jobs within a run, and queueing still lets the stale earlier run finish and waste minutes.