githubgithub-actionsworkflow

Make workflow run sequentially, allowing one job run at a time for Github Action reusable workflow


I have multiple repos calling to a reusable workflow. I want the github action in each repo that call reusable workflow must be run sequentially, out of order is fine but only 1 workflow can be run at a time. Not in a way of cancelling another running workflow but put it in queue and run later.

Here is more detail of my setup. I have the reusable workflow like this, already setup grant access permission from other repos.

name: Reusable workflow

on:
  workflow_call:
    inputs:
      config-path:
        required: true
        type: string
    secrets:
      personal_access_token:
        required: true

concurrency:
  group: global-group
  cancel-in-progress: false

jobs:
  ...

In other repos, I added workflows that reference to the reusable workflow above

name: Call reusable workflow

on:
  pull_request:
    types: [opened, synchronize, reopened]

jobs:
  call-reusable-workflow:
    name: foo
    uses: foo/bar/.github/workflows/reusable-workflow.yml@main
    with:
      config-path: "foo"
    secrets:
      personal_access_token: "bar"

In overall, the set up look like this:

Repo1 workflow -> reusable workflow
Repo2 workflow -> reusable workflow
Repo3 workflow -> reusable workflow
Repo4 workflow -> reusable workflow
... repo N

The github actions in RepoX run correctly, it can refer to the reusable workflow. But, I want the github action in each repo that call reusable workflow must be run sequentially, out of order is fine but only 1 workflow can be run at a time. Not in a way of cancelling another running workflow but put it in queue and run later.

Does someone counter this issue before? Thank you!!


Solution

  • Firstly I created a test in my GitHub profile, as repoA, repoB and ci-orchestrator. You may check them out if you want example on how to create the .yml files for dispatch.yaml and handle-dispatch.yml

    GitHub Actions' concurrency only works within a single repository. If multiple repositories use the same reusable workflow, adding:

    concurrency:
      group: global-group
      cancel-in-progress: false
    

    …won’t prevent parallel executions across repos, because GitHub scopes concurrency groups per repo.

    What you can do is, create a Orchestrator Repository + repository_dispatch