Skip to main content
In this tutorial, you’ll learn how to package common CI/CD steps—caching and installing NPM dependencies—into a reusable composite GitHub Action. By extracting these steps, you reduce duplication across jobs and maintain a single source of truth.

Table of Contents

Action Metadata Overview

Every custom GitHub Action requires a metadata file (action.yml or action.yaml). At minimum, include:
  • name: Visual identifier
  • description: Short summary
  • inputs/outputs (optional): Dynamic parameters
  • runs: Runtime configuration
Composite actions let you chain multiple uses: and run: steps, apply if conditions, and even define pre/post scripts. They don’t require separate Docker or Node environments.
Optionally, add branding for the GitHub Marketplace:

Use Case: Caching & Installing Dependencies

Imagine a CI workflow with two jobs—Unit Testing and Code Coverage—both executing:
  1. Checkout repository
  2. Set up Node.js
  3. Cache NPM dependencies
  4. Install dependencies
Steps 3 and 4 are identical in both jobs. Extracting them into a composite Action improves maintainability.

Sample Workflow Before Refactoring

The Code Coverage job repeats the same cache and install steps. Let’s extract them next.

Defining the Composite Action

  1. Create a directory for custom actions:
  2. Populate action.yml:
  • Inputs
    • cache-folder: Makes the cache path configurable.
  • Steps
    • Reproduce the original cache and install commands.
Composite actions currently do not support Docker-level isolation. All steps run in the same default environment.

Using Your Composite Action

Update your workflow jobs to replace separate cache and install steps with one uses: entry:
Repeat the same uses: step in Code Coverage or any other job. Now both jobs share a single, maintainable action.

Watch Video