Skip to main content
GitHub Actions lets you reuse common CI/CD logic across multiple workflows and repositories. Instead of duplicating identical deployment steps in both dev-deploy and prod-deploy, extract them into a single reusable workflow.

Why Avoid Duplication?

A typical “Solar System Workflow” might look like this:
Maintaining nearly identical steps in dev-deploy and prod-deploy quickly becomes error-prone. Use reusable workflows to centralize your logic.
See the official documentation for an overview of reusing workflows in GitHub Actions.
The image shows a GitHub Docs page about GitHub Actions, specifically focusing on the limitations of reusing workflows. It includes a navigation menu on the left and a list of related topics on the right.

1. Create the Reusable Workflow

  1. File location: .github/workflows/reuse-deployment.yml
  2. Trigger: replace on: workflow_dispatch with on: workflow_call.
  3. Inputs: declare kubeconfig as a required string.

Full Workflow Definition


2. Call the Reusable Workflow

Replace the inline dev-deploy and prod-deploy jobs in your main pipeline:
The image shows a GitHub Actions workflow interface with a series of jobs and their statuses, including unit testing, code coverage, and deployment steps. The workflow is titled "modified path of reusable workflow" and is currently in a waiting status.

3. Troubleshoot Missing Inputs

If your pipeline fails with:
it indicates that the caller did not pass the required kubeconfig input.
The image shows a GitHub Actions workflow with a failed job in the "dev-deploy" stage due to a missing "kubeconfig" input. Other stages like unit testing and code coverage are marked as successful.
Always pass all required inputs when calling a reusable workflow:

References

Watch Video