Sub topic 7
Using the action from a workflow
This chapter assumes you know basic workflow syntax (jobs, steps, uses, run), YAML, and bash. It also assumes you have a composite action with an action.yml file. Here you call that action from a workflow and read its outputs.
Calling a local action
A local action lives in the same repository as the workflow. You reference it with uses: and a path that starts with ./. The path points to the directory that holds action.yml, not to the file itself.
The runner must have the repository files on disk before it can find that directory. Run actions/checkout first. Without it, the job fails because the path does not exist.
name: CI
on: [push]
jobs:
greet:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: hello
uses: ./.github/actions/greet
with:
who-to-greet: Octocat
- run: echo "${{ steps.hello.outputs.greeting }}"Three parts of this workflow matter:
uses: ./.github/actions/greetselects the action by directory.with:sets the action's inputs. The keys must match the input names inaction.yml.id: hellogives the step a name, so later steps can read its outputs.
Reading outputs
An action's outputs are available through the steps context. The pattern is steps.<step id>.outputs.<output name>. In the example above, steps.hello.outputs.greeting returns the value that the action mapped from its internal step.
The step needs an id. A step without one has no name that later steps can use, so you cannot read its outputs.
The sequence below shows how the data flows.
Calling an action in another repository
For an action in a different repository, use owner/repo@ref. If action.yml is at the repository root, you write only that. If it is in a subdirectory, add the path.
steps:
- uses: my-org/greet-action@v1
with:
who-to-greet: Octocat
- uses: my-org/shared-actions/greet@v1
with:
who-to-greet: OctocatYou do not need actions/checkout for this. The runner downloads the action at the ref you name. The ref can be a tag, a branch, or a full commit SHA. A later chapter covers how to choose one.
If the action's repository is private, you must allow other repositories to use it in that repository's Actions settings.
Common errors
| Symptom | Likely cause |
|---|---|
| `Can't find 'action.yml'` for a local path | `actions/checkout` is missing, or the path points to the file instead of the directory. |
| Output is empty | The step has no `id`, the `id` is misspelled, or the action does not map the output to a step output. |
| Input seems ignored | The `with:` key does not match the declared input name. |
| Boolean input behaves oddly | Inputs are strings. Compare against `'true'`, not `true`. |
Exercises
Exercise
A workflow calls uses: ./.github/actions/greet and then runs echo "${{ steps.greet.outputs.greeting }}", but the message is empty. The action defines the greeting output correctly. Name two things to check in the workflow.
Show answer
Check that the calling step has id: greet, because the output is read through the step id and a different or missing id yields an empty value. Also check that actions/checkout ran earlier. The action must be found on disk, and a missing checkout would normally fail the step, so the id mismatch is the more likely cause of an empty value.
Exercise
Write the uses: line for an action whose action.yml is in the tools/lint directory of the repository acme/ci-actions, pinned to the tag v2.
Show answer
uses: acme/ci-actions/tools/lint@v2