Sub topic 4
Why every run step needs a shell
This chapter assumes you can read workflow YAML and write short bash scripts. It also assumes you know how uses and run steps work in a normal workflow. Here you will see why composite actions require a shell on every run step, which values are allowed, and what each one does.
The rule
In a workflow job, you can write run: echo hi and it works. The runner picks a shell for you. In a composite action, the same step fails to load:
name: Broken
description: Missing shell
runs:
using: composite
steps:
- run: echo "hello"The runner rejects this action.yml with an error like Required property is missing: shell. The check happens when the runner loads the action metadata, so the step never runs. The fix is one line:
name: Fixed
description: Shell set on the run step
runs:
using: composite
steps:
- run: echo "hello"
shell: bashThe requirement applies only to steps that have run. Steps that use uses start another action, which brings its own runtime, so they take no shell.
Why there is no default
A workflow author knows which runner the job uses, so the runner can choose a shell: bash when it is available (otherwise sh) on Linux and macOS, and pwsh on Windows. A job can also set defaults.run.shell for all its steps.
A composite action has no such knowledge. Any repository can call it, on any runner image, including self-hosted runners with unusual tooling. A default would make the same action.yml behave differently depending on the caller. The caller's defaults.run.shell setting does not fill in a missing shell in your action either. The action author must say which interpreter the script was written for, because only the author knows.
What the shell value means
The runner saves your run text to a temporary file and runs a command line that contains {0}, the file's path. The built-in values map to these templates:
| `shell` value | Command the runner executes | Notes |
|---|---|---|
| `bash` | `bash --noprofile --norc -eo pipefail {0}` | Stops on the first error and on failures inside pipes |
| `sh` | `sh -e {0}` | Stops on the first error only |
| `pwsh` | `pwsh -command ". '{0}'"` | PowerShell Core, on all platforms |
| `powershell` | `powershell -command ". '{0}'"` | Windows PowerShell, Windows only |
| `cmd` | `%ComSpec% /D /E:ON /V:OFF /S /C "CALL "{0}""` | Windows only |
| `python` | `python {0}` | Runs the step body as a Python script |
Two details matter in practice.
- Explicit
bashis stricter than the implicit default. When a workflow step omitsshell, the runner usesbash -e {0}. Withshell: bashyou also get-o pipefail. A pipeline such asfalse | truesucceeds in the first case and fails in the second. Code that worked as a plain workflow step can therefore fail after you move it into an action and addshell: bash. That is usually the better behavior, but it can surprise you. - Each step is a new process. Shell variables,
cd, andexportdo not carry over to the next step, even in the same action. Share data through$GITHUB_OUTPUT,$GITHUB_ENV, or$GITHUB_PATH.
Custom shell templates
You can supply your own command line, as long as it contains {0}. The runner replaces {0} with the script file path:
name: Strict bash
description: Treat unset variables as errors
runs:
using: composite
steps:
- shell: bash --noprofile --norc -euo pipefail {0}
env:
TARGET: ${{ inputs.target }}
run: |
echo "Deploying to ${TARGET}"
inputs:
target:
description: Deployment target
required: trueThe template starts with the executable name, so it must be on the runner's PATH. A custom template replaces the built-in flags completely. If you write bash {0}, you lose -e and pipefail, so repeat any flags you want.
Choosing a shell
Pick the shell by who will call the action.
- Use
bashfor most actions. Linux and macOS runners include it. Windows hosted runners provide it through Git for Windows, so one script runs on all three operating systems. - Use
shonly when the script is plain POSIX and may run where bash is missing, such as a minimal self-hosted container. Avoid arrays,[[ ]], andpipefail. - Use
pwshfor PowerShell logic. PowerShell Core is installed on the GitHub-hosted runners for all three operating systems. - Use
pythonfor parsing or string work that is clumsy in shell. The step body is Python, andpythonmust be on thePATH. If the action depends on a specific version, add anactions/setup-pythonstep first.
You can mix shells in one action. Each step stands alone:
name: Mixed shells
description: Show that every step chooses its own shell
runs:
using: composite
steps:
- shell: bash
run: echo "step one runs in bash"
- shell: pwsh
run: Write-Output "step two runs in PowerShell"
- shell: python
run: |
import platform
print("step three runs Python on", platform.system())Writing to outputs depends on the shell
The $GITHUB_OUTPUT file works with every shell, but the syntax to append to it differs. In bash you redirect with >>:
- id: version
shell: bash
run: echo "tag=v1.2.3" >> "$GITHUB_OUTPUT"In PowerShell you read the path from the environment and append with Add-Content:
- id: version
shell: pwsh
run: Add-Content -Path $env:GITHUB_OUTPUT -Value "tag=v1.2.3"If your action must run on Windows runners and you use pwsh for some steps, remember that $VAR in PowerShell is a PowerShell variable, not an environment variable. Use $env:VAR for environment variables.
Common errors
Required property is missing: shell. Arunstep has noshell. Add it to that step. There is no way to set it once for the whole action.- A step passes but should have failed. The step uses
sh, a custom template without-e, or a pipeline withoutpipefail. Switch toshell: bash, or add the flags to your template. bash: command not foundon a self-hosted runner. The runner image lacks bash. Install it, or write the step forshand setshell: sh.- A variable is empty in the next step. Variables set with
exportlast only for one step. Write them to$GITHUB_ENVor an output. - A Windows runner fails on a Linux-only command. The step uses
shell: bash, but the script calls tools such asapt-get. The shell is available, but the tool is not. Guard such steps withif: ${{ runner.os == 'Linux' }}.
Exercise
Exercise
A composite action has a step run: ./build.sh | tee build.log with shell: bash. The script build.sh exits with status 1. A colleague copied the same line into a normal workflow job without shell, and there the job passes. Why do the results differ, and what would you change in the action if you wanted the old behavior?
Show answer
With shell: bash, the runner uses bash --noprofile --norc -eo pipefail {0}. Because of pipefail, the pipeline's status is the failing status of build.sh, so the step fails. In the workflow job without shell, the runner uses bash -e {0}. Without pipefail, the pipeline's status is that of tee, which succeeds. To get the old behavior, use a custom shell such as shell: bash -e {0}. In most cases, though, keeping pipefail is better, because it reports the real failure.