Sub topic 7
Using the action from a workflow
This chapter covers how a workflow calls a composite action, how data flows in and out, and what goes wrong. It assumes you can read basic workflow syntax (jobs, steps, uses, run), you are comfortable with YAML and bash, and you know what Git tags and repositories are. It also assumes you have an action.yml with inputs and outputs, as built in the earlier chapters.
What a `uses` step does
A workflow step with uses runs an action. For a composite action, the runner reads the action's action.yml and runs each inner step in order, inside the calling job. There is no separate container or job. The inner steps share the job's runner, its filesystem, and its working directory.
The value of uses tells the runner where to find the action. The common forms are:
| Form | Example | Where the action comes from |
|---|---|---|
| Local path | `./.github/actions/greet` | The checked-out workspace of the current job |
| Another repository | `my-org/greet-action@v1` | The repository root, at a tag, branch, or commit SHA |
| Subdirectory of another repository | `my-org/tools/.github/actions/greet@v1` | A directory inside that repository |
The local path form is relative to the workspace, not to the workflow file. The action is only there if the workflow has already checked out the repository.
Calling a local action
Here is a workflow that calls the greet action from the earlier chapter. It lives in the same repository.
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 matter here.
actions/checkout@v4comes first. Without it, the workspace is empty and the runner fails with an error saying it cannot findaction.ymlat the given path.withsupplies the inputs. Each key must match an input name declared in the action'saction.yml.id: hellonames the step so that later steps can readsteps.hello.outputs.greeting.
Passing inputs
Everything under with becomes an input. Three rules apply.
- Inputs are always strings.
with: { run-tests: false }arrives as the stringfalse. Compare against strings inside the action, as ininputs.run-tests == 'true'. - An input with a
defaultcan be omitted. An input withrequired: trueand no default does not stop the workflow if you omit it, so a missing value shows up as an empty string. Check for it inside the action if it matters. - An unknown key under
withproduces a warning, not an error. A typo such aswho-to-gretis silently ignored and the default is used.
Expressions in with are evaluated by the calling workflow, before the action runs. That means you can pass values from the github context, from matrix, or from earlier steps:
name: Matrix greet
on: [push]
jobs:
greet:
runs-on: ubuntu-latest
strategy:
matrix:
name: [Ada, Grace, Linus]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/greet
with:
who-to-greet: ${{ matrix.name }}This runs the action three times, once per matrix entry, each in its own job.
Reading outputs
An action's outputs are available on the calling step's outputs object, which you read through the step id. In the example above, steps.hello.outputs.greeting holds the value defined by the action's outputs.greeting.value expression.
Without an id on the uses step, you cannot read its outputs. This is the most common reason an output appears empty. The next most common reasons are:
- The
idon the calling step does not match the one used in the expression. - The action declares the output, but the
valueexpression points to a step id that does not exist inside the action. The output is then an empty string, with no error. - The inner step wrote to
$GITHUB_OUTPUTusing a different key than the one thevalueexpression reads.
An output can be used in a later step's run, in an if, in with for another action, or in a job-level outputs block that passes the value to other jobs.
name: Pass output to another job
on: [push]
jobs:
build:
runs-on: ubuntu-latest
outputs:
greeting: ${{ steps.hello.outputs.greeting }}
steps:
- uses: actions/checkout@v4
- id: hello
uses: ./.github/actions/greet
report:
needs: build
runs-on: ubuntu-latest
steps:
- env:
GREETING: ${{ needs.build.outputs.greeting }}
run: echo "$GREETING"The report step reads the value through env rather than writing the expression into the script text. The reason is covered in a later chapter on script injection.
Calling an action from another repository
To share an action across repositories, put action.yml in a repository and refer to it as owner/repo@ref. The ref can be a tag, a branch, or a full commit SHA.
name: Use shared action
on: [push]
jobs:
greet:
runs-on: ubuntu-latest
steps:
- id: hello
uses: my-org/greet-action@v1
with:
who-to-greet: Octocat
- run: echo "${{ steps.hello.outputs.greeting }}"No checkout step is needed for the action itself. The runner downloads the action's repository at the requested ref before it runs the step. You only need actions/checkout if your own steps need the calling repository's files.
If the action's action.yml is in a subdirectory rather than the repository root, add the path: my-org/tools/.github/actions/greet@v1.
Access to private repositories
A public action can be used by any workflow. An action in a private repository can be used by other repositories only if the repository's Actions access setting allows it. In the action repository, open Settings, then Actions, then General, and under Access choose to allow access from repositories in the same user account or organization. Without this, the job fails when it tries to download the action.
Choosing the ref
The @ref part decides which version of the action you run. This is a trade-off.
| Ref | Behavior | Risk |
|---|---|---|
| `@v1` (moving major tag) | Gets compatible updates automatically | The owner can move the tag, so the code can change without your review |
| `@v1.2.3` (exact tag) | Stays on one release unless the tag is moved | Tags are mutable in Git, so this is not a guarantee |
| `@<full commit SHA>` | Always the exact same code | Updates are manual, and the SHA is hard to read |
| `@main` (branch) | Always the latest commit | Any push can break or change your workflow |
For actions you do not control, pinning to a full commit SHA is the safest choice, and a trailing comment such as # v1.2.3 keeps it readable. For actions your team owns, a moving major tag is common. Releasing and tag management are covered in a later chapter.
What happens inside the job
It helps to know how the runner presents the action in the log and in the job's state.
- The composite step appears as one entry in the log, with the inner steps nested under it. Each inner step has its own group.
- Inner steps run with the job's working directory. A
runstep in the action starts inGITHUB_WORKSPACE, the same as your own steps, unless the inner step setsworking-directory. - Environment variables set by the calling workflow with
envon the job or on theusesstep are visible to inner steps. - Variables written to
$GITHUB_ENVinside the action stay in effect for later steps in the calling job. This is useful, but it also means an action can change the job's environment as a side effect. secretsare not available as a context inside the action. The caller must pass a secret in throughwith, for exampletoken: ${{ secrets.MY_TOKEN }}.
Common mistakes
- Forgetting checkout for a local action. The error mentions that
action.ymlwas not found. Addactions/checkoutbefore theusesstep. - Missing step
id. The output expression returns an empty string. Addid:to the calling step. - Treating inputs as booleans or numbers.
inputs.flagis the string'false', and a non-empty string is truthy in some contexts. Compare explicitly with== 'true'. - Calling a composite action with
usesinside arun.usesis a step key, not a shell command. To run an action, it must be its own step. - Putting
withkeys that the action does not declare. The runner warns, and the value is ignored. - Moving a tag without telling users. Callers of
@v1receive the change on their next run.
Exercises
Exercise
A workflow calls uses: ./.github/actions/greet but the job fails with a message that action.yml cannot be found. The path is correct. What is the most likely cause, and how do you fix it?
Show answer
The repository has not been checked out, so the workspace is empty and the local path does not exist. Add - uses: actions/checkout@v4 as a step before the step that calls the action.
Exercise
A calling step reads ${{ steps.hello.outputs.greeting }} and gets an empty string. The action is correct and runs without errors. Name two things to check in the calling workflow.
Show answer
First, check that the step that calls the action has id: hello, because without an id its outputs cannot be read. Second, check that the id in the expression matches the id on the step exactly. If both are right, check the action's outputs.greeting.value expression and the key written to $GITHUB_OUTPUT.
Exercise
You pass with: { run-tests: false } to an action whose step has if: ${{ inputs.run-tests }}. Tests still run. Why, and what should the condition be?
Show answer
The input arrives as the string 'false', and a non-empty string is truthy, so the condition passes. Use if: ${{ inputs.run-tests == 'true' }} so the comparison is made against the string.