Chapter 90: GitHub Actions Deep Dive
90.7 Reusable workflows and composite actions
Story (fictional teaching scenario). Mohammed at an Infosys-style services firm in Chennai looked after 30 repos. Each had its own copy of the same test-and-deploy YAML. A fix meant 30 pull requests. Chloe from Paris showed him two tools. A reusable workflow is a whole workflow other repos call with uses: at the job level. A composite action packs several steps into one step. He wrote each once. A fix now meant one PR.
Why
Copy-paste YAML drifts. A shared piece means one review, one fix, one version.
What
- Reusable workflow — A workflow with
on: workflow_call. Another workflow calls it as a whole job. - inputs / secrets — Values the caller passes in.
- Composite action — An
action.ymlwithruns: using: composite. It bundles steps into one step. - Version pin — Call shared code by a tag like
@v1so changes roll out on purpose.
How
- Put shared logic in a central repo inside your organisation.
- For whole jobs, write a reusable workflow with
workflow_call. - For a few repeated steps, write a composite action.
- Callers pin a tag, such as
@v1.
Example 1: Reusable workflow and its caller
# shared repo: .github/workflows/node-test.yml
on:
workflow_call:
inputs:
node:
type: string
default: "24"
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: ${{ inputs.node }}
- run: npm ci && npm test
# caller repo
jobs:
ci:
uses: shop-org/ci-templates/.github/workflows/node-test.yml@v1
with:
node: "24"
Output (illustrative) (caller run summary)
ci / test ✓ 54s
What it shows: The caller has four lines. The real work lives in one shared file. The org and repo names are examples.
Example 2: Composite action for a repeated setup
# .github/actions/setup-app/action.yml
name: setup-app
runs:
using: composite
steps:
- uses: actions/setup-python@v7
with:
python-version: "3.12"
- run: pip install -r requirements.txt
shell: bash
# used inside any job
- uses: ./.github/actions/setup-app
Output (illustrative)
Run ./.github/actions/setup-app
Successfully installed fastapi-0.x pytest-8.x
What it shows: Two steps became one line. In composite actions every run: needs shell:.
Ravindra Bagale's Tip
Reusable workflow = share whole jobs. Composite action = share a few steps. Pin both with a tag.
Reusable workflow = पूर्ण jobs share करा. Composite action = काही steps share करा. दोन्ही tag ने pin करा.
Reusable workflow = पूरे jobs share करो. Composite action = कुछ steps share करो. दोनों को tag से pin करो.
Quick quiz
Q1. Which trigger makes a workflow reusable?
on: workflow_call.
Q2. Where do you call a reusable workflow?
At the job level with uses:, not as a step.
Q3. What must every run: in a composite action have?
A shell: value.
Did you understand? Let us try it once more.