Sub topic 16
Limitations and choosing the right tool
This chapter assumes you can write an action.yml with runs.using: composite, declare inputs and outputs, and call the action from a workflow. It covers where composite actions fall short and how to pick another tool.
What composite actions cannot do
A composite action is a list of steps that runs inside the caller's job. That design explains most of its limits.
- No separate runner or container. The steps run on the caller's runner. You cannot choose
runs-onor a container image inside the action. - No job-level features. You cannot use
services,strategy.matrix,needs, orconcurrencyin the action. Those belong to jobs and workflows. - No
postorprehooks. JavaScript actions can run cleanup after the job. A composite action has no equivalent, so cleanup that must always run needs care in the calling workflow. - Strings only. Inputs and outputs are strings. Booleans and numbers need explicit comparison, such as
inputs.run-tests == 'true'. - Shell required. Every
runstep needs ashell, and the shell must exist on the runner. - Secrets are not automatic. The action cannot read the
secretscontext directly. The caller must pass a secret in as an input. - Limited logging control. The action appears as one step in the caller's log. Its inner steps are grouped under it, which makes failures harder to scan.
Comparing the options
| Need | Best fit |
|---|---|
| Bundle several shell steps and other actions | Composite action |
| Fast startup, complex logic, or `post` cleanup | JavaScript action |
| A fixed tool environment or non-standard language | Docker container action |
| Multiple jobs, matrices, secrets inheritance, or separate runners | Reusable workflow |
Trade-offs to weigh
A Docker action only runs on Linux runners and pays an image build or pull cost on every use. A JavaScript action starts quickly and works on all runner operating systems, but you must write and maintain code, and often commit a bundled dist folder. A reusable workflow gives you whole jobs and can inherit secrets, but the caller sees it as a job rather than a step, so you cannot slot it between two steps of an existing job.
A composite action is the lightest option. You write only YAML and shell, and it fits inside an existing job. The cost is that your shell steps must work on every runner your callers use. A bash script that works on ubuntu-latest may fail on a Windows runner if the script relies on Linux tools.
name: Cross-platform note
description: Prefer a portable shell when callers may use any runner
runs:
using: composite
steps:
- shell: bash
run: echo "bash is available on GitHub-hosted Linux, macOS and Windows runners"<br>
A practical rule
Start with a composite action when you are repeating a sequence of steps. Move to another tool only when you hit a specific limit from the list above.
Exercise
Your team wants a shared unit that starts a database service container, runs tests across three Node versions, and then uploads results. Why is a composite action the wrong choice, and what should you use?
Show answer
A composite action runs inside one existing job. It cannot declare services or a strategy.matrix. Use a reusable workflow, which can define whole jobs with services and a matrix.