Course contentsShow
← Cloud and Infrastructure
Lesson 1716 of 2,98935. GitHub ActionsFree lesson

Workflow Templates and Reusable Workflows

Define reusable workflows that can be called from other workflows, reducing duplication across repositories.

Workflow Templates and Reusable Workflows

What you'll learn: How to define reusable workflows that can be called from other workflows, eliminating duplication across your repositories.


The Problem: Workflow Duplication

Imagine you have ten microservices, each needing the same CI pipeline: checkout code, run tests, build, and push artifacts. Copy-pasting the same workflow file across repositories creates maintenance nightmares—when you need to update the process, you must touch ten files.

Reusable Workflows: The Solution

Reusable workflows let you define a workflow once and call it from other workflows like a function. The "caller" workflow invokes the "called" workflow using the workflow_call trigger, passing inputs and secrets as needed.

Think of it like creating a recipe template: instead of writing cooking instructions ten times, you reference the master recipe and just provide different ingredients each time.

How It Works

The called workflow lives in .github/workflows/ and uses on: workflow_call as its trigger. It can define inputs (parameters) and outputs (return values).

The caller workflow uses the uses keyword in a job to reference the reusable workflow by repository path and file name, like owner/repo/.github/workflows/reusable.yml@main.

Benefits

  • DRY principle: Define logic once, use everywhere
  • Centralized updates: Fix or improve in one place
  • Consistency: Ensures all repos follow the same standards
  • Secrets passing: Securely share secrets without exposing them
  • Versioning: Pin to specific refs (tags/commits) for stability

Key Takeaway: Reusable workflows transform GitHub Actions from scattered YAML files into composable, maintainable pipeline components—reducing duplication and centralizing your CI/CD logic across all repositories.