From f1c58c33b6bb4d1481b2b7f8df5bac98ccc28736 Mon Sep 17 00:00:00 2001 From: Thomas Boop <52323235+thboop@users.noreply.github.com> Date: Wed, 23 Oct 2019 11:24:02 -0400 Subject: [PATCH] Default to pwsh with powershell as a fallback (#142) * Default to pwsh with powershell as a fallback * Update releaseNote.md * clean up code --- releaseNote.md | 1 + src/Runner.Worker/Handlers/ScriptHandler.cs | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/releaseNote.md b/releaseNote.md index b442870a4..723e30b7f 100644 --- a/releaseNote.md +++ b/releaseNote.md @@ -1,5 +1,6 @@ ## Features - Set Default shell to powershell for windows runners (#135) + - Use Powershell as fallback if Powershell Core is not available for default shell on windows (#142) ## Bugs - Removed unintended additional fields on error and warning commands (#137) diff --git a/src/Runner.Worker/Handlers/ScriptHandler.cs b/src/Runner.Worker/Handlers/ScriptHandler.cs index 182913049..6564863a6 100644 --- a/src/Runner.Worker/Handlers/ScriptHandler.cs +++ b/src/Runner.Worker/Handlers/ScriptHandler.cs @@ -60,10 +60,16 @@ namespace GitHub.Runner.Worker.Handlers if (string.IsNullOrEmpty(shell)) { #if OS_WINDOWS - shellCommand = "powershell"; + shellCommand = "pwsh"; if(validateShellOnHost) { - shellCommandPath = WhichUtil.Which(shellCommand, true, Trace); + shellCommandPath = WhichUtil.Which(shellCommand, require: false, Trace); + if (string.IsNullOrEmpty(shellCommandPath)) + { + shellCommand = "powershell"; + Trace.Info($"Defaulting to {shellCommand}"); + shellCommandPath = WhichUtil.Which(shellCommand, require: true, Trace); + } } #else shellCommand = "sh"; @@ -143,8 +149,14 @@ namespace GitHub.Runner.Worker.Handlers if (string.IsNullOrEmpty(shell)) { #if OS_WINDOWS - shellCommand = "powershell"; - commandPath = WhichUtil.Which(shellCommand, true, Trace); + shellCommand = "pwsh"; + commandPath = WhichUtil.Which(shellCommand, require: false, Trace); + if (string.IsNullOrEmpty(commandPath)) + { + shellCommand = "powershell"; + Trace.Info($"Defaulting to {shellCommand}"); + commandPath = WhichUtil.Which(shellCommand, require: true, Trace); + } ArgUtil.NotNullOrEmpty(commandPath, "Default Shell"); #else shellCommand = "sh";