🎓 A1Learner
🔍
0 of 50 lessons completed

GitHub Actions: Composite Actions

A composite action is a small action made from several steps in one file. It bundles repeated steps so a workflow can call them with one line.

The pain first: the same greeting steps in every workflow

Every workflow prints the same two lines. Each copy can drift apart.

- run: echo "Hello from CI"
- run: echo "Tests start now"

The composite action file

This file lives at .github/actions/hello/action.yml. It takes one input, a name.

name: Hello

description: Print a greeting

inputs:
  name:
    description: 'Name to greet'
    required: true

runs:
  using: composite
  steps:
    - run: echo "Hello, ${{ inputs.name }}!"
      shell: bash

Call it with one line

The workflow passes a name. The action prints the greeting.

- uses: ./.github/actions/hello
  with:
    name: A1Learner

Example

name: Use Composite Action

on: push

jobs:
  greet:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: ./.github/actions/hello
        with:
          name: A1Learner
      - uses: actions/setup-node@v7
        with:
          node-version: '24'
      - run: npm test

Key points

  • Composite action: a home-made action built from steps, not code.
  • Use runs with using composite to mark the file as a composite action.
  • Use inputs to pass values into a composite action.
  • Use uses with a local path to call a composite action from a workflow.
  • A reusable workflow shares whole jobs, while a composite action shares steps.
  • A composite action is a bundle of steps that a workflow calls by name.

In this example, the workflow runs on every push. It checks out the code. It calls the local hello action with the name A1Learner. The action prints the greeting. The workflow then sets up Node 24. It runs npm test. The tests pass.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

When should a composite action be used?