Sub topic 18
Reusable Workflows and Debugging Failed Runs
This chapter assumes you can read a workflow file, know how jobs, steps, and needs fit together, and have seen secrets and job outputs. It covers two topics: sharing logic between workflows, and finding out why a run failed.
Reusable workflows
A reusable workflow is an ordinary workflow file that declares the workflow_call trigger. Other workflows call it at the job level, so it runs as a job in the caller's run. This removes copy-pasted build logic from many repositories or files.
The called workflow declares the inputs it accepts. The caller passes values with with.
# .github/workflows/build.yml (the called workflow)
name: Build
on:
workflow_call:
inputs:
node-version:
type: string
default: '20'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
- run: npm ci && npm run build# .github/workflows/ci.yml (the caller)
name: CI
on:
pull_request:
jobs:
call-build:
uses: ./.github/workflows/build.yml
with:
node-version: '20'Key points:
- The caller uses
uses:on the job, not on a step. A job that calls a workflow cannot also havestepsorruns-on. - A local file is referenced as
./.github/workflows/build.yml. A file in another repository is referenced asowner/repo/.github/workflows/build.yml@ref. - Inputs need a
type(string,number, orboolean). Usedefaultto make an input optional. - Secrets are not inherited automatically. Declare them under
on.workflow_call.secretsand pass them withsecrets:, or usesecrets: inheritto pass all of them. - To return data, declare
on.workflow_call.outputs. Each one maps to a job output in the called workflow. The caller reads it asneeds.call-build.outputs.<name>.
Reading logs and debugging failed runs
Open the run from the Actions tab. The run page shows each job with a status icon. Click the failed job, and the failed step is expanded with a red mark. Read from the first error upward. The last lines often only report that the step exited with a non-zero code.
Check these common causes in order:
- YAML or expression errors. The run fails at startup, with no jobs. The annotation at the top of the run page names the line.
- A skipped job. A job with an
ifthat evaluated to false, or aneedsjob that failed, shows as skipped. Look at the upstream job. - Missing values. An empty secret or output expands to an empty string with no error. Print non-secret values to confirm them.
- Wrong path or working directory. Run
pwdandls -Rin a step.
You can print a context to see what the runner received:
steps:
- name: Dump event context
env:
EVENT: ${{ toJSON(github.event) }}
run: echo "$EVENT"Never dump secrets or a full env. Secrets are masked in logs, but a transformed value, such as a base64 copy, may not be.
Debug logging
Set the repository secret or variable ACTIONS_STEP_DEBUG to true for extra step-level messages. ACTIONS_RUNNER_DEBUG adds runner diagnostics. You can also use Re-run jobs and tick Enable debug logging without editing any settings. Re-running only the failed jobs saves time. Debug logs are noisy, so turn them off when you finish.
Exercise
A caller workflow passes node-version: '22' to a reusable workflow, but the called job still installs Node 20. The called file contains node-version: 20 hard-coded in its setup-node step. What is the fix?
Show answer
Change the called workflow's setup-node step to use node-version: ${{ inputs.node-version }}. The input is declared and passed, but nothing reads it until the step references the inputs context.
Exercise
A deploy job shows as skipped, and nothing in its own log explains why. Where do you look first?
Show answer
Look at the job it lists in needs, and at the job's own if condition. A failed or skipped upstream job, or an if that evaluated to false, causes a skip.