Sub topic 2
Anatomy of action.yml
This chapter covers the metadata file that defines every action. It assumes you know basic workflow syntax (jobs, steps, uses, run), can read YAML, and can write simple bash. The chapter before this one compared composite actions with JavaScript actions, Docker container actions and reusable workflows. Here we look at the file itself.
What action.yml is
Every action has a metadata file named action.yml (or action.yaml) at the root of the action's directory. GitHub reads it to learn what the action is called, what it accepts, what it returns, and how to run it. The file name is fixed. A different name means the action is not found.
For a local action, the directory is usually under .github/actions/<name>/. For a shared action, the file sits at the root of its own repository.
Top-level keys
| Key | Required | Purpose |
|---|---|---|
| `name` | Yes | Display name of the action |
| `description` | Yes | Short summary of what it does |
| `author` | No | Who maintains it |
| `inputs` | No | Values the caller can pass in |
| `outputs` | No | Values the action returns to the caller |
| `runs` | Yes | How the action executes |
| `branding` | No | Icon and color for the Marketplace listing |
Only name, description and runs are mandatory. The other keys describe the action's interface. Keep description specific, because it appears in the Marketplace and in editor hints.
A complete example
name: Greet
description: Build a greeting and expose it as an output
inputs:
who-to-greet:
description: Name to greet
required: false
default: World
outputs:
greeting:
description: The greeting text
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 file has three parts: an interface (inputs and outputs), an implementation (runs), and identity (name and description).
How the sections relate
Callers supply values with with:. The inputs section declares which names are valid and what defaults apply. Steps under runs read those values through the inputs context. The outputs section then maps a step's output to a named result that the caller can read.
The runs block
The runs key tells GitHub which kind of action this is. For a composite action you set using: composite and list steps. A JavaScript action would set using to a Node version, and a Docker action would set using: docker. That one value decides which other keys are allowed. A composite action has steps, while a JavaScript action has main.
Common errors
- File in the wrong place. If
action.ymlis not at the root of the path you pass touses, the workflow fails with a "Can't find action.yml" error. - Missing
description. The file is rejected becausedescriptionis required on the action and on each declared input and output. - Output
valuepointing at nothing. Thevalueexpression must name a real stepid. A typo gives an empty string and no error. - Treating
required: trueas enforced. For inputs,requiredis documentation. A missing input becomes an empty string rather than failing the run.
Exercise
Which three top-level keys are mandatory in an action.yml, and what does runs.using decide?
Show answer
name, description and runs are mandatory. runs.using selects the action type (composite, docker, or a Node version for JavaScript), which determines the other keys allowed under runs, such as steps for composite actions.
Exercise
An action declares an output greeting with value: ${{ steps.bulid.outputs.greeting }}, but the step's id is build. What does the caller receive, and why?
Show answer
An empty string. The expression refers to a step id that does not exist, and GitHub evaluates it to an empty string instead of raising an error.