Maven / 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>.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
