MSBA-300 · Lesson 9 of 12 · 21 min

Reusable workflows

▶ Video coming soon A video version of this lesson is on the way.

By the ninth clinic Tidewater had four repositories with workflows: TrailCheck, the guidebook, Malik's validator and a small repository for the trail-data importer. Each had its own copy of the same setup: check out, install Node from the lock file with caching, run lint, run tests, upload a report. When the team decided to raise the Node version, Lena changed it in four places and missed a fifth, buried in a job she had forgotten. "We are copying and pasting automation," Dmitri said. "We would never do that with code." This session was about the three ways GitHub Actions lets you share automation instead of copying it, and above all about reusable workflows.

Three ways to share

Three columns. Starter workflow or workflow template: copied into a repository once and independent after; unit is a whole file. Reusable workflow: called with workflow_call, one central version; unit is one or more jobs. Composite action: used as a step with uses, versioned like any action; unit is a group of steps.
Starter workflows, reusable workflows and composite actions share different units of automation.

The GH-200 outline asks you to tell these three apart, because they solve different problems and exam questions often describe a need and ask which to use.

A starter workflow, also called a workflow template, is a file that people copy into a repository when they create a new workflow from the Actions tab. GitHub offers public templates for common languages and deployments, and an organization can publish its own in its .github repository, including, since September 2025, templates that are not public. A template is a starting point: once copied, the new workflow is independent, so later improvements to the template do not reach copies already made.

A reusable workflow is a workflow file that other workflows call as a job. It lives in one place, is versioned like code, and every caller runs the current version of the ref it names. Change it once and every caller that tracks that ref picks up the change on its next run. The unit of reuse is one or more whole jobs, including their runners.

A composite action packages a sequence of steps as an action, with inputs and outputs, used as a single step inside a job with uses. The unit of reuse is steps, and the caller decides the runner and the rest of the job. Building composite actions is the subject of the next course in the program, so here they are only compared.

Choosing a way to share automation.
QuestionStarter workflowReusable workflowComposite action
What is shared?A whole workflow file, copiedOne or more jobs, calledA group of steps, used
How is it used?Chosen when creating a workflowjobs.<id>.uses with workflow_callsteps[*].uses inside a job
Do updates reach users?No, copies are independentYes, for callers tracking that refYes, for users tracking that version
Who chooses the runner?The copied fileThe reusable workflowThe calling job
Can it use secrets?As any workflowPassed explicitly or inheritedOnly values passed as inputs or env
Shows in logs asA normal workflowNested jobs under the calling jobOne step with expandable sub-steps

Making a workflow reusable

A workflow becomes reusable when its on key includes workflow_call. Under workflow_call you declare what the workflow accepts and returns: inputs, with a type of string, number or boolean, a description, a required flag and a default; secrets, which must be passed by the caller; and outputs, mapped from the outputs of the reusable workflow's own jobs. Inside, the reusable workflow reads inputs from the inputs context and secrets from the secrets context exactly as any workflow does.

A reusable Node CI workflow with inputs, an optional secret and an output.
# tidewater/.github repository: .github/workflows/node-ci.yml
name: Node CI

on:
  workflow_call:
    inputs:
      node-version:
        type: string
        default: "24"
      working-directory:
        type: string
        default: "."
    secrets:
      registry_token:
        required: false
    outputs:
      report-name:
        description: Name of the uploaded test report
        value: ${{ jobs.test.outputs.report }}

jobs:
  test:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    outputs:
      report: ${{ steps.name.outputs.report }}
    defaults:
      run:
        working-directory: ${{ inputs.working-directory }}
    steps:
      - uses: actions/checkout@v5
      - uses: actions/setup-node@v5
        with:
          node-version: ${{ inputs.node-version }}
          cache: npm
      - run: npm ci && npm run lint && npm test
        env:
          NPM_TOKEN: ${{ secrets.registry_token }}
      - id: name
        run: echo "report=test-report-$GITHUB_RUN_ID" >> "$GITHUB_OUTPUT"
      - uses: actions/upload-artifact@v7
        with:
          name: ${{ steps.name.outputs.report }}
          path: ${{ inputs.working-directory }}/reports/

The reusable workflow can be in the same repository as the caller, in another repository of the organization, or in a public repository. For a private or internal repository to be callable from other repositories, its Actions settings must allow access from repositories in the organization or enterprise; otherwise only workflows in the same repository can call it.

Calling a reusable workflow

A caller uses a reusable workflow as a whole job. Instead of runs-on and steps, the job has uses, pointing at the workflow file, plus with for inputs and secrets for secrets. A workflow in another repository is referenced as the owner, the repository, the path to the file and a ref after an at sign: a tag, a branch or a full commit SHA. A workflow in the same repository is referenced with a relative path starting with ./.github/workflows, and then always comes from the same commit as the caller.

Calling a shared workflow by tag with inherited secrets, reading its output, and calling a local workflow.
# trailcheck repository: .github/workflows/check.yml
name: Check
on:
  pull_request:
    branches: [main]

jobs:
  node:
    uses: tidewater/.github/.github/workflows/node-ci.yml@v2
    with:
      node-version: "24"
      working-directory: site
    secrets: inherit

  summarize:
    needs: node
    runs-on: ubuntu-latest
    steps:
      - run: echo "Report is ${{ needs.node.outputs.report-name }}"

  local-example:
    uses: ./.github/workflows/deploy.yml
    with:
      environment: staging

Secrets can be passed one by one under secrets, mapping each name the reusable workflow declares to a value from the caller, or all at once with secrets: inherit, which passes every secret the caller can see to a reusable workflow in the same organization or enterprise. Inheriting is convenient but broad; passing secrets explicitly documents exactly what the reusable workflow receives. Environment variables set with env in the caller do not pass into the reusable workflow at all, which surprises people: use inputs for anything the reusable workflow needs. Outputs flow the other way, through the needs context, as summarize shows.

Permissions and the token

The GITHUB_TOKEN permissions of a called workflow can only stay the same as the caller's or be reduced, never raised. If the caller grants contents read only, a reusable workflow that tries to push a commit will fail, however its own permissions block is written. That rule keeps a shared workflow from quietly gaining more power than the repository that calls it granted. When a reusable workflow needs a permission, document it, and have callers grant it at the job that calls the workflow.

Matrices and nesting

A calling job can use a matrix strategy, running the reusable workflow once per combination with matrix values passed as inputs, which is how Tidewater ran the same Node CI against its four repositories' folders in a monorepo experiment. Reusable workflows can also call other reusable workflows. Since November 2025 a run can nest reusable workflows up to ten levels deep and call up to fifty reusable workflows in total, counting every distinct call in the tree; the old limits were four levels and twenty workflows. Deep nesting is rarely a good idea, because each level hides detail from the person reading the caller.

One reusable workflow called three times through a matrix.
jobs:
  ci:
    strategy:
      fail-fast: false
      matrix:
        folder: [site, validator, importer]
    uses: tidewater/.github/.github/workflows/node-ci.yml@v2
    with:
      working-directory: ${{ matrix.folder }}

Versioning shared workflows

Callers choose how much change they accept through the ref they name. A full commit SHA never changes, which is the safest and the most work to update. A tag such as v2 is the usual compromise: the team that owns the workflow moves the v2 tag forward for compatible improvements and creates v3 for breaking changes, so callers get fixes automatically and choose when to take breaking changes. A branch such as main gives callers every change immediately, good inside one team that controls both sides and risky across teams. Tidewater put its shared workflows in the organization's .github repository, tagged releases, and documented each workflow's inputs, secrets, outputs and required permissions in a README beside it.

Designing a good reusable workflow

A reusable workflow is an interface, and good interfaces are small and stable. Give every input a description and, where possible, a sensible default, so that the simplest call needs no inputs at all. Prefer a few meaningful inputs, such as a working directory and a language version, over dozens of switches that turn steps on and off; a workflow with twenty boolean inputs is several workflows pretending to be one. Declare every secret the workflow can use, mark optional ones as not required, and fail early with a clear message if a required value is missing, rather than letting a later step fail mysteriously.

Treat changes the way a library maintainer would. Adding an optional input with a default is compatible; renaming or removing an input, changing an output's meaning, or requiring a new secret is a breaking change that deserves a new major tag. Keep a changelog in the repository, and test the shared workflow itself: Tidewater added a small workflow in the .github repository that called node-ci.yml against a sample project on every pull request, so a broken change could not be tagged.

Common problems when calling reusable workflows.
Error or symptomUsual causeFix
Workflow was not found or not accessibleWrong path or ref, or the private repository does not allow accessCheck owner, repository, path and ref; allow access in the reusable repository's Actions settings
Invalid input or unexpected inputInput name misspelled or not declared under workflow_callMatch the declared input names exactly
Secret is empty inside the reusable workflowSecret not passed and secrets: inherit not usedPass it under secrets or use inherit within the organization
Step fails with a permission errorCaller granted fewer permissions than the workflow needsGrant the needed permission on the calling job
Value set in env is missingenv does not pass to called workflowsDeclare and pass an input

Organizations that want certain workflows to run in every repository, whether or not the repository calls them, can go further with rulesets that require workflows to pass before merging. That is an administrative control rather than an authoring technique, and it belongs to the enterprise management course.

What callers see in the logs

In the calling run, a job that uses a reusable workflow appears with the reusable workflow's jobs nested under it, and its check name combines the caller's job id and the reusable job's name, such as node / test. Logs, annotations and artifacts belong to the calling run, so troubleshooting does not mean hunting through another repository's Actions tab. The run summary also shows which version of the reusable workflow ran, which matters when a caller tracks a moving tag and something changed overnight.

Worked problem

Choosing the right sharing tool

Three needs come up: (a) every new repository should start with Tidewater's standard check file, after which teams adjust it freely; (b) all repositories must run the same CI jobs, updated centrally; (c) several jobs repeat the same four setup steps but run on different runners. Which tool fits each?

Show solution
  1. (a) A starting point that teams then own is a starter workflow published in the organization's .github repository.
  2. (b) Central jobs that update for every caller is a reusable workflow, called with workflow_call and versioned by tag.
  3. (c) Repeated steps inside jobs whose runners differ is a composite action.

Answer: (a) starter workflow, (b) reusable workflow, (c) composite action.

Worked problem

Choosing a ref for callers

The node-ci.yml workflow is used by four Tidewater repositories and, soon, by a partner's repository that Tidewater does not control. A change is planned that renames the input working-directory to path. How should the change be released, and which ref should each caller use?

Show solution
  1. Renaming an input breaks every caller that passes the old name, so it is a breaking change.
  2. Release it as a new major version, v3, and leave v2 where it is so existing callers keep working.
  3. Tidewater's own repositories track v3 once they update their calls; they accept compatible changes automatically after that.
  4. The partner, which does not control the shared workflow, should pin a full commit SHA and update deliberately after reviewing changes, ideally with Dependabot proposing the updates.

Answer: Release the rename as v3 and keep v2 unchanged; Tidewater repositories move to the v3 tag, and the partner pins a commit SHA and updates deliberately.

Common mistakes

  • MistakeExpecting env variables from the caller to be visible in the reusable workflow.

    InsteadPass values as inputs; env does not cross into a called workflow.

  • MistakeGiving a calling job runs-on and steps as well as uses.

    InsteadA job that calls a reusable workflow has uses, with, secrets, needs, if, strategy and permissions, but no runs-on or steps.

  • MistakeAssuming a reusable workflow can raise the token's permissions.

    InsteadCalled workflows can keep or reduce the caller's permissions, never raise them.

  • MistakeExpecting improvements to a starter workflow to update existing copies.

    InsteadStarter workflows are copied once; use a reusable workflow for central updates.

The Node version change that started the session became one line in node-ci.yml and a new v2 tag. All four repositories picked it up on their next runs, and the forgotten fifth copy no longer existed.

Summary and key terms

  • Starter workflows are copied once; reusable workflows are called as jobs; composite actions are used as steps.
  • A workflow is reusable when on includes workflow_call, which declares inputs, secrets and outputs.
  • Callers use jobs.<id>.uses with owner/repo/path@ref or a local ./.github/workflows path, plus with and secrets.
  • secrets: inherit passes all of the caller's secrets within the organization; env does not pass through.
  • Called workflows cannot raise token permissions; calling jobs can use a matrix.
  • Nesting allows up to 10 levels and 50 reusable workflows per run; version shared workflows with tags or SHAs.
Starter workflow
A workflow template copied into a repository as a starting point.
Reusable workflow
A workflow with a workflow_call trigger that other workflows call as a job.
Caller workflow
The workflow that calls a reusable workflow.
workflow_call
The trigger that makes a workflow reusable and defines its inputs, secrets and outputs.
secrets: inherit
A shortcut that passes all of the caller's secrets to a reusable workflow in the same organization or enterprise.
Composite action
An action made of several steps, used as one step in a job.
Organization .github repository
A special repository where an organization keeps workflow templates and shared files.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. How do you reference a reusable workflow in the same repository?

    Show answer

    With a relative path such as ./.github/workflows/deploy.yml in the job's uses.

  2. The reusable workflow needs a value the caller sets in env. How should it get it?

    Show answer

    Declare an input under workflow_call and pass the value with with.

  3. Why tag a shared workflow as v2 instead of having callers use main?

    Show answer

    So callers get compatible fixes while choosing when to accept breaking changes.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz