Script Valley
CI/CD with GitHub Actions
Advanced Workflow PatternsLesson 5.1

How to create reusable workflows in GitHub Actions

workflow_call trigger, inputs, secrets: inherit, caller workflow, called workflow, reusable workflow limitations, on.workflow_call.inputs

What are Reusable Workflows?

Multiple caller workflows calling one reusable workflow

Reusable workflows let you define a workflow once and call it from other workflows — even across repositories. They eliminate duplication of complex job sequences like deployment pipelines.

Defining a Reusable Workflow

# .github/workflows/deploy.yml (reusable)
on:
  workflow_call:
    inputs:
      environment:
        required: true
        type: string
    secrets:
      DEPLOY_KEY:
        required: true

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: ${{ inputs.environment }}
    steps:
      - run: echo "Deploying to ${{ inputs.environment }}"

Calling the Reusable Workflow

# .github/workflows/ci.yml (caller)
jobs:
  call-deploy:
    uses: ./.github/workflows/deploy.yml
    with:
      environment: production
    secrets:
      DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}

A reusable workflow must use workflow_call as its trigger. The caller passes inputs via with and secrets via secrets. Use secrets: inherit in the caller to automatically forward all caller secrets without listing them individually — convenient but less explicit.

Up next

How to write a composite action in GitHub Actions

Sign in to track progress