Sub topic 2
Describing an action with action.yml
Every custom action has a metadata file at its root. GitHub reads it to learn what the action is called, what it accepts, what it returns, and how to run it. This chapter assumes you know basic workflow syntax (jobs, steps, uses, with) and can read YAML. Inputs and outputs get their own chapter, so here the focus is the file's structure and the runs block.
The file and where it lives
The file must be named action.yml or action.yaml. It sits in the root of the action's repository, or in a subdirectory if one repository holds several actions. When a workflow says uses: ./, the runner looks for this file in the current directory. If the file is missing or misnamed, the step fails before any of your code runs.
Top-level keys
The metadata has a small set of keys.
| Key | Required | Purpose |
|---|---|---|
| `name` | Yes | Display name shown in the workflow log and in the Marketplace |
| `description` | Yes | One-line summary of what the action does |
| `inputs` | No | Values the caller can pass with `with:` |
| `outputs` | No | Values later steps can read from `steps.<id>.outputs` |
| `runs` | Yes | Which runtime to use and which entry point to start |
| `branding` | No | Icon and color for the Marketplace listing |
The runs key decides what kind of action you have. The other keys describe the action's interface, so they look the same for every type.
A JavaScript action's metadata
This file declares one input, one output, and runs index.js on Node 20.
name: 'Hello World'
description: 'Greet someone and record the time'
inputs:
who-to-greet:
description: 'Who to greet'
required: true
default: 'World'
outputs:
time:
description: 'The time we greeted you'
runs:
using: 'node20'
main: 'index.js'In runs, using selects the runtime. main is the file the runner executes with Node. The path is relative to the action's root. The runner provides Node itself, so you do not install it.
A Docker action's metadata
For a container action, only runs changes.
name: 'Hello World (Docker)'
description: 'Greet someone from a container'
inputs:
who-to-greet:
description: 'Who to greet'
required: true
default: 'World'
outputs:
time:
description: 'The time we greeted you'
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.who-to-greet }}Here using: 'docker' tells the runner to build the image from the Dockerfile in the action's directory and start a container. Each entry in args is passed to the container's entrypoint. The expression ${{ inputs.who-to-greet }} is replaced with the caller's value before the container starts.
The two files show the pattern: the interface is shared, and runs is the part that varies.
Common errors
- Wrong file name.
Action.ymloraction.yaml.txtis not found. Use exactlyaction.ymloraction.yaml. - Missing required keys. Leaving out
name,description, orrunsmakes the metadata invalid. - Path mistakes.
mainandimageare relative to the action's root. Amainthat points to a file you did not commit fails at run time. - Mismatched names. Input names in
action.ymlmust match what your code reads. Declaringwho-to-greetbut readingnamereturns an empty string. - Unquoted expressions. In
args, a value beginning with${{is valid YAML here, but quote values elsewhere if they contain characters like:or#.
Exercise
A workflow step uses uses: ./ but fails immediately with a message that the metadata file cannot be found. Name two likely causes.
Show answer
The file is not named exactly action.yml or action.yaml, or it is not in the directory the path points to. A missing actions/checkout step is also a likely cause, because the repository files are not on the runner yet.
Exercise
Which key in action.yml decides whether the action runs as a Node script or as a container, and what values would you set for each?
Show answer
The using field under runs. Use node20 with a main file for a JavaScript action, or docker with an image for a container action.