DevOps / GitHub Actions Interview Questions
What are reusable workflows in GitHub Actions and how do you call them?
A reusable workflow is a standard workflow file that exposes a workflow_call trigger, making it callable from other workflows. This lets you centralise a common CI/CD pattern (e.g. build-and-push, deploy-to-kubernetes) in one place and have many repositories or workflows invoke it without copy-pasting YAML.
Defining a reusable workflow (.github/workflows/deploy-template.yml in the shared repo):
on: workflow_call: inputs: environment: required: true type: string secrets: DEPLOY_KEY: required: true jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: ./deploy.sh ${{ inputs.environment }} env: DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
Calling the reusable workflow from another workflow:
jobs: call-deploy: uses: my-org/shared-workflows/.github/workflows/deploy-template.yml@main with: environment: production secrets: DEPLOY_KEY: ${{ secrets.PROD_DEPLOY_KEY }}
Key rules to remember:
- A reusable workflow is called as a job, not a step — so it can run in parallel with or be sequenced using
needs:like any other job. - Secrets are not automatically inherited; you must explicitly pass them or use
secrets: inheritto forward all caller secrets. - A caller workflow can nest reusable workflows up to 4 levels deep.
- Outputs declared in the reusable workflow are available to the calling workflow via
needs.<job>.outputs.<name>.
More Related questions...