Skip to content
Latchkey

How to Factor Common Steps Into a Composite Action in GitHub Actions

A composite action bundles several repeated steps behind a single uses: reference you call from any job.

Create an action.yml with runs.using: composite and a steps: list, then replace the duplicated steps in each job with one uses: ./.github/actions/<name> line.

Steps

  • Create action.yml under .github/actions/setup.
  • Set runs.using: composite, add the steps, and declare any inputs:.
  • Give each run: step a shell:, then call the action with uses:.

action.yml

.github/actions/setup/action.yml
name: 'Project setup'
inputs:
  node-version:
    default: '20'
runs:
  using: composite
  steps:
    - uses: actions/setup-node@v4
      with:
        node-version: ${{ inputs.node-version }}
    - run: npm ci
      shell: bash

Gotchas

  • Every run: step inside a composite action must declare a shell:.
  • Reference the local action as uses: ./.github/actions/setup after a checkout.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →