Script Valley
CI/CD with GitHub Actions
Advanced Workflow PatternsLesson 5.2

How to write a composite action in GitHub Actions

action.yml, composite action type, using: composite, steps in action.yml, inputs in composite, calling local action, action outputs, composite vs reusable workflow

Composite Actions vs Reusable Workflows

Composite action vs reusable workflow scope

Composite actions bundle multiple steps into a single reusable step. They run within a job, unlike reusable workflows which define entire jobs. Use composite actions for setup sequences; use reusable workflows for full pipelines.

Creating a Composite Action

# .github/actions/setup-app/action.yml
name: 'Setup Application'
description: 'Checks out code, sets up Node, and installs deps'
inputs:
  node-version:
    description: 'Node.js version'
    default: '20'

runs:
  using: 'composite'
  steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-node@v4
      with:
        node-version: ${{ inputs.node-version }}
        cache: 'npm'
    - run: npm ci
      shell: bash

Using the Composite Action

steps:
  - uses: ./.github/actions/setup-app
    with:
      node-version: '20'

  - run: npm test

The using: composite key is required. Every run step inside a composite action must have a shell key. The action lives in .github/actions/ and is referenced with a relative path.

Up next

How to use conditional logic with if expressions in GitHub Actions

Sign in to track progress