Sub topic 1
Choosing between JavaScript, container, and composite actions
Prerequisites
This chapter assumes you can read a GitHub Actions workflow (jobs, steps, uses, with) and have basic familiarity with JavaScript and npm, Docker (Dockerfile, image, container), Git tags and branches, and a shell such as bash. You will not write a full action here. The goal is to pick the right type before you start.
The three action types
A custom action is a reusable unit of automation that a workflow calls with uses:. GitHub supports three types. They differ in what the runner executes, and that choice affects speed, portability, and what you can install.
- JavaScript action. The runner runs your script directly on the machine with Node. The
runs.usingvalue isnode20, andruns.mainnames the entry file. - Docker container action. The runner builds or pulls an image and runs your code inside a container. The
runs.usingvalue isdocker. - Composite action. The action is a list of steps, some of which run shell commands and some of which call other actions. The
runs.usingvalue iscomposite.
Every type is described by an action.yml metadata file in the action's repository. The next chapter covers that file in detail.
How the types compare
| Property | JavaScript | Docker container | Composite |
|---|---|---|---|
| Runs on | Linux, macOS, Windows | Linux runners only | Linux, macOS, Windows |
| Startup cost | Low | Higher (image build or pull) | Low |
| Environment control | Whatever the runner has, plus Node | Full control through the Dockerfile | Whatever the runner has |
| Language | JavaScript or anything that compiles to it | Any language | Shell and other actions |
| Toolkit access | `@actions/core`, `@actions/github` | Via workflow commands only | Via workflow commands only |
The Linux-only limit for Docker actions matters. If your users run jobs on Windows or macOS runners, a container action cannot serve them.
Choosing one
Work through these questions in order.
- Does the action just chain existing steps? If you are bundling a few
run:commands and calls to other actions, use a composite action. There is no code to build or bundle. - Does it need to run on every operating system? If yes, rule out Docker. Use JavaScript or composite.
- Does it need a specific language, runtime, or system tool that the runner lacks? Use Docker. The Dockerfile pins the exact environment, so the action behaves the same everywhere it runs.
- Does it need to call the GitHub API or handle structured inputs? Use JavaScript. The toolkit packages give you typed access to inputs, outputs, and the event context.
- Is fast startup important? Prefer JavaScript or composite. A container action pays for the image build or pull on every run.
Common mistakes
- Choosing Docker for a small script. A ten-line check does not justify an image. A composite or JavaScript action starts faster.
- Forgetting the Linux restriction. A container action fails on a Windows runner, and the failure shows up in your users' workflows, not yours.
- Writing JavaScript when shell would do. If the action only runs commands, a composite action removes the build and bundling step.
Exercise
Your action must parse a pull request payload, call the GitHub API, and run on ubuntu-latest, windows-latest, and macos-latest. Which type do you choose, and why?
Show answer
A JavaScript action. It runs on all three operating systems, and @actions/github gives access to the event payload and an authenticated API client. A Docker action is ruled out because it runs only on Linux runners.
Exercise
Your action needs a specific version of a Python-based linter that is not on the runner, and it will only run on Linux. Which type fits best?
Show answer
A Docker container action. The Dockerfile installs the exact linter version, so the environment is the same on every run.