Sub topic 1
Composite actions, other action types and reusable workflows
Prerequisites
This chapter assumes basic GitHub Actions workflow syntax, YAML, Bash, Git repositories, and tags.
Choosing the right reusable unit
A composite action packages several workflow steps behind one uses step. It is useful for repeated setup, checks, or scripts that should run inside the caller's job.
A JavaScript action runs bundled JavaScript in the runner. A Docker container action runs its code inside a container. A reusable workflow packages complete jobs, including runners, permissions, matrices, and job dependencies.
| Tool | Packages | Best fit |
|---|---|---|
| Composite action | Steps | Shared job logic |
| JavaScript action | Program code | Cross-platform action logic |
| Docker action | Container and code | Fixed Linux environment |
| Reusable workflow | Jobs | A complete CI process |
Anatomy of `action.yml`
The action.yml file describes the action. Its main fields are name, description, inputs, outputs, and runs. A composite action sets runs.using to composite and lists its ordered steps.
name: Greet
description: Build a greeting
inputs:
who-to-greet:
description: Name to greet
required: false
default: World
outputs:
greeting:
description: The generated greeting
value: ${{ steps.build.outputs.greeting }}
runs:
using: composite
steps:
- id: build
shell: bash
env:
WHO: ${{ inputs.who-to-greet }}
run: echo "greeting=Hello, ${WHO}" >> "$GITHUB_OUTPUT"The id lets another expression refer to a step. Writing name=value to the GITHUB_OUTPUT file creates a step output. The action output then maps to that step output.
Defining composite steps
Each item under runs.steps can use run or call another action with uses. A composite action can therefore combine shell commands with actions such as actions/setup-node.
Every run step must specify a shell, such as bash, pwsh, or python. Unlike a workflow job, a composite action does not inherit a default shell for these steps. Omitting it causes metadata validation to fail.
Exercise
Which field makes an action a composite action, and what does every run step need?
Show answer
Set runs.using to composite; every run step needs an explicit shell.