docs/adrs/0277-run-action-shell-options.md
Date 2019-07-09
Status Accepted
run-actions run scripts using a platform specific shell:
bash -eo pipefail on non-windows, and cmd.exe /c /d /s on windows
The shell option overrides this to allow different flags or completely different shells/interpreters
A small example is:
jobs:
bash-job:
actions:
- run: echo "Hello"
shell: bash
python-job:
actions:
- run: print("Hello")
shell: python {0}
The keyword being used is shell
shell can be either:
Builtins / Explicitly supported keywords. It is useful to support at least cmd, and powershell on Windows. Because cmd my_cmd_script and powershell my_ps1_script are not valid the same way many Linux/cross-platform interpreters are, e.g. bash myscript or python myscript. Those tools (and potentially others) also require the correct file extension to run, or must be run in a particular way to get the exit codes consistently, so we must have first class knowledge about them. We provide default templates for these keywords as follows:
cmd: Default is: %ComSpec% /D /E:ON /V:OFF /S /C "CALL "{0}"" where the script name is automatically appended with .cmd and substituted for {0}
pwsh: Default is: pwsh -command "& '{0}'" where the script is automatically appended with .ps1powershell: Default is: powershell -command "& '{0}'" where the script is automatically appended with .ps1bash: Uses bash --noprofile --norc -eo pipefail {0}
sh: Uses sh -e {0}
bash (see above) was not located on the PATHpython: python {0}sh (or other commands) may actually be a link to /bin/dash, /bin/bash, or otherA template string: command [...options] {0} [...more_options]
python {0} arg1 arg2 or similar can be used if passing args is needed. Some shells will require other options after the filename for various reasonsNote that (1) simply provides defaults that are executed with the same mechanism as (2). That is:
{0}shell: bash expands to /bin/bash --noprofile --norc -eo pipefail /runner/_layout/_work/_temp/f8d4fb2b-19d9-47e6-a786-4cc538d52761.sh on my private runnerAt this time, THE LIST OF WELL-KNOWN SHELL OPTIONS IS:
For container jobs, shell should just work the same as above, transparently. We will simply exec the command in the job container, passing the same arguments in
For builtin shells, we provide defaults that make the most sense for CI, running within Actions, and being executed by our runner
bash/sh:
set -e o pipefail is the default for bash and shell builtins, and by default when no option is given on non-Windows platformsbash {0}.powershell/pwsh
pwsh and powershell builtins, we will prepend $ErrorActionPreference = 'stop' to script contentsif ((Test-Path -LiteralPath variable:\LASTEXITCODE)) { exit $LASTEXITCODE } to powershell scripts to get Action statuses to reflect the script's last exit codepwsh -File {0}, or powershell -Command "& '{0}'", depending on needcmd
Valid shell options will depend on the hosted images. We will need to maintain tight image compat
First class support for a shell will require a major version schema change to modify. We cannot remove or modify the behavior of a well-known supported option, However, adding first class support for new shells is backwards compatible. For instance, we can add a well-known python option, because non-well-known options would have always needed to include {0}, e.g. python {0}