Sub topic 7
Requiring a shared workflow to pass before merging
This chapter assumes you can read a ruleset JSON body, know how status checks gate a pull request, and have written a GitHub Actions workflow. It also assumes you know that an organisation ruleset selects repositories by name. The goal is to make one workflow, stored in a single repository, run and pass on every pull request in the repositories you target.
Why a required workflow rule exists
A status check rule tells GitHub that a named check must pass. It does not make that check run. Each repository still has to contain a workflow that produces it, and a repository owner can delete or edit that workflow.
The workflows rule closes this gap. The ruleset points at a workflow file in a central repository. GitHub runs that file for every pull request that targets a matching branch, whatever the target repository contains. The result must pass before the merge is allowed.
This rule is available only in organisation rulesets. A repository-level ruleset cannot use it.
How the rule is defined
The rule entry names the workflow by repository ID, file path and Git ref:
{
"type": "workflows",
"parameters": {
"do_not_enforce_on_create": false,
"workflows": [
{
"repository_id": 123456,
"path": ".github/workflows/org-ci.yml",
"ref": "refs/heads/main"
}
]
}
}Replace 123456 with the ID of the repository that holds the workflow. You can add this entry to the rules array of the ruleset from the previous chapters. The conditions block of that ruleset then decides which repositories and branches are covered.
| Field | Meaning |
|---|---|
| `repository_id` | Numeric ID of the repository that stores the workflow file. |
| `path` | Path of the workflow file in that repository. |
| `ref` | Branch, tag or commit SHA to read the file from. |
| `do_not_enforce_on_create` | If `true`, a newly created branch is not checked until it receives later changes. |
Prefer a tag or a commit SHA for ref when you need reproducible behaviour. A branch such as main means every change merged there takes effect across the organisation immediately.
What the workflow must contain
The workflow runs in the context of the pull request, so it needs the pull_request or merge_group trigger. A minimal version looks like this:
name: org-ci
on:
pull_request:
merge_group:
jobs:
checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run organisation checks
run: echo "Run your shared checks here"Because the same file runs in many repositories, keep it generic. Detect the project type or call scripts that each repository provides, instead of hard-coding one build.
Common errors
- The check never appears. The workflow lacks a
pull_requesttrigger, or therepository_idorpathis wrong. The rule then waits for a result that never arrives. - Wrong repository ID. The
repository_idis a number, not the repository name. You can read it from the repository's API response. - Private workflow repository. The organisation must allow Actions in the central repository to be used by other repositories. Otherwise the run fails to start.
- Surprise failures after an edit. With
refset to a branch, editing the workflow changes behaviour everywhere. Test changes first with the ruleset in evaluate mode.
Exercise
Your organisation ruleset requires org-ci.yml from a central repository, but pull requests in one repository stay stuck waiting for the check forever. Name two likely causes.
Show answer
The workflow file may not have a pull_request (or merge_group) trigger, so no run is produced. The repository_id, path or ref in the rule may also be wrong, so GitHub cannot find the file. A central repository that does not allow its workflows to be used by other repositories is a third possibility.