Ravindra BagaleCourses & study guides मराठी

Chapter 90: GitHub Actions Deep Dive

DevOps

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.

One shared workflow or composite action, called by many repos, so one fix updates all.
One shared workflow or composite action, called by many repos, so one fix updates all.

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.yml with runs: using: composite. It bundles steps into one step.
  • Version pin — Call shared code by a tag like @v1 so changes roll out on purpose.

How

  1. Put shared logic in a central repo inside your organisation.
  2. For whole jobs, write a reusable workflow with workflow_call.
  3. For a few repeated steps, write a composite action.
  4. 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.

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.