Reusable workflows & composite actions
Share one pipeline across many repos.
By Invicly Tech, , in Git, GitHub & GitHub Actions. About 10 minutes to read.
In short
Reusable workflows let many repos call one shared pipeline, while composite actions bundle several steps into one reusable step. Both stop you copying the same YAML everywhere.
Explained simply
Once a team has ten repos, it often has ten nearly identical CI files. When you want to change one thing, like the Python version or a security scan, you edit ten files and forget two. Reuse fixes that: write the pipeline once, and let every repo call it.
GitHub offers two tools. A reusable workflow is a whole workflow (one or more jobs) that other workflows can call, like a function. A composite action is a bundle of steps that you use as a single step inside your own job.
Think of it like cooking. A reusable workflow is ordering the full set menu: the kitchen runs every course for you. A composite action is a spice mix: you still cook your own meal, you just add the same blend every time.
Both take inputs, so each repo can adjust details like the version or the folder. Both should be versioned with tags, so a change in the shared copy reaches each repo only when that repo chooses to upgrade.
Press Play on a diagram to walk through it one step at a time.
- Triggered by workflow_call
- Called at job level with uses
- Can contain many jobs
- Takes inputs and secrets
- runs: using: composite
- Called as a step with uses
- Bundles several steps
- Runs inside the caller's job
- 1Reusable workflow
Whole pipeline: jobs, runners, environments
- 2Job in your workflow
Your own runs-on and steps
- 3Composite action
A bundle of steps used as one step
- 4JavaScript or Docker action
Custom code behind one step
- 5Shell script in the repo
Smallest reuse: run: ./scripts/x.sh
In depth
What happens when a workflow calls another
A caller job has uses: OWNER/REPO/.github/workflows/FILE.yml@REF (or ./.github/workflows/FILE.yml for the same repo) instead of runs-on and steps. GitHub loads the called file at that ref and runs its jobs as part of the caller's run; in the UI they appear nested under the caller job.
The called workflow sees the caller's world. The github context is the caller's, so github.repository is the calling repo and actions/checkout checks out the caller's code. The GITHUB_TOKEN permissions can only stay the same or be reduced inside the called workflow, never raised. Environment variables set with env: in the caller are not passed down; use inputs instead.
- Caller repo to GitHub: Job uses acme/ci/...python-ci.yml@v11Job uses acme/ci/...python-ci.yml@v1
- GitHub to Shared repo: Load workflow file at tag v12Load workflow file at tag v1
- 3Check inputs, secrets, permissionsGitHub to GitHub: Check inputs, secrets, permissions
- GitHub to Runner: Run called jobs in the caller's context4Run called jobs in the caller's context
- Runner to GitHub: Job outputs and results5Job outputs and results
- GitHub to Caller repo: Outputs available via needs6Outputs available via needs
Inputs, secrets and outputs
Under on: workflow_call you declare inputs with a type (string, number or boolean), plus required or default. Secrets are declared separately and the caller passes them with secrets:, or with secrets: inherit to pass all of its secrets (only within the same organization or enterprise). Outputs map to job outputs: value: ${{ jobs.build.outputs.image }}.
The caller job may also use with, needs, if, permissions, concurrency and strategy, so a matrix can call the same workflow several times. One subtle rule: if the called job sets environment:, it receives that environment's secrets from the caller repo, not values passed through workflow_call. That is actually convenient for deploy workflows.
- Caller keys: uses, with, secrets, needs, if, permissions, strategy, concurrency
- Not allowed on a caller job: runs-on and steps
- Inputs are typed; workflow_call has no choice type
Composite actions in detail
A composite action is a folder with an action.yml whose runs: section says using: composite and lists steps. Each run: step must set shell: explicitly, because there is no default inside a composite action. Steps read inputs with ${{ inputs.NAME }}, and outputs map a step output with value:. Scripts stored next to action.yml are reachable through ${{ github.action_path }}.
Composite actions run inside the caller's job, on the same runner and workspace, so they see the checked-out files and the job's environment. They cannot read the secrets context directly; pass secrets in as inputs. In the log they show as one step that you can expand. Reference them as OWNER/REPO/PATH@REF, or ./path/to/action for a local one, which requires actions/checkout to run first.
Sharing across repos and versioning
A reusable workflow or action in a public repo can be used by anyone. For private or internal repos, open the shared repo's Settings, Actions, General, and under Access allow repositories in the organization (or enterprise) to use it. The calling repos need no extra token.
Treat the shared repo like a library. Tag releases like v1.3.0 and move a major tag v1 to the newest compatible one. Callers on @v1 get fixes automatically; breaking changes go to v2. Security-sensitive callers can pin a full commit SHA instead, and Dependabot can keep that pin up to date. Avoid @main: one bad commit would break every repo at the same moment.
- .github/workflows/
- python-ci.yml (workflow_call)
- deploy.yml (workflow_call)
- actions/setup-app/
- action.yml (composite)
- install.sh
- Tags
- v1.3.0, v1.3.1
- v1 moves to the latest 1.x
- Settings, Actions, Access
- Allow repos in the organization
Learn it in 4 short steps
About 45m each. Track them with a timer in your plan.
- 1Write a reusable workflow with workflow_call~45m
- 2Pass inputs and secrets to it~45m
- 3Build a composite action~45m
- 4Call shared workflows from other repos~45m
Key points
- Use a reusable workflow to standardise a whole pipeline across repos.
- Use a composite action for a small repeated sequence of steps.
- Pass secrets explicitly, or with secrets: inherit inside the same organization.
- Reference shared workflows by tag or commit SHA so updates are deliberate.
Key terms
Tap a card to flip it. 0/4 known
Examples
# acme/shared/.github/workflows/python-ci.yml
on:
workflow_call:
inputs:
python-version: { type: string, default: "3.12" }
jobs:
test:
runs-on: ubuntu-latest
steps: [{ uses: actions/checkout@v4 }, { run: pytest }]
# caller repo
jobs:
ci:
uses: acme/shared/.github/workflows/python-ci.yml@v1
with: { python-version: "3.13" }One shared CI workflow, called with an input.
A shared deploy workflow with inputs, secrets and an output
Every service deploys the same way. Step 1: in acme/ci, declare a required environment input, a required secret and an output. Step 2: the job uses environment: from the input, so the caller repo's environment rules and secrets apply. Step 3: a step writes the deployed URL as an output. Step 4: each service calls it with a single job (shown in the last comment line) and can read needs.prod.outputs.url.
on:
workflow_call:
inputs: { environment: { type: string, required: true } }
secrets: { DEPLOY_TOKEN: { required: true } }
outputs: { url: { value: "${{ jobs.deploy.outputs.url }}" } }
jobs:
deploy:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
outputs: { url: "${{ steps.d.outputs.url }}" }
steps:
- uses: actions/checkout@v4
- id: d
run: ./deploy.sh "${{ inputs.environment }}" && echo "url=https://${{ inputs.environment }}.example.com" >> "$GITHUB_OUTPUT"
env: { TOKEN: "${{ secrets.DEPLOY_TOKEN }}" }
# caller: prod: { uses: acme/ci/.github/workflows/deploy.yml@v1, with: { environment: production }, secrets: inherit }A composite action that sets up a Python app
Five workflows start with the same three steps. Step 1: create .github/actions/setup-app/action.yml with an input for the Python version. Step 2: list the steps; the run step needs shell: bash. Step 3: expose setup-python's output as the action's output. Step 4: in each workflow, after actions/checkout, replace the three steps with one uses: ./.github/actions/setup-app.
name: Setup app
description: Install Python, cache pip and install dependencies
inputs:
python-version: { description: Python version, default: "3.13" }
outputs:
python-path: { description: Python used, value: "${{ steps.py.outputs.python-path }}" }
runs:
using: composite
steps:
- id: py
uses: actions/setup-python@v5
with: { python-version: "${{ inputs.python-version }}", cache: pip }
- run: pip install -r requirements.txt
shell: bashQuick reference
- Call a reusable workflow at job level: uses: OWNER/REPO/.github/workflows/FILE.yml@v1
- A caller job cannot have runs-on or steps; it can have with, secrets, needs, if, strategy
- secrets: inherit passes all caller secrets, within the same organization or enterprise
- Every run step in a composite action needs shell:
- ${{ github.action_path }} points to the composite action's own folder
- Private shared repos: Settings, Actions, General, Access, allow the organization
- Pin shared workflows to a tag or SHA, never @main
- Caller env: values are not passed to the called workflow; use inputs
Common mistakes
- Pointing at @main of a shared workflow, so a change breaks every repo at once.
- Forgetting shell: on run steps in a composite action, which is required.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Turn your repo's test job into a reusable workflow in the same repo and call it from ci.yml.
- Exercise 2medium
Call the same reusable workflow for three Python versions using a matrix in the caller.
- Exercise 3hard
Return the built image tag from a reusable build workflow and use it in a deploy job of the caller.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- Reusable workflow or composite action: which should I use?
- Use a reusable workflow to share a whole pipeline, including runners and environments. Use a composite action to share a few steps that run inside jobs you already have.
- Can a reusable workflow call another reusable workflow?
- Yes, nesting is allowed up to a fixed depth. Keep it shallow, because deep chains are hard to debug and permissions can only shrink at each level.
- Do I need a token to use workflows from a private repo in my organization?
- No. Allow access in the shared repo's Actions settings, and repos in the organization can reference it directly.