Sub topic 11
Calling your action from a workflow
This chapter assumes you can read basic workflow syntax (jobs, steps, uses, with) and that you already have an action.yml for a JavaScript or Docker action. Here you will call that action from a workflow, pass it inputs, and read its outputs.
Two ways to reference an action
A step runs an action through the uses key. The value tells the runner where to find the action.
| Reference | Example | Where the action lives |
|---|---|---|
| Local path | `uses: ./` | A folder in the checked-out repository |
| Subfolder | `uses: ./.github/actions/hello` | A nested folder with its own `action.yml` |
| Repository | `uses: octo-org/hello-action@v1` | Another repository, at a tag, branch, or SHA |
A local path is resolved against the workspace. The runner can only see your repository files after they are checked out, so a local action needs actions/checkout as an earlier step. This is the most common mistake: without checkout, the runner reports that it cannot find action.yml.
A complete example
This workflow checks out the repository, runs the action in the current directory, and reads its output through the step id.
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 }}"Three parts matter here:
with:supplies inputs. Each key must match an input name declared inaction.yml. For a JavaScript action,core.getInput('who-to-greet')reads the value. For a Docker action, theargslist inaction.ymlpasses it to the container.id: hellogives the step a name that later steps can refer to.steps.hello.outputs.timereads the output namedtime. The name must match the key underoutputs:inaction.yml.
How the pieces connect
Inputs and defaults
If an input is marked required: true and the workflow omits it, the runner does not stop the step by itself for a JavaScript action. The check happens when your code calls core.getInput('name', { required: true }). A default in action.yml is used when the workflow gives no value, so who-to-greet falls back to World.
All input values arrive as strings. A workflow value of true or 5 reaches the action as "true" or "5", so convert it in your code.
Referencing a published action
Once the action lives in its own repository, other workflows call it by owner, repository, and version:
steps:
- uses: octo-org/hello-action@v1
with:
who-to-greet: 'Mona'For a repository that holds several actions in subfolders, add the path: octo-org/tools/hello@v1.
Common errors
- Missing checkout. A local
uses: ./fails because the files are not on the runner yet. - Wrong output name.
steps.hello.outputs.timesexpands to an empty string and does not raise an error. Check the spelling againstaction.yml. - Missing step
id. Withoutid, thesteps.<id>expression has nothing to point to. - Unknown input. A key in
with:thataction.ymldoes not declare produces a warning, and the action ignores it.
Exercise
A workflow uses uses: ./ to run an action, but the job fails because action.yml cannot be found. The repository does contain the file. What is the likely cause, and how do you fix it?
Show answer
The job never checked out the repository, so the files are not on the runner. Add - uses: actions/checkout@v4 as a step before the step that uses ./.
Exercise
Your action sets an output named time, but a later step printing ${{ steps.hello.outputs.time }} shows nothing. Name two things to check.
Show answer
Check that the calling step has id: hello, and check that the output name in the expression matches the outputs: key in action.yml exactly. Also confirm the action actually wrote the output.