Sub topic 4
Why every run step needs a shell
This chapter assumes you can read workflow YAML, know the difference between uses and run, and have written a short bash script. It covers one rule of composite actions: every run step must declare a shell.
The rule
In a workflow job, a run step uses a default shell chosen by the runner. On Linux and macOS that is bash. On Windows it is pwsh. A composite action does not know which runner will call it, so it does not get a default. Each run step must set shell itself.
If you leave it out, the action fails when the workflow loads. The error reads like Required property is missing: shell.
runs:
using: composite
steps:
- run: echo "no shell here"The step above is invalid. This one is valid:
runs:
using: composite
steps:
- shell: bash
run: echo "shell is set"The rule applies only to run steps. A step that uses uses to call another action needs no shell, because that action defines how it runs.
Choosing a value
The shell key accepts these values:
| Value | Meaning | Notes |
|---|---|---|
| `bash` | Bash | Available on all GitHub-hosted runners, including Windows. |
| `sh` | POSIX shell | Use when you need strict portability. |
| `pwsh` | PowerShell Core | Works on all hosted runners. |
| `python` | Python interpreter | Needs Python on the runner. |
| `cmd` | Windows Command Prompt | Windows only. |
| `powershell` | Windows PowerShell | Windows only. |
You can also give a custom command template that contains {0}, which is replaced by the name of a temporary script file. An example is shell: perl {0}.
Pick bash for most actions. It runs on Linux, macOS and Windows runners, so one script works everywhere. If you choose cmd or powershell, the action fails on a Linux runner.
How the shell changes behavior
The shell sets the flags GitHub passes to the interpreter. For bash without a custom template, the runner runs your script as bash --noprofile --norc -eo pipefail {0}. This means:
- The step stops at the first command that returns a non-zero exit code (
-e). - A failure anywhere in a pipeline fails the whole pipeline (
-o pipefail).
sh is different. It runs as sh -e {0}, so a failure in the middle of a pipeline can be missed. If a step must detect that, use bash.
Setting it once is not possible
You cannot set a default shell for a composite action. The defaults.run.shell setting works in workflows, but composite action steps ignore it. You must repeat shell: bash on every run step.
A complete example
This action has two run steps, and both declare a shell. The python step shows that the value can differ per step.
name: Show versions
description: Print the bash and Python versions
runs:
using: composite
steps:
- shell: bash
run: echo "bash $BASH_VERSION"
- shell: python
run: |
import sys
print("python", sys.version.split()[0])Exercise
A composite action has one step, - run: npm ci, and a workflow that calls it fails when it loads. What is the fix, and why was shell not needed in the calling workflow's own run steps?
Show answer
Add shell: bash to the step. The calling workflow's job runs on a known runner, which supplies a default shell (bash on Linux and macOS, pwsh on Windows). A composite action can run on any runner, so it has no default and each run step must name its shell.