mirror of
https://github.com/actions/runner.git
synced 2025-12-12 05:37:01 +00:00
Job hook provider now sets shell name for script handler (#1826)
* Job hook provider now sets shell name for script handler * fixed script handler and job hook provider to work with the name without fail * returned used import by osx * fixed order of imports * added quotes around resolved script path allowing space in script path * added quotes around bash and sh _defaultArguments * Changed double quotes to single quotes in sh -e Co-authored-by: Ferenc Hammerl <31069338+fhammerl@users.noreply.github.com> * Changed double quotes to single quotes in bash Co-authored-by: Ferenc Hammerl <31069338+fhammerl@users.noreply.github.com> Co-authored-by: Ferenc Hammerl <31069338+fhammerl@users.noreply.github.com>
This commit is contained in:
@@ -13,8 +13,8 @@ namespace GitHub.Runner.Worker.Handlers
|
||||
["cmd"] = "/D /E:ON /V:OFF /S /C \"CALL \"{0}\"\"",
|
||||
["pwsh"] = "-command \". '{0}'\"",
|
||||
["powershell"] = "-command \". '{0}'\"",
|
||||
["bash"] = "--noprofile --norc -e -o pipefail {0}",
|
||||
["sh"] = "-e {0}",
|
||||
["bash"] = "--noprofile --norc -e -o pipefail '{0}'",
|
||||
["sh"] = "-e '{0}'",
|
||||
["python"] = "{0}"
|
||||
};
|
||||
|
||||
@@ -82,18 +82,23 @@ namespace GitHub.Runner.Worker.Handlers
|
||||
}
|
||||
}
|
||||
|
||||
internal static string GetDefaultShellForScript(string path, Common.Tracing trace, string prependPath)
|
||||
internal static string GetDefaultShellNameForScript(string path, Common.Tracing trace, string prependPath)
|
||||
{
|
||||
var format = "{0} {1}";
|
||||
switch (Path.GetExtension(path))
|
||||
{
|
||||
case ".sh":
|
||||
// use 'sh' args but prefer bash
|
||||
var pathToShell = WhichUtil.Which("bash", false, trace, prependPath) ?? WhichUtil.Which("sh", true, trace, prependPath);
|
||||
return string.Format(format, pathToShell, _defaultArguments["sh"]);
|
||||
if (WhichUtil.Which("bash", false, trace, prependPath) != null)
|
||||
{
|
||||
return "bash";
|
||||
}
|
||||
return "sh";
|
||||
case ".ps1":
|
||||
var pathToPowershell = WhichUtil.Which("pwsh", false, trace, prependPath) ?? WhichUtil.Which("powershell", true, trace, prependPath);
|
||||
return string.Format(format, pathToPowershell, _defaultArguments["powershell"]);
|
||||
if (WhichUtil.Which("pwsh", false, trace, prependPath) != null)
|
||||
{
|
||||
return "pwsh";
|
||||
}
|
||||
return "powershell";
|
||||
default:
|
||||
throw new ArgumentException($"{path} is not a valid path to a script. Make sure it ends in '.sh' or '.ps1'.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user