Sub topic 16
Limitations and Choosing the Right Tool
This chapter assumes you can write a composite action with inputs, outputs, and shell on every run step. It also assumes you know how a workflow calls an action with uses. Here you will learn what composite actions can't do. You will also learn how they compare with JavaScript actions, Docker container actions, and reusable workflows, and how to pick one.
What a composite action cannot do
A composite action is a list of steps that runs inside the caller's job. It borrows the caller's runner, workspace, and environment. Most of its limits follow from that.
- No job-level settings. A composite action can't set
runs-on,strategy.matrix,services,container,needs, orpermissions. The calling job owns all of these. - No
secretscontext. Insideaction.ymlyou can't write${{ secrets.NPM_TOKEN }}. The caller must pass the value in as an input. - String inputs only. A boolean
truearrives as the string'true', and a number arrives as text. Compare with== 'true'and convert numbers in the shell. - A shell on every
runstep. There is no default shell. If you leaveshellout, the action fails validation. A step that saysshell: bashalso assumes bash exists on the runner. It does on GitHub-hosted runners, including Windows. A self-hosted runner may not have it. - No
preorposthooks. JavaScript and Docker actions can declare cleanup that runs after the job's main steps. Composite actions have no equivalent inaction.yml. Check the current documentation, because this area has changed before. If you need guaranteed cleanup, have the caller add anif: always()step. - Limited expression language.
ifand${{ }}support comparisons,contains,format, andfromJSON. They do not support loops or functions you define yourself. Complex logic belongs in a script. - A nesting cap. Composite actions can call other composite actions, but the depth is limited. The documented cap was 10 levels when this was written.
Because the action shares the job, it can also change things the caller did not expect. A step that writes to $GITHUB_ENV or $GITHUB_PATH affects every later step in the caller's job. Treat these files as part of your action's public interface and document them.
Passing a secret the supported way
The caller reads the secret and hands it to the action as an input. The action then moves it into env, which also avoids script injection.
# Caller workflow step
- uses: ./.github/actions/publish
with:
token: ${{ secrets.NPM_TOKEN }}# .github/actions/publish/action.yml
name: Publish
description: Publish the package to npm
inputs:
token:
description: npm auth token
required: true
runs:
using: composite
steps:
- shell: bash
env:
NODE_AUTH_TOKEN: ${{ inputs.token }}
run: npm publishGitHub masks the secret's value in logs. That protection breaks if your script transforms the value, for example by base64-encoding it, and then prints the result. Mask derived values yourself with echo "::add-mask::$VALUE".
How the four options compare
| Feature | Composite action | JavaScript action | Docker container action | Reusable workflow |
|---|---|---|---|---|
| Called as | A step (`uses` in `steps`) | A step | A step | A whole job (`uses` on the job) |
| Written in | YAML plus shell, other actions | JavaScript or TypeScript | Any language in an image | YAML workflow |
| Runs where | The caller's runner and job | The caller's runner and job | A container on the runner | Its own job or jobs |
| Runner OS | Any, if the shell exists | Any | Linux runners only | Whatever its jobs choose |
| Startup cost | None | Low | Image pull or build | Job scheduling |
| `pre` and `post` hooks | No | Yes | Yes | Not applicable |
| Matrix, services, `runs-on` | No | No | No | Yes |
| Receives secrets | Only as inputs | Only as inputs | Only as inputs | Declared `secrets` or `secrets: inherit` |
| Needs a build step | No | Often (bundling) | Yes, the image | No |
The "Runner OS" row matters for portability. A Docker container action fails on Windows and macOS runners. A composite action that assumes bash can still work there.
Reusable workflows for job-level reuse
If you find yourself wanting runs-on or matrix inside a composite action, you want a reusable workflow. It declares on: workflow_call, and the caller invokes it at the job level.
# .github/workflows/test.yml
name: Test
on:
workflow_call:
inputs:
node-versions:
description: JSON array of Node.js versions
type: string
default: '["18", "20"]'
secrets:
NPM_TOKEN:
required: false
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node: ${{ fromJSON(inputs.node-versions) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm ci
- run: npm test# Caller workflow
name: CI
on: [push]
jobs:
call-tests:
uses: ./.github/workflows/test.yml
with:
node-versions: '["20", "22"]'
secrets: inheritThe trade-offs run the other way from composite actions.
- A reusable workflow appears as separate jobs in the run graph. It can run in parallel with other jobs and gets a fresh runner, so it doesn't share the caller's workspace or files.
- You can't use it as one step among others in an existing job.
- Its inputs are typed (
string,boolean,number), which avoids the all-strings problem.
Choosing: a decision flow
Use these rules of thumb alongside the flow.
- Choose composite when the job is mostly gluing steps together: set up a tool, install dependencies, run a command, expose a result. It has no build step, and anyone can read the source.
- Choose JavaScript when you call the GitHub API, parse structured data, need cleanup in a
poststep, or want fast startup on every OS. The cost is a build and a committeddist/bundle, or a dependency install at run time. - Choose Docker when the action needs a fixed environment, such as a specific compiler or a language that isn't on the runner. You accept Linux-only runners and image pull time.
- Choose a reusable workflow when you are standardizing a whole pipeline: several jobs, a matrix, environments, or deployment steps.
Signs you have outgrown composite
- The
runblocks exceed 20 or 30 lines, or you have nestedifconditions that are hard to read. Move the logic into a script and call it withgithub.action_path. If the script then needs unit tests and a real language, consider a JavaScript action. - You keep adding inputs to emulate a matrix. Switch to a reusable workflow.
- You need to clean up after the job even when it fails, and the caller can't be trusted to add an
if: always()step. Use a JavaScript action withpost. - You need Windows and Linux support, but the shell commands differ. Either set
shellper step withif: runner.os == 'Windows', or move to JavaScript.
You can also combine tools. A reusable workflow can call composite actions for its repeated step sequences, so each layer handles what it does best.
Exercise
Your team wants one reusable unit that installs Node.js, restores a cache, and runs npm test across Node 18, 20, and 22 on both ubuntu-latest and windows-latest. Which tool fits, and why can't a composite action do it alone?
Show answer
Use a reusable workflow. A matrix over Node versions and operating systems, together with runs-on, are job-level settings, and a composite action can't declare them because it runs inside the caller's job. The reusable workflow declares the matrix and runs-on itself. It can still call a composite action for the install, cache, and test steps that repeat in each job.
Exercise
A composite action needs an API token. Why does ${{ secrets.API_TOKEN }} inside its action.yml fail, and what is the supported pattern?
Show answer
Composite actions can't read the secrets context. The caller must pass the value as an input, for example with: token: ${{ secrets.API_TOKEN }}. The action then reads inputs.token and maps it into a step's env instead of interpolating it directly into the run script.