Reusable Workflows and Composite Actions
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
Copy-pasting a workflow between repositories, or between two files in one repository, is the fastest way to end up
with five slightly different pipelines. GitHub offers two reuse mechanisms that operate at different levels. A
reusable workflow is a whole workflow (with its own jobs and runners) that another workflow calls as a job. A
composite action is a bundle of steps that another job runs as a single step. This page explains both, how to
choose, and how to share them across an organisation. The running example is this documentation site: its publish
and manual_publish workflows are byte-for-byte twins except for the trigger, which is exactly what a reusable
workflow removes. Versions were verified on 2026-11-10; the official docs win on any discrepancy. Background on
workflow files is on Workflow Syntax and Triggers.
Reusable workflows
A workflow becomes reusable by listing workflow_call under on. It can declare typed inputs, secrets and outputs:
# .github/workflows/build-antora.yml in the called repository
name: build-antora
on:
workflow_call:
inputs:
node-version:
description: Node.js version
type: string
default: '24'
playbook:
type: string
default: antora-playbook.yml
artifact-name:
type: string
default: docs-site
secrets:
npm-token:
required: false
outputs:
artifact-name:
description: Name of the uploaded site artifact
value: ${{ jobs.build.outputs.artifact-name }}
jobs:
build:
runs-on: ubuntu-latest
outputs:
artifact-name: ${{ steps.meta.outputs.name }}
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: ${{ inputs.node-version }}
cache: npm
- run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.npm-token }}
- run: npx antora ${{ inputs.playbook }}
- id: meta
run: echo "name=${{ inputs.artifact-name }}" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@v7
with:
name: ${{ inputs.artifact-name }}
path: build/site
Input types are string, number and boolean. Inputs are available in the inputs context (not github.event),
and in a called workflow the github context still describes the caller’s event, so github.repository and
github.sha refer to the calling repository.
Calling a reusable workflow
A reusable workflow is called with uses at the job level, instead of runs-on and steps:
| Syntax | Where the workflow lives |
|---|---|
|
Another repository; |
|
The same repository. It runs at the caller’s commit, so no ref is allowed. |
# .github/workflows/publish.yml
name: publish
on:
schedule:
- cron: '0 3 * * *'
jobs:
build:
uses: albertoirurueta/docs/.github/workflows/build-antora.yml@v1
with:
node-version: '24'
secrets:
npm-token: ${{ secrets.NPM_TOKEN }}
report:
needs: build
runs-on: ubuntu-latest
steps:
- run: echo "Site artifact is ${{ needs.build.outputs.artifact-name }}"
Rules to remember: a job that uses a reusable workflow cannot also have steps; it can have needs, if, with,
secrets, strategy, permissions and concurrency; and outputs of the called workflow are read through
needs.<job>.outputs.
Secrets
Secrets are not inherited implicitly across repositories: pass them by name under secrets:, or forward all of the
caller’s secrets with secrets: inherit.
jobs:
build:
uses: ./.github/workflows/build-antora.yml
secrets: inherit
secrets: inherit is convenient inside one organisation, but it hands the called workflow every secret the caller
can see, so prefer explicit names when the workflow lives in a different repository or you do not control it. The
called workflow must still declare the secrets it uses under on.workflow_call.secrets if you pass them by name.
See Secrets, Variables and OIDC.
Matrix and permissions
A caller can fan a reusable workflow out with a matrix:
jobs:
build:
strategy:
matrix:
node: ['22', '24']
uses: ./.github/workflows/build-antora.yml
with:
node-version: ${{ matrix.node }}
artifact-name: docs-site-${{ matrix.node }}
Permissions follow a one-way rule: the called workflow’s GITHUB_TOKEN can be downgraded but never elevated
relative to the caller. Set permissions: on the calling job (or workflow) to the maximum you are willing to grant,
and restrict further inside the called workflow:
permissions:
contents: read
id-token: write # only if the called workflow needs OIDC
If the called workflow needs id-token: write or pages: write, the caller must grant it first.
Nesting and limits
A workflow can call another reusable workflow, which can call another, to several levels deep (check the current limit in the docs, as it has been raised over time); loops, where a workflow calls itself directly or indirectly, are not allowed. A single workflow run can also call only a bounded number of unique reusable workflows. Keep the chain short: debugging a failure four calls deep is unpleasant.
Other restrictions worth knowing:
-
Environment variables set with
envin the caller are not propagated to the called workflow; usewith:. -
GITHUB_ENVandGITHUB_PATHchanges do not leak between the caller and called jobs. -
A reusable workflow in a private repository is callable only if that repository’s Actions settings allow access from other repositories (Settings, then Actions, then General, then Access).
Composite actions
A composite action packages steps. It is defined by an action.yml with runs.using: composite, usually in its own
folder such as .github/actions/setup-antora/action.yml:
name: Setup Antora
description: Install Node with npm caching and the Antora dependencies
inputs:
node-version:
description: Node.js version
default: '24'
outputs:
antora-version:
description: Installed Antora version
value: ${{ steps.v.outputs.version }}
runs:
using: composite
steps:
- uses: actions/setup-node@v7
with:
node-version: ${{ inputs.node-version }}
cache: npm
- run: npm ci
shell: bash
- id: v
run: echo "version=$(npx antora --version | head -n1)" >> "$GITHUB_OUTPUT"
shell: bash
-
Every
run:step must setshell:(bash,pwsh,sh,python,cmd…). There is no job-level default inherited from the workflow. -
Inputs are read with
inputs.<name>; outputs need avalueexpression pointing at a step’s output. -
Steps can call other actions with
uses:, including other composite actions. -
A composite action does not have its own
runs-on,secrets,services,strategyorpermissions; it runs inside the caller’s job and shares its runner, workspace and token. Pass secrets as inputs and mask them. -
A local composite action needs
actions/checkoutto run first so the folder exists on the runner.
Calling it:
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/setup-antora
with:
node-version: '24'
- run: npx antora antora-playbook.yml
Reusable workflow or composite action?
| Question | Reusable workflow | Composite action |
|---|---|---|
Granularity |
Entire jobs (runner, matrix, services, environments). |
A sequence of steps inside one job. |
Runner selection |
Chosen by the called workflow ( |
Inherits the caller’s runner. |
Secrets |
Declared and passed explicitly, or |
Passed as inputs; shares the caller job’s context. |
Shows in the run UI as |
A separate group of jobs, easy to read logs. |
A single step with collapsed nested steps. |
Nesting |
Several levels. |
Composites can call composites. |
Best for |
A standard pipeline (build, test, deploy) shared by many repositories. |
Repeated setup or utility steps used inside many different jobs. |
Versioning |
|
|
In practice they combine: a reusable workflow defines the pipeline, and inside it a composite action does the repeated setup.
Sharing across an organisation
Starter workflows
A public or internal repository named .github in the organisation can offer starter workflows, templates that
appear in the Actions, New workflow page of every repository. Put them in workflow-templates/ with a matching
properties file:
.github/
workflow-templates/
antora-docs.yml
antora-docs.properties.json
{
"name": "Antora docs site",
"description": "Build an Antora site and publish it to GitHub Pages.",
"iconName": "octicon book",
"categories": ["Documentation", "JavaScript"],
"filePatterns": ["^antora-playbook\\.yml$"]
}
The $default-branch placeholder in a template is replaced by the repository’s default branch when a user adopts
the template. filePatterns makes the template show up only in repositories with matching files. Starter workflows
are copied, not linked, so later changes do not propagate; for that, the template should simply call a reusable
workflow.
Required workflows and rulesets
Organisation owners can require a workflow to pass on all (or selected) repositories through repository rulesets (Settings, then Rules, then Rulesets, then Require workflows to pass before merging). This is the enforcement counterpart to starter workflows: the workflow lives in a central repository and runs on pull requests in the targeted repositories whether or not they opted in. Branch rules are introduced on Branches and pull-request gating on Pull Requests.
Versioning and pinning shared workflows
Treat a shared workflow like a library with consumers:
-
Tag releases (
v1.2.0) and move a major tag (v1) for compatible changes, as described on Using and Writing Actions. -
Consumers that handle secrets or deploy should pin to a full commit SHA and let Dependabot propose updates:
uses: org/shared/.github/workflows/build.yml@<sha> # v1.2.0. -
A branch ref such as
@mainmeans every merge to the shared repository changes all callers immediately; reserve it for experiments. -
Never reference a reusable workflow from a fork or personal repository you do not control.
Example: one build-antora workflow for the docs site
Today publish.yml and manual_publish.yml each repeat the checkout, Node setup, Antora install, Mermaid
validation, build and deploy steps. Moving the common steps into a reusable workflow keeps one definition (the
following is a proposal for this repository, not what the workflow does today).
# .github/workflows/build-antora.yml (called)
name: build-antora
on:
workflow_call:
inputs:
node-version:
type: string
default: '24'
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: write # crazy-max/ghaction-github-pages pushes to gh-pages
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: ${{ inputs.node-version }}
- name: Install Antora
run: |
npm i -D -E antora
npm i @antora/collector-extension @sntke/antora-mermaid-extension @djencks/asciidoctor-mathjax
- name: Validate Mermaid diagrams
run: |
npm i --no-save mermaid@11 jsdom
node scripts/validate-mermaid.mjs
- name: Build Antora docs
run: npx antora antora-playbook.yml
- name: Deploy to GitHub Pages
uses: crazy-max/ghaction-github-pages@v5
with:
target_branch: gh-pages
build_dir: ./build/site
fqdn: www.irurueta.com
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# .github/workflows/publish.yml (caller, nightly)
name: publish
on:
schedule:
- cron: '0 3 * * *'
jobs:
publish:
uses: ./.github/workflows/build-antora.yml
permissions:
contents: write
# .github/workflows/manual_publish.yml (caller, on demand)
name: manual_publish
on: workflow_dispatch
jobs:
publish:
uses: ./.github/workflows/build-antora.yml
with:
node-version: '24'
permissions:
contents: write
Each caller is now a dozen lines, and a change such as adding npm caching, a concurrency group or SHA-pinned actions
happens in one file. The deploy step uses the built-in token, which secrets: inherit is not needed for because
GITHUB_TOKEN is always available in the called workflow.
Common mistakes
-
Putting
stepsorruns-onnext tousesin the calling job. -
Referencing the called workflow with a path outside
.github/workflows. -
Using
secrets: inheritfor a workflow you do not control; it exposes every secret the caller can see. -
Expecting
envin the caller to be visible in the called workflow. -
Omitting
shell:in a composite action’srunstep. -
Calling a composite action from a local path before checking out the repository.
-
Using
@mainfor shared workflows that deploy.