Metadata File Basics
Every custom GitHub Action requires a metadata file namedaction.yml or action.yaml. This file uses YAML syntax to describe your action’s configuration:
| Key | Required | Description |
|---|---|---|
name | Yes | A unique identifier for the action. |
description | No | A short summary of what the action does. |
author | No | The creator or maintainer of the action. |
inputs | No | Define parameters your action accepts. |
outputs | No | Expose values for downstream steps. |
runs | Yes | Specifies how the action executes (e.g., composite). |
branding | No | Marketplace icon and color settings. |
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.
${{ 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
- Inputs
cache-path: Specifies which folder to cache (defaults tonode_modules).
- Steps
- Cache npm dependencies: Uses
actions/cache@v3to store and restore the specified directory. - Install dependencies: Runs
npm installto fetch packages.
- Cache npm dependencies: Uses
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