Sample CI Workflow for a Node.js App
Here’s an example.github/workflows/ci-testing.yml that runs tests, coverage, dependency scanning, build, and deployments in sequence:
Copy-pasting deployment steps across multiple workflows leads to fragmented updates and higher maintenance costs. A single change requires edits in every file.
Why Use Reusable Workflows?
A reusable workflow is a YAML file that other workflows can invoke viaworkflow_call. Benefits include:
Example Repository Layout
Assume the following structure in yourXYZ/nodejs-app-repo:
.github/workflows/awesome-app.yaml.github/workflows/reusable-workflow.yaml
Original Workflow: awesome-app.yaml
This caller workflow builds the app, runs tests, and then invokes the reusable deployment job:Reusable Workflow: reusable-workflow.yaml
By declaringon.workflow_call, you expose inputs, secrets, and jobs that any caller workflow can use:
Invoking the Reusable Workflow
You can call this reusable workflow from any repository or branch:Inputs and secrets are strongly typed. Ensure that every
workflow_call declaration and invocation matches the expected names and types.Key Terminology
- Caller workflow: The YAML file that uses
uses:to invoke a reusable workflow. - Called workflow: The reusable workflow that declares
on.workflow_call.
Links and References
- GitHub Actions: Reusing workflows
- GitHub Actions: Workflow syntax
- actions/checkout
- actions/setup-node