Sub topic 11
Sharing workflows across repositories and an organization
This chapter assumes you can write a basic workflow, know how workflow_call and jobs.<job_id>.uses work, and understand secrets and the GITHUB_TOKEN. Here you will see who is allowed to call a reusable workflow, and how to set that up for a team.
Who can call a workflow
A caller can use a reusable workflow only if the called workflow's repository allows it. The rules depend on repository visibility.
| Called workflow lives in | Who can call it |
|---|---|
| A public repository | Any repository, by default |
| A private repository | Only repositories allowed in its Actions access settings |
| An internal repository (organizations on GitHub Enterprise Cloud) | Repositories in the same enterprise, if access is allowed |
For a private or internal repository, open Settings, then Actions, then General. Under Access, choose one of these options:
- Not accessible: only workflows in this repository can use its actions and reusable workflows.
- Accessible from repositories in the organization: any repository in the same organization can call them.
- Accessible from repositories in the enterprise: this option appears for internal repositories and widens access to the enterprise.
A private repository's workflows can be shared only within its organization. A public caller cannot use a workflow from a private repository.
A central workflow repository
A common pattern is one repository that holds the organization's shared workflows. The name is up to you. This chapter uses shared-workflows.
The called file must live in .github/workflows/ at the top level of that repository. Subdirectories are not supported. A caller then refers to it by owner, repository, path and ref:
# .github/workflows/ci.yml in any repository of my-org
name: CI
on:
pull_request:
jobs:
call-test:
uses: my-org/shared-workflows/.github/workflows/node-test.yml@v1
with:
node-version: '22'
secrets: inheritThe reference after @ follows the pinning rules from the previous chapter. Pin to a tag or commit SHA for stability.
Secrets across the boundary
A called workflow does not read the caller's secrets on its own. The caller passes them with secrets: or secrets: inherit. When the caller and the called workflow are in the same organization, secrets: inherit passes every secret the caller can access, including organization secrets. If the called workflow is in a different organization or enterprise, inherit is not available, so you must name each secret.
Prefer organization-level secrets for values that many repositories need, and limit each secret's repository access. Then inherit cannot hand a secret to a repository that should not have it.
Sharing in practice
- Create the shared repository and add the reusable workflow under
.github/workflows/. - If the repository is private or internal, set its Access option so the calling repositories are allowed.
- Tag a release such as
v1, and move that tag only for backward-compatible changes. - In each calling repository, add a job that uses the workflow with the tag.
- When you make a breaking change, publish
v2and move callers over one at a time.
Organization rulesets and required workflows can also run a workflow in many repositories without each one adding a caller. Use them for checks you need everywhere, such as security scans.
Common problems
- "Workflow was not found": the path, the ref, or the access setting is wrong. Check the file is directly under
.github/workflows/and that the caller is allowed. - A secret is empty in the called workflow: the caller did not pass it, or the secret is not available to the calling repository.
- Using a private repository's workflow from a public repository: this is not allowed. Move the workflow to a public repository, or make the caller private.
Exercise
Your organization keeps a private shared-workflows repository. A new repository in the same organization gets a "workflow was not found" error when it calls deploy.yml, even though the path and tag are correct. What should you check first, and which secrets option can you use once the call works?
Show answer
Check the Actions access setting of shared-workflows (Settings, Actions, General, Access). It must allow access from repositories in the organization. Once the call works, secrets: inherit can pass the caller's secrets, because both repositories are in the same organization.