Skip to main content
Composite actions let you encapsulate multiple workflow steps into a single, reusable GitHub Actions component. In this guide, you’ll learn how to author a composite action from scratch, define its metadata, and integrate it into your workflows.

Metadata File Basics

Every custom GitHub Action requires a metadata file named action.yml or action.yaml. This file uses YAML syntax to describe your action’s configuration:
Learn more about metadata syntax in the GitHub Actions docs.

runs Syntax for Composite Actions

To bundle multiple workflow steps, set using: "composite" under runs. You can then list any combination of uses, run, if, shell, or id fields as you would in a standard workflow.
Reference inputs with ${{ inputs.INPUT_NAME }} and step outputs with ${{ steps.STEP_ID.outputs.OUTPUT_NAME }}.

Example: npm-custom-action

Let’s create a composite action to cache and install npm dependencies. Save this file as
.github/custom-actions/npm-action/action.yml in your repository:

How It Works

  1. Inputs
    • cache-path: Specifies which folder to cache (defaults to node_modules).
  2. Steps
    • Cache npm dependencies: Uses actions/cache@v3 to store and restore the specified directory.
    • Install dependencies: Runs npm install to fetch packages.

Using the Composite Action

In your main workflow (e.g., .github/workflows/ci.yml), replace the redundant caching and install steps with your new composite action:
You can reference the composite action via its relative path (./.github/custom-actions/npm-action). Pass inputs under with: just like any other action.

Conclusion

By defining a composite action, you can centralize common steps—such as caching and installation—into a single reusable unit. This reduces duplication across workflows and simplifies maintenance. For advanced scenarios, consider adding:
  • Output parameters to pass data downstream
  • Conditional steps (if) for dynamic behavior
  • Branding options for Marketplace listings

Watch Video