GitHub Actions Workflow for Reusable Workflow
Define CI once and call it from many repos or workflows.
This is a reusable workflow triggered by workflow_call, plus a caller that passes inputs and secrets.
The workflow
.github/workflows/reusable-ci.yml
name: Reusable CI
on:
workflow_call:
inputs:
node-version:
type: string
default: '20'
secrets:
NPM_TOKEN:
required: false
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: ${{ inputs.node-version }}, cache: npm }
- run: npm ci
- run: npm test
---
# .github/workflows/ci.yml (caller)
name: CI
on: [push]
jobs:
call:
uses: ./.github/workflows/reusable-ci.yml
with:
node-version: '22'
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}Notes
- The reusable file declares
on: workflow_callwith typed inputs and secrets. - Callers reference it by path with
uses:and passwith:/secrets:. - Centralizes CI logic so updates propagate to all callers.
Run it cheaper
Point runs-on: at a Latchkey label to run this workflow at roughly 69% lower per-minute cost, with self-healing for transient failures.
Related guides
How to Use Matrix Builds in GitHub ActionsUse GitHub Actions matrix builds to test across versions and OSes in parallel - strategy.matrix, include/excl…
How to Speed Up GitHub Actions: 9 High-Impact TacticsMake GitHub Actions faster: caching, parallelization, test splitting, Docker layer caching, slimmer images, a…