Skip to content
Visual explainer 3h to learn 4 steps

Reusable workflows & composite actions

Share one pipeline across many repos.

By Invicly Tech, , in Git, GitHub & GitHub Actions. About 10 minutes to read.

Topic 13 of 18

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.

CompareTwo ways to reuse
Reusable workflow
  • Triggered by workflow_call
  • Called at job level with uses
  • Can contain many jobs
  • Takes inputs and secrets
Composite action
  • runs: using: composite
  • Called as a step with uses
  • Bundles several steps
  • Runs inside the caller's job
LayersLevels of reuse, from big to small
  1. 1
    Reusable workflow

    Whole pipeline: jobs, runners, environments

  2. 2
    Job in your workflow

    Your own runs-on and steps

  3. 3
    Composite action

    A bundle of steps used as one step

  4. 4
    JavaScript or Docker action

    Custom code behind one step

  5. 5
    Shell 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.

SequenceCalling a shared workflow
Caller repo
GitHub
Shared repo
Runner
  1. 1Job uses acme/ci/...python-ci.yml@v1
    Caller repo to GitHub: Job uses acme/ci/...python-ci.yml@v1
  2. 2Load workflow file at tag v1
    GitHub to Shared repo: Load workflow file at tag v1
  3. 3Check inputs, secrets, permissions
    GitHub to GitHub: Check inputs, secrets, permissions
  4. 4Run called jobs in the caller's context
    GitHub to Runner: Run called jobs in the caller's context
  5. 5Job outputs and results
    Runner to GitHub: Job outputs and results
  6. 6Outputs available via needs
    GitHub to Caller repo: Outputs 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.

MapA shared CI repository
acme/ci
  • .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.

  1. 1
    Write a reusable workflow with workflow_call~45m
  2. 2
    Pass inputs and secrets to it~45m
  3. 3
    Build a composite action~45m
  4. 4
    Call 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

yaml
# 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.

yaml
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.

yaml
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: bash

Quick 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.

Question 1

1In a called reusable workflow, what does github.repository contain?

Question 2

2Your composite action's run step fails validation. What is the most likely cause?

Question 3

3The caller sets permissions: contents: read. The called workflow asks for contents: write. What happens?

Question 4

4You need the same three setup steps inside many existing jobs. Which tool fits best?

0/4 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Turn your repo's test job into a reusable workflow in the same repo and call it from ci.yml.

  2. Exercise 2medium

    Call the same reusable workflow for three Python versions using a matrix in the caller.

  3. 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.
ShareXLinkedInWhatsApp