Sub topic 2
Anatomy of action.yml
This chapter assumes you can write a basic workflow with jobs, steps, uses and run, and that you are comfortable with YAML. It also assumes you know what a Git tag is. The chapter covers the metadata file that defines every action. The next chapters go deeper into composite steps, inputs and outputs.
What the metadata file is
Every action is defined by a metadata file named action.yml (or action.yaml). The file sits in the action's own directory, not in .github/workflows. GitHub reads it when a workflow step says uses: <something>. It tells the runner what the action is called, what it accepts, what it returns, and how to execute it.
The same file format describes all three kinds of actions: composite, JavaScript and Docker container. The runs key is the only part that changes. Reusable workflows are a different mechanism. They are ordinary workflow files with on: workflow_call, and they have no action.yml.
The top-level keys
| Key | Required | Purpose |
|---|---|---|
| `name` | Yes | Display name of the action. Shown in the workflow UI and on the Marketplace. |
| `description` | Yes | One-line summary of what the action does. |
| `author` | No | Name of the author or organization. |
| `inputs` | No | Values the caller can pass with `with:`. |
| `outputs` | No | Values the caller can read after the step runs. |
| `runs` | Yes | How the action executes. For this tutorial, `using: composite` plus `steps`. |
| `branding` | No | An icon and color used on the Marketplace page. |
Leaving out a required key makes the action fail to load. The runner reports an error such as a missing description or runs, and the job stops at the step that uses the action.
A complete example
The file below uses every key. It installs a tool version and reports it back.
name: Print tool version
description: Print the version of a command-line tool and expose it as an output
author: Example Team
branding:
icon: terminal
color: blue
inputs:
tool:
description: Command to inspect
required: false
default: git
outputs:
version:
description: First line of the tool's version output
value: ${{ steps.probe.outputs.version }}
runs:
using: composite
steps:
- id: probe
shell: bash
env:
TOOL: ${{ inputs.tool }}
run: echo "version=$("$TOOL" --version | head -n 1)" >> "$GITHUB_OUTPUT"Read it from top to bottom as three groups. The first group is identity: name, description, author and branding. The second is the interface: inputs and outputs. The third is behavior: runs.
How the pieces connect
Identity keys never affect execution. The data path always goes through the interface: the caller supplies inputs, the steps under runs consume them, and outputs publish results.
Identity keys
name and description are plain strings. They have no effect on how the action runs. name appears in the job log as the step title when the caller does not set its own name: on the step.
branding takes an icon (a name from the Feather icon set that GitHub supports) and a color. These only matter if you publish to the Marketplace. An unsupported icon or color name is not accepted for publishing, so check the current list in the GitHub documentation before choosing one.
The inputs block
Each entry under inputs is keyed by an input id. An id must start with a letter or _ and contain only letters, digits, - or _. Each input accepts these fields:
description: required text explaining the input.required:trueorfalse. A caller who omits a required input gets no automatic error for composite actions in every case, so do not rely on it for validation. Validate inside a step when the value matters.default: the value used when the caller omits the input.deprecationMessage: a warning shown when a caller still passes the input.
Inputs are always strings, even when you write default: true or default: 20. Quote numeric defaults so the YAML matches what the action actually receives, as in default: "20". Comparisons later in the action must then use strings, such as inputs.run-tests == 'true'.
The outputs block
Each entry under outputs has a description and, for composite actions, a value. The value is an expression that points at a step output, as in ${{ steps.probe.outputs.version }}. Without value, a composite action exposes nothing, because there is no code that sets the output directly. The step that produces the data needs an id, and the id in the expression must match it exactly.
The runs block
For a composite action, runs needs two things:
using: composite- A
stepslist.
Each step may have id, name, if, env, with, run, uses and shell, among others. Every run step must have a shell. That rule is the subject of a later chapter. A missing shell is the most common reason a new composite action fails validation.
Expressions you can use in the file
Expressions inside action.yml run in a limited scope. You can use the inputs, steps, github and runner contexts. The secrets context is not available inside a composite action, so a secret has to arrive as an input. Another chapter covers that pattern.
Where the file lives and how callers find it
The location of action.yml determines the uses string the caller writes.
| Location | Caller writes |
|---|---|
| `.github/actions/greet/action.yml` in the same repository | `uses: ./.github/actions/greet` |
| `action.yml` at the root of `octo-org/tools` | `uses: octo-org/tools@v1` |
| `actions/lint/action.yml` in `octo-org/tools` | `uses: octo-org/tools/actions/lint@v1` |
Three rules follow from this table:
- The
usesvalue points at the directory, never at the file. - A local path starts with
./and is relative to the workspace. The repository must already be checked out, so the job needsactions/checkoutbefore the step. - Each directory holds one action. To have several actions in one repository, give each its own subdirectory with its own
action.yml.
Publishing to the Marketplace requires the file at the repository root, which means one action per published repository.
Common mistakes
- Wrong file name or location.
Action.yml,action.yaml.txtor a file one directory too deep makes the runner report that it cannot find the action metadata file. File names are case-sensitive on Linux runners. - No checkout before a local action. The path does not exist on a fresh runner until the repository is checked out.
- Output without a matching step id. The expression resolves to an empty string, and nothing warns you.
- Unquoted numeric defaults.
default: 20.10loses its trailing zero when YAML parses it as a number, so the action receives20.1. - Missing
descriptionon an input or output. Validation rejects it.
Exercise
A repository octo-org/tools has action.yml at its root. A teammate adds a second action in actions/lint/ and writes uses: octo-org/tools/actions/lint/action.yml@v1. The job fails. What is wrong, and what is the correct uses value?
Show answer
uses must point at the directory that contains the metadata file, not at the file itself. The correct value is octo-org/tools/actions/lint@v1.
Exercise
An action declares outputs.version.value: ${{ steps.probe.outputs.version }}, but the callers always read an empty string. The step that writes the output is defined as - shell: bash followed by a run: line that appends version=1.2.3 to $GITHUB_OUTPUT. What should you change?
Show answer
Add id: probe to that step. The expression looks up the step by id, so a step without an id produces nothing for it to read.