Skip to content

GitHub Actions: Examples for canceling in-progress jobs / runs with concurrency groups lead to confusing behavior #11243

Description

@mnquintana

Code of Conduct

What article on docs.github.com is affected?

https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#example-using-concurrency-to-cancel-any-in-progress-job-or-run

What part(s) of the article would you like to see updated?

👋🏽 I recently made a change to several of our GitHub Actions workflows that adds the config from https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#example-using-concurrency-to-cancel-any-in-progress-job-or-run to cancel any redundant in-progress run on the current PR – to recreate the PR behavior other CI providers offer out of the box. (e.g. Azure Pipelines, CircleCI)

However, it wasn't having the intended effect – it resulted in progress runs of these workflows to get canceled no matter what branch they're on, so long as they have an open PR.

From a lot of back and forth with GitHub Support, it turns out the issue was that the repo has multiple workflows that run on pull requests. Concurrency group names must be unique for each workflow across the whole repo, otherwise they will auto-cancel each other on a single PR run (because that would mean they share the same concurrency group).

In the example given in the GitHub Actions docs, github.head_ref evaluates to the same string on every workflow on a given PR, leading to these workflow runs were clobbering each other.

The fix is to ensure that each concurrency group name is unique. But, this wasn't clear to me from the docs at all – I only found this out from messaging GitHub Support and a lot of trial and error. I'd like to do what I can to help other folks avoid similar frustration in the future, with any luck. 🙏🏽

Expected

The docs gives examples for how multiple workflows with auto-canceling in-progress runs / jobs can coexist without auto-canceling each other.

Actual

The docs' only example for enabling auto-canceling on a PR sets a single concurrency group name that doesn't allow for multiple workflows to coexist without auto-canceling each other on a pull request (github.head_ref as the whole concurrency group name)

Let me know if there's any more information I could add that would be helpful! 🙇🏽 I'll have a PR up for this shortly.

Additional information

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    contentThis issue or pull request belongs to the Docs Content team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions