brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: concurrency with cancel-in-progress stops older workflow runs when you push again

Git
~/tips/tip-github-actions-concurrency-cancel

concurrency:

Makes a GitHub Actions workflow cancel its older run on the same branch when a new one starts.

Push, notice a typo, push again. Now two runs of the same workflow are going for the same branch, and the first one is a waste of runner minutes. A concurrency block in the workflow file takes care of that.

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

Put it at the top level of the workflow file, next to on: and jobs:. Runs that share the same group name are limited to one at a time. According to the GitHub docs, cancel-in-progress: true also cancels a currently running job or workflow in the same group. The group above combines the workflow name with the ref, which is the form the docs use as an example, so every branch gets its own queue.

The docs also describe what happens without the cancel line. By default only one run can be pending in a group. When a newer run is queued, an existing pending run in the same group is canceled and replaced. The run that is already in progress is left to finish.

You can also use the concurrency keyword at the job level, to limit the concurrency of jobs inside a workflow.

Caveats from the same page:

  • Group names are case insensitive.
  • Group names must be unique across workflows, otherwise one workflow can cancel the runs of another. That is the reason for putting github.workflow in the name.

Think twice before you use it on a deployment workflow. A cancelled deploy can end up half done, so for those drop the cancel-in-progress line and let the runs queue up one after another.

Further reading: GitHub docs: control the concurrency of workflows and jobs

Going deeper: Moving on from hdtv: how to export your TV show list to Trakt.tv

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link