Sub topic 10
How actions run: JavaScript, Docker, and composite
This chapter assumes you can read a workflow file and already know how to reference an action with uses and pass inputs with with. Here you will learn the three ways an action can execute. Each one affects speed, runner support, and what you see in the logs.
Why the action type matters
Every action has a metadata file at its root, named action.yml or action.yaml. The runs section of that file declares the action type. You don't choose the type when you call the action, but it changes how the action behaves on your runner.
| Type | `runs.using` value | Runs on | Typical startup |
|---|---|---|---|
| JavaScript | `node20` (or another supported Node version) | Linux, Windows, macOS | Fast |
| Docker container | `docker` | Linux runners only | Slower, because the image must be pulled or built |
| Composite | `composite` | Any runner | Depends on the steps inside |
JavaScript actions
A JavaScript action runs a Node.js file directly on the runner machine. There is no container, so it starts quickly and works on all three operating systems. Most actions from actions/, such as actions/checkout and actions/setup-node, are JavaScript actions.
The metadata looks like this:
name: Example JavaScript action
description: Runs a bundled Node.js file.
runs:
using: node20
main: dist/index.jsThe main file is usually a bundled build, so the action does not need npm install at run time. An action can also declare pre and post scripts. For example, actions/cache saves the cache in a post step, which is why you see a "Post" entry for it at the end of a job log.
Docker container actions
A Docker container action packages its code and its dependencies in an image. The runner pulls the image, or builds it from a Dockerfile in the action repository, and runs it in a container.
name: Example Docker action
description: Runs inside a container.
runs:
using: docker
image: DockerfileConsider these points when you use one:
- It works only on Linux runners. A job on
windows-latestormacos-latestfails. - Building from a
Dockerfilemakes the step slower than a JavaScript step. An action that references a prebuilt image, such asimage: docker://ghcr.io/example/tool:1.2.0, avoids the build. - The container sees the workspace mounted from the runner, so it can read the files that
actions/checkoutplaced there. - You get a fixed, reproducible tool environment. That helps when an action needs software that is hard to install on the runner.
Composite actions
A composite action bundles several steps into one reusable action. Its steps can be run commands or calls to other actions through uses.
name: Install and test
description: Installs dependencies and runs tests.
inputs:
node-version:
description: Node.js version to use
default: "20"
runs:
using: composite
steps:
- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
- run: npm ci
shell: bash
- run: npm test
shell: bashEvery run step in a composite action must set shell explicitly. A missing shell is a common cause of a validation error.
A composite action hides its steps behind one entry in the calling job's log, although the log can be expanded to show the inner steps. Because it can call other actions, vet the whole chain. An innocent-looking composite action may pull in an unpinned action you never reviewed.
Telling the type of an action you use
Open the action's repository and read action.yml. Check the runs.using line. This takes under a minute and tells you three things. It tells you whether the action works on your runner OS, how much startup cost to expect, and what code runs. For a JavaScript action, review the bundled dist file or its source. For a composite action, review the listed steps. For a Docker action, review the Dockerfile or the image it names.
Exercise
Your workflow runs a job on windows-latest and calls an action whose action.yml has runs.using: docker. What happens, and what are two ways to fix it?
Show answer
The step fails because Docker container actions run only on Linux runners. Fix it by moving the job to a Linux runner such as ubuntu-latest, or by choosing a JavaScript or composite action that does the same work and supports Windows.
Exercise
You write a composite action with a step - run: npm test and the action fails validation. What is missing?
Show answer
Each run step in a composite action needs an explicit shell key, for example shell: bash.