GitHub workflow default shell
By default github workflows run the bash shell with the command:
/usr/bin/bash --noprofile --norc -e -o pipefail {0}
This is a non-interactive (due to –norc) non-login shell (due to –noprofile).
Non-interactive shell
A non-interactive shell does not source the ~/.bashrc file.
Non-login shell
A non-login shell does not source any of the following files:
- /etc/profile
- ~/.bash_profile
- ~/.bash_login
- ~/.
Issues
Not sourcing those files might cause issues, for example, it is common to set paths to installed binaries in the .bashrc file. If this is the case, by default, your github workflows will not be able to find such binaries.
Solution A. Changing shell behaviour
A common solution to prevent a github workflow step from running a non-interactive non-login shell, is to define the shell default as:
defaults:
run:
shell: bash -leo pipefail {0}
Using the -l flag will make the shell behave as a login shell.
The clear downside of this approach is that for each workflow step which requires the custom vars defined in the profile file, the default shell needs to be overridden.
Note: the -i flag makes the shell interactive. This is not recommended for github actions. An interactive shell reads and writes to a users terminal and has other effects.
Solution B. Update github runner env file
Each github runner has a .env file located in the same directory where the run.sh file is located. This file can be modified, for example, adding the paths to the desired binaries. After making changes to the .env file, the github runner has to be restarted. This can be done with:
./svc.sh stop
./svc.sh start