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.ymlunder.github/actions/setup. - Set
runs.using: composite, add the steps, and declare anyinputs:. - Give each
run:step ashell:, then call the action withuses:.
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: bashGotchas
- Every
run:step inside a composite action must declare ashell:. - Reference the local action as
uses: ./.github/actions/setupafter a checkout.
Related guides
How to Share a Script Across Jobs in GitHub ActionsReuse the same script in multiple GitHub Actions jobs by committing it once and checking out the repo in each…
How to Run a pre-commit Check Script in GitHub ActionsEnforce the same pre-commit hooks in GitHub Actions that developers run locally by installing pre-commit and…