GitHub Actions: Reusable Workflows
A reusable workflow is a workflow that other workflows can call. It holds shared steps in one file instead of copying them everywhere.
The shared test workflow
This file runs the tests. It runs only when another workflow calls it.
name: Reusable Test
on:
workflow_call:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: '24'
- run: npm testThe pain first: the same steps copied twice
Two workflows both check out, set up Node and run tests. One fix means two edits.
jobs:
test:
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
- run: npm testCall it from another workflow
A job can call the shared file instead of repeating the steps.
jobs:
test:
uses: ./.github/workflows/reusable-test.ymlExample
name: Call Reusable Test
on: push
jobs:
test:
uses: ./.github/workflows/reusable-test.ymlKey points
- Reusable workflow: a workflow file that other workflows call with workflow_call.
- Use workflow_call in the on block to mark a workflow as reusable.
- Use uses with a file path to call a reusable workflow from a job.
- A same-repo call uses a relative path like ./.github/workflows/reusable-test.yml.
- A cross-repo call uses owner/repo/.github/workflows/file.yml@ref instead.
- Fix the shared file once and every caller gets the fix.
- A reusable workflow is one file that many workflows share.
In this example, the workflow runs on every push. It has one job. The job does not list steps. It calls the shared test workflow by its path. That file checks out the code. It sets up Node 24. It runs npm test. The tests pass.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
Three workflows all run the same test steps. What is the best fix?