How do you write a composite action?
IntermediateConceptGitHub Actions
Answer
Create action.yml in a directory (for example .github/actions/setup-app/) and use it with a local path.
# .github/actions/setup-app/action.yml
name: Setup app
inputs:
node-version: { default: '22' }
runs:
using: composite
steps:
- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
cache: npm
- run: npm ci
shell: bash
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-app
Checkout must happen first for local actions to exist.
More on GitHub Actions
What are workflows, jobs, steps and actions in GitHub Actions?BeginnerWhat events can trigger a workflow?BeginnerWhat is the difference between `pull_request` and `pull_request_target`?AdvancedWhat is a runner, and how do GitHub-hosted and self-hosted runners differ?BeginnerHow do you pass data between steps and between jobs?IntermediateHow does a build matrix work?Intermediate