question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Default non-Windows bash is not invoked as documented

See original GitHub issue

Describe the bug The documentation at https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepsrun implies that when a shell is not specified on a non-Windows platform, bash (if found) will be invoked as bash --noprofile --norc -eo pipefail {0}.

Fail-fast behavior using set -e o pipefail: Default for bash and built-in shell. It is also the default when you don’t provide an option on non-Windows platforms.

However, this is not exactly the case.

To Reproduce Steps to reproduce the behavior:

  1. Create an action without specifying a shell value:
    - name: No shell specified (default bash)
      run: echo Hello, world!
  1. Observe that it is executed as shell: /bin/bash -e {0} as per this example at https://github.com/johnstevenson/runner-actions-test/actions/runs/48283923 which also shows the documented behaviour when the shell is specified.

action-error-bash

Expected behavior For the command to be executed as shell: /bin/bash --noprofile --norc -e -o pipefail {0}

Runner Version and Platform

Current runner version: 2.165.2 Tested on ubuntu-latest and macos-latest

What’s not working?

Regardless of whether this is a documentation problem (or my incorrect interpretation), there is no consistency when invoking bash with and without a shell value.

The ScriptHandler:RunAsync code (also duplicated in ScriptHandler:PrintActionDetails) sets shellCommand as sh even if bash is found, resulting in the wrong format string being used:

https://github.com/actions/runner/blob/d80ab095a55324be2777de87a3c70791ae917885/src/Runner.Worker/Handlers/ScriptHandler.cs#L152-L168

So any fix would be:

#if OS_WINDOWS
                shellCommand = "pwsh";
                commandPath = WhichUtil.Which(shellCommand, require: false, Trace, prependPath);
                if (string.IsNullOrEmpty(commandPath))
                {
                    shellCommand = "powershell";
                    Trace.Info($"Defaulting to {shellCommand}");
                    commandPath = WhichUtil.Which(shellCommand, require: true, Trace, prependPath);
                }
                ArgUtil.NotNullOrEmpty(commandPath, "Default Shell");
#else
                shellCommand = "bash";
                commandPath = WhichUtil.Which(shellCommand, require: false, Trace, prependPath)
                if (string.IsNullOrEmpty(commandPath))
                {
                    shellCommand = "sh";
                    Trace.Info($"Defaulting to {shellCommand}");
                    commandPath = WhichUtil.Which(shellCommand, require: true, Trace, prependPath);
                }
                ArgUtil.NotNullOrEmpty(commandPath, "Default Shell");
#endif
                argFormat = ScriptHandlerHelpers.GetScriptArgumentsFormat(shellCommand);

I’d happily PR this if needed and if I could find out how you debug an action in Visual Studio (are there any docs about this?)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:16
  • Comments:5

github_iconTop GitHub Comments

1reaction
Makeshiftcommented, Sep 12, 2022

For self hosted runners, we don’t have the same luxury.

I’m aware this issue has been closed for a long time, and this does make sense for self-hosted runners and code running in the self-hosted environment.

However, for containers, wouldn’t it be preferable to query the default shell before starting the container and set the job defaults appropriately as part of container start?

eg.

$ docker inspect catthehacker/ubuntu:act-latest | jq -c '.[0].Config.Shell'
["/bin/bash","--login","-e","-o","pipefail","-c"]

Let me know if this should be a new issue/suggestion.

0reactions
thboopcommented, Mar 14, 2022

This is working as intended, thought I definitely understand with the docs in their current state this is very confusing.

For hosted runners, we know bash is installed, so users can expect their steps to run on it. For self hosted runners, we don’t have the same luxury. -eo pipefail would cause scripts executing on bash to fail where there would have passed on a sh instance, which could be confusing and tricky to debug for workflow authors who don’t have great visibility into what software is installed on the runner they landed on (or what happened to be in the PATH at the time of the run).

That being said, we should update the docs to clarify this behavior. I’ve filed an issue to update the documentation so we can improve this experience.

Thank you for the report! I’m going to close out this issue for now. If you need this behavior, you can use the job defaults shell and specify it as bash to invoke all steps with bash --noprofile --norc -eo pipefail {0}

Read more comments on GitHub >

github_iconTop Results From Across the Web

'bash' is not recognized as an internal or external command
It seems that it needs Bash installed. If you're using Windows then you may be able to install it using one of:.
Read more >
windows - Bash not executing from command line
Solution 1: Using 64-bit Windows command processor ... The first solution is opening a 64-bit command prompt by starting %SystemRoot%\System\cmd.
Read more >
Windows Terminal Troubleshooting
Learn fixes to common obstacles in Windows Terminal. ... To fix this, open the .inputrc file for your Git bash with a text...
Read more >
Getting Started with Git Bash Commands on Windows
Start your journey with Git and learn about Git Bash commands on Windows ... Through a separate project on GitHub called Git for...
Read more >
Git bash: Definition, commands, & getting started
Bash is a popular default shell on Linux and macOS. Git Bash is a package that installs Bash, some common bash utilities, and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found