Learn to refactor GitHub Actions workflows by creating reusable workflows for common deployment steps, reducing duplication and simplifying maintenance across repositories.
Use this file to discover all available pages before exploring further.
In this lesson, you’ll learn how to refactor your GitHub Actions workflows by extracting common deployment steps into a reusable workflow. This approach reduces duplication, ensures consistency, and simplifies maintenance across multiple repositories.
1.1 The “Solar System” Workflow: Before Refactoring
Imagine you have a single workflow handling everything from testing to deploying in both development and production. The deployment steps for dev-deploy and prod-deploy are identical—this is a maintenance headache:
Contains a single reuse-deploy job that checks out the code, configures kubectl, replaces tokens, creates secrets, deploys manifests, and outputs the ingress URL.
In your original workflow file (.github/workflows/solar-system.yml), replace the inline dev-deploy and prod-deploy jobs with calls to the reusable workflow:
The UI prefixes the reusable-job name under dev-deploy and prod-deploy so you can easily identify the steps executed:
If you forget to pass a required input or secret, the job will fail. For example, omitting kubeconfig will cause the Set kubeconfig step to error out:
Always verify that every input and secret listed under on.workflow_call is provided when invoking the reusable workflow.In the next lesson, we’ll cover advanced patterns for sharing secrets and artifacts across reusable workflows.