Reusable workflows and composite actions

Intermediate · 5 min

Stop copying the same YAML between repositories: share whole jobs with reusable workflows, share a few steps with composite actions, and know which one to pick.

Before thisWorkflows, triggers, jobs and stepsSecrets, variables and contextsCaching, artifacts and matrix builds

CoderDave · 5 min

Reusable workflows and composite actions

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by CoderDaveReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • A reusable workflow is a whole workflow that other workflows call as a job, declared with on: workflow_call and called with jobs.<id>.uses.
  • A composite action bundles several steps into one step, defined in an action.yml with runs: using: composite, and called with uses: like any action.
  • Reuse a workflow to share entire jobs, including runner choice and secrets, and reuse a composite action to share a sequence of steps inside a job.
  • Inputs, secrets and outputs are explicit contracts, and secrets reach only the directly called workflow unless you pass them on.
  • Pin a shared workflow or action to a tag or commit SHA, because everyone who calls it changes behaviour when it changes.

Copy and paste is a maintenance bill

The notes project’s CI works. Then you start a second project, and copy ci.yml into it. Then a third. Six months later you want to change the Node versions you test, or add a security step, and you have to edit it in every repository. Some will be forgotten, and those copies drift.

This is the same problem as duplicated code in any program, and the fix is the same: put the shared part in one place and call it. GitHub Actions has two mechanisms, and they work at different sizes.

Reusable workflows: share whole jobs

A reusable workflow is an ordinary workflow file that declares it can be called. Its trigger is workflow_call:

# .github/workflows/node-ci.yml
name: Node CI

on:
  workflow_call:
    inputs:
      node-version:
        description: Node.js version to test with
        required: false
        type: string
        default: "24"
    outputs:
      build-ok:
        description: Whether the build step ran
        value: ${{ jobs.test.outputs.build-ok }}

permissions:
  contents: read

jobs:
  test:
    runs-on: ubuntu-latest
    outputs:
      build-ok: ${{ steps.build.outputs.ok }}
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: ${{ inputs.node-version }}
          cache: npm
      - run: npm ci
      - run: npm test
      - id: build
        run: |
          npm run build
          echo "ok=true" >> "$GITHUB_OUTPUT"

And another workflow calls it as a job, using uses: at the job level, not inside steps:

# .github/workflows/ci.yml
name: CI

on:
  pull_request:
  push:
    branches: [main]

jobs:
  node-24:
    uses: ./.github/workflows/node-ci.yml
    with:
      node-version: "24"

  node-26:
    uses: ./.github/workflows/node-ci.yml
    with:
      node-version: "26"

  report:
    needs: [node-24, node-26]
    runs-on: ubuntu-latest
    steps:
      - run: echo "build ok = ${{ needs.node-24.outputs.build-ok }}"

I loaded both files with a YAML parser, so the syntax is valid. I could not run them, because they need a repository on GitHub, so I have not seen the runs. The shapes follow GitHub’s “Reuse workflows” page, which I read on 2026-11-23.

What matters in the contract:

  • Where it lives. The called file must be in .github/workflows, and the docs say subdirectories there are not supported.
  • How to reference it. ./.github/workflows/node-ci.yml for the same repository. For another repository: owner/repo/.github/workflows/node-ci.yml@ref, where the ref can be a SHA, tag or branch. The docs call a commit SHA the safest.
  • Inputs, secrets, outputs. Inputs are typed (string, number or boolean). Secrets are declared under on.workflow_call.secrets. Outputs map from a step, to a job, to the workflow, as above.
  • Secrets are not automatic. They reach only the directly called workflow. The caller passes them with secrets:, or uses secrets: inherit to pass all of them within the same organization. If A calls B and B calls C, C only gets A’s secrets if B passes them on.
  • Permissions can only shrink. In a chain of nested calls, permissions can stay the same or be reduced, never increased.
  • Limits. You can nest up to ten levels, counting the top-level caller, and loops are not allowed.

A common pattern is a repository holding the organization’s shared workflows. Each project then keeps a short ci.yml calling it, and changing the shared file changes them all. That also makes the shared file a high-value target, so protect it with CODEOWNERS and call it at a tag or SHA, not @main.

Composite actions: share a few steps

Sometimes you want less than a whole job. Say the same three steps, checkout, setup Node with caching and install, begin every job in several workflows. A composite action packages steps into one step.

It is a folder with an action.yml. For the notes project, .github/actions/setup-notes/action.yml:

name: Set up notes-cli
description: Install Node.js and the project's dependencies

inputs:
  node-version:
    description: Node.js version
    required: false
    default: "24"

runs:
  using: composite
  steps:
    - uses: actions/setup-node@v7
      with:
        node-version: ${{ inputs.node-version }}
        cache: npm
    - name: Install dependencies
      run: npm ci
      shell: bash

A workflow uses it like any action, with a path for one in the same repository:

steps:
  - uses: actions/checkout@v7
  - uses: ./.github/actions/setup-notes
    with:
      node-version: "26"
  - run: npm test

The docs say the workflow still needs actions/checkout first when you use a local path, because the action’s files are in the repository. I parsed both YAML files, and I also ran the commands inside the composite, npm ci then npm test, in the notes project locally, with both passing. I did not run the action on GitHub.

Notes on composite actions:

  • runs: using: composite is what makes it composite.
  • Every run step needs shell:. The GitHub docs example puts shell: bash on each one. I treat it as required for composite actions, and the docs example never omits it.
  • Inputs and outputs are declared at the top. Outputs map from a step’s output, as in the docs’ random-number example.
  • It runs inside the caller’s job, on the same runner, as one collapsed step in the log.

Choosing between them

Reusable workflow Composite action
Called with jobs.<id>.uses A step’s uses
Runs as Its own job or jobs One step in the caller’s job
Own runner Yes, set inside No, uses the caller’s
Secrets Passed explicitly Read from the caller’s job
Best for A whole pipeline, such as CI or deploy A repeated setup sequence

The rule of thumb: if you are sharing a pipeline, use a reusable workflow. If you are sharing a setup routine that sits inside a job, use a composite action. They combine well: a reusable workflow whose steps use a composite action.

Both change behaviour for everyone who calls them the moment you change them. Version them with tags, and consider Dependabot to bump callers.

What the video covers

CoderDave’s “Composite Actions VS Reusable Workflows in GitHub Actions [2023 Update]” is about five minutes and was published in 2023. Its description says it shows the difference between the two in 2023. It is the shortest and most direct comparison I found, though it is older, and GitHub has changed limits and UI since, including the nesting depth. I could not read a transcript or chapters. English is judged from the title, description and channel. It matches the comparison table above. For a longer, hands-on build of a reusable workflow, a 2025 video by Mickey Gousset is linked under deeper.

Where this fits

You can now share your CI between projects. The next lesson is about the step that most pipelines end with, deployment, and how to do it without storing a long-lived password: deploying from Actions with OIDC.

Check yourself

  1. 01What is the main difference between a reusable workflow and a composite action?

    A reusable workflow is called at the job level and runs as its own job or jobs on its own runners. A composite action is called as a step and runs inside the calling job, on its runner.

  2. 02How does a workflow become callable by other workflows?

    Its on: section includes workflow_call, optionally with typed inputs, secrets and outputs. The file lives in .github/workflows.

  3. 03Why must every run step in a composite action set shell?

    A composite action's steps are not tied to the workflow's default shell, so each run step has to say which shell to use, such as bash. The docs example sets it on every run step.

  4. 04Workflow A calls B, and B calls C. Does C receive A's secrets automatically?

    No. Secrets reach only the directly called workflow. B has to pass them to C explicitly.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark