Sub topic 2
Describing an action with action.yml
Every custom action has one file that tells the runner what the action is, what it accepts, what it returns, and how to start it. That file is action.yml. This chapter covers its fields, how the runner uses them, and the mistakes that cause most first-time failures.
This chapter assumes you know basic workflow syntax (jobs, steps, uses, with) and can read YAML. You don't need to have written an action yet. The later chapters on inputs and outputs, JavaScript actions, and Docker actions build on the file described here.
Where the file lives and what it is called
The runner looks for a metadata file named action.yml or action.yaml in the root of the action's directory. If an action lives in a repository root, the file sits at the root. If a repository holds several actions, each gets its own subdirectory with its own metadata file, and a workflow refers to it as owner/repo/path@ref.
If both action.yml and action.yaml exist, action.yml wins. Use .yml consistently and don't keep both.
The shape of the file
An action file has a small set of top-level keys.
| Key | Required | Purpose |
|---|---|---|
| `name` | Yes | Display name shown in the workflow log and 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 in with `with:` |
| `outputs` | No | Values later steps can read |
| `runs` | Yes | Runtime and entry point |
| `branding` | No | Icon and color for the Marketplace listing |
The first example from the plan declares a name, a description, one input, one output, and a runtime:
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'Three of these keys (name, description, runs) must be present. A file missing any of them fails to load, and the step errors before any of your code runs.
How the runner uses the file
When a job reaches a step with uses:, the runner downloads or locates the action, reads its metadata, and decides how to execute it. The runs.using value is the branch point.
The runner also uses the file to prepare the environment. It reads the caller's with: values, matches them against the declared inputs, fills in defaults, and exposes them to your code. After your code finishes, it reads whatever outputs were written and makes them available as steps.<id>.outputs.<name>.
Inputs in detail
Each input has a key, which is its name, and a few optional properties.
inputs:
who-to-greet:
description: 'Who to greet'
required: true
default: 'World'
legacy-name:
description: 'Old name for who-to-greet'
required: false
deprecationMessage: 'Use who-to-greet instead'descriptionexplains the input to the person writing the workflow.requireddocuments whether the caller must supply a value.defaultis used when the caller does not pass the input.deprecationMessageprints a warning in the log when a caller still uses the input.
Several details matter in practice:
- Inputs are always strings. A caller who writes
with: { retries: 3 }gets the text"3". Booleans arrive as"true"or"false". Parse them in your code, and compare against the string, because"false"is truthy in JavaScript. required: trueis not a hard check at run time. The runner does not stop the step when a required input is missing. Your code has to check. In JavaScript,core.getInput('name', { required: true })throws if the value is empty. In a shell script, test the variable yourself.- A default makes
requiredmostly moot. In the example above,who-to-greetis both required and has a default, so the input is never empty unless the caller explicitly passes an empty string. - Names are case-insensitive for lookup. The runner turns each input into an environment variable named
INPUT_plus the uppercased name, with spaces changed to underscores. Hyphens are kept. Sowho-to-greetbecomesINPUT_WHO-TO-GREET. Shell scripts cannot read that name with plain$VARsyntax, which is one reason Docker actions often pass inputs throughargsinstead. The Docker chapter covers this.
Outputs in detail
For JavaScript and Docker actions, an output needs only a description:
outputs:
time:
description: 'The time we greeted you'The declaration does not produce a value. It documents what the action promises to set. The code sets the value at run time, through core.setOutput or by writing to the GITHUB_OUTPUT file. If your code never sets time, the declaration stays in the file, and the caller gets an empty string.
Composite actions work differently. Their outputs include a value key that maps to an expression, because there is no code to set the value. That belongs to the composite action chapter, but keep it in mind so you don't copy a value: line into a JavaScript action and expect it to work.
The runs block
The runs block depends on the action type. Here are the common shapes.
For a JavaScript action:
runs:
using: 'node20'
main: 'index.js'
pre: 'setup.js'
post: 'cleanup.js'usingnames the Node runtime. The value must be one the runner supports, such asnode20. A value the runner does not recognize fails the step.mainis the file to run. The path is relative to the action's root.preandpostare optional scripts that run before the job's steps and after them. A later chapter covers them.
For a Docker action:
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.who-to-greet }}imageis either a path to a Dockerfile in the action, which the runner builds on every use, or a reference such asdocker://alpine:3.20to a prebuilt image.argsis a list passed to the container's entrypoint. Expressions such as${{ inputs.who-to-greet }}are evaluated before the container starts, so each value arrives as an ordinary argument.entrypointcan override the Dockerfile'sENTRYPOINT, andenvcan set extra environment variables.
For a composite action, using is composite and a steps list follows. The first chapter of this tutorial introduced composite actions as a third type, and they are not developed here.
Branding
The optional branding block controls how the action looks in the Marketplace:
branding:
icon: 'message-circle'
color: 'blue'It has no effect on how the action runs. Add it only if you plan to publish.
Common mistakes
| Symptom | Likely cause |
|---|---|
| Step fails with "Can't find 'action.yml'" | File is missing, misnamed, or in a subdirectory the `uses:` path does not point to |
| Step fails before running any code | A required key (`name`, `description`, or `runs`) is missing, or the YAML is indented wrongly |
| Input is empty inside the action | The workflow used a different name than the declaration, or the code read the wrong name |
| `if (flag)` is always true | The input is the string `"false"`, not a boolean |
| Output is empty in a later step | The step has no `id`, the code never set the output, or the later step used the wrong output name |
| Hyphenated input unreadable in shell | The environment variable name contains a hyphen, so use `args` or a helper to read it |
The "can't find" error shows up most often when a workflow uses uses: ./ without running actions/checkout first. The runner looks in the workspace, and the workspace is empty until the repository is checked out. The test workflow from the plan does this correctly:
name: Test hello action
on: [push]
jobs:
hello:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run the local action
id: hello
uses: ./
with:
who-to-greet: 'Mona'
- name: Show the output
run: echo "The time was ${{ steps.hello.outputs.time }}"Note the id: hello on the action step. Without it, the later step has no way to refer to the output.
Keeping the file honest
The metadata file is the contract between you and every caller. A few habits keep it reliable:
- Write a real
descriptionfor every input and output. Callers read these in your README and in editors that understand the schema. - Give optional inputs a
defaultso the action works with minimal configuration. - Never rename an input in a released version without keeping the old name working. Use
deprecationMessageto steer callers toward the new name, and remove the old one only in a new major version. - Keep the declared outputs in sync with what the code sets. An output documented but never set is a silent bug.
Exercise
A workflow passes with: { dry-run: false } to your action, which declares a dry-run input with default: 'true'. Inside the action, the code runs if (core.getInput('dry-run')) { skipDeploy(); }, and the deployment is skipped even though the caller passed false. Explain why, and show the fix.
Show answer
Inputs are always strings, so the action receives the text "false", and any non-empty string is truthy in JavaScript. The check should compare against the string, for example if (core.getInput('dry-run') === 'true') { skipDeploy(); }. The toolkit also provides core.getBooleanInput('dry-run'), which converts "true" and "false" to real booleans and throws on other values.
Exercise
Write the runs block for a JavaScript action that runs dist/index.js on Node 20 and executes dist/cleanup.js after the job finishes. Then say what the runner needs in order to find these files.
Show answer
runs: using: 'node20' main: 'dist/index.js' post: 'dist/cleanup.js' The paths are relative to the action's root, so both files must be committed to the repository at the referenced ref. The runner does not run a build step for the action.