-
Notifications
You must be signed in to change notification settings - Fork 993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shell from prependpath #231
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2ffce0e
Prepend path before locating shell tool
092847a
Join optional prepended path to path before searching it
2de5fcb
Use prepended path when whiching shell tool
4608399
Addition prependPath location
a6dc4e1
Also use prepended paths when writing out run details
a5172c8
Small tweak to undo unnecessary change
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
using System.IO; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Linq; | ||
using GitHub.DistributedTask.Pipelines.ContextData; | ||
using GitHub.Runner.Common; | ||
using GitHub.Runner.Sdk; | ||
|
@@ -56,26 +57,27 @@ public override void PrintActionDetails(ActionRunStage stage) | |
string shellCommand; | ||
string shellCommandPath = null; | ||
bool validateShellOnHost = !(StepHost is ContainerStepHost); | ||
string prependPath = string.Join(Path.PathSeparator.ToString(), ExecutionContext.PrependPath.Reverse<string>()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just duplicated from Handler.AddPrependPathToEnvironment so it should function the same. Might could refactor a bit to reduce duplication |
||
Inputs.TryGetValue("shell", out var shell); | ||
if (string.IsNullOrEmpty(shell)) | ||
{ | ||
#if OS_WINDOWS | ||
shellCommand = "pwsh"; | ||
if(validateShellOnHost) | ||
{ | ||
shellCommandPath = WhichUtil.Which(shellCommand, require: false, Trace); | ||
shellCommandPath = WhichUtil.Which(shellCommand, require: false, Trace, prependPath); | ||
if (string.IsNullOrEmpty(shellCommandPath)) | ||
{ | ||
shellCommand = "powershell"; | ||
Trace.Info($"Defaulting to {shellCommand}"); | ||
shellCommandPath = WhichUtil.Which(shellCommand, require: true, Trace); | ||
shellCommandPath = WhichUtil.Which(shellCommand, require: true, Trace, prependPath); | ||
} | ||
} | ||
#else | ||
shellCommand = "sh"; | ||
if (validateShellOnHost) | ||
{ | ||
shellCommandPath = WhichUtil.Which("bash") ?? WhichUtil.Which("sh", true, Trace); | ||
shellCommandPath = WhichUtil.Which("bash", false, Trace, prependPath) ?? WhichUtil.Which("sh", true, Trace, prependPath); | ||
} | ||
#endif | ||
argFormat = ScriptHandlerHelpers.GetScriptArgumentsFormat(shellCommand); | ||
|
@@ -86,7 +88,7 @@ public override void PrintActionDetails(ActionRunStage stage) | |
shellCommand = parsed.shellCommand; | ||
if (validateShellOnHost) | ||
{ | ||
shellCommandPath = WhichUtil.Which(parsed.shellCommand, true, Trace); | ||
shellCommandPath = WhichUtil.Which(parsed.shellCommand, true, Trace, prependPath); | ||
} | ||
|
||
argFormat = $"{parsed.shellArgs}".TrimStart(); | ||
|
@@ -144,23 +146,24 @@ public async Task RunAsync(ActionRunStage stage) | |
Inputs.TryGetValue("shell", out var shell); | ||
var isContainerStepHost = StepHost is ContainerStepHost; | ||
|
||
string prependPath = string.Join(Path.PathSeparator.ToString(), ExecutionContext.PrependPath.Reverse<string>()); | ||
string commandPath, argFormat, shellCommand; | ||
// Set up default command and arguments | ||
if (string.IsNullOrEmpty(shell)) | ||
{ | ||
#if OS_WINDOWS | ||
shellCommand = "pwsh"; | ||
commandPath = WhichUtil.Which(shellCommand, require: false, Trace); | ||
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); | ||
commandPath = WhichUtil.Which(shellCommand, require: true, Trace, prependPath); | ||
} | ||
ArgUtil.NotNullOrEmpty(commandPath, "Default Shell"); | ||
#else | ||
shellCommand = "sh"; | ||
commandPath = WhichUtil.Which("bash", false, Trace) ?? WhichUtil.Which("sh", true, Trace); | ||
commandPath = WhichUtil.Which("bash", false, Trace, prependPath) ?? WhichUtil.Which("sh", true, Trace, prependPath); | ||
#endif | ||
argFormat = ScriptHandlerHelpers.GetScriptArgumentsFormat(shellCommand); | ||
} | ||
|
@@ -169,7 +172,7 @@ public async Task RunAsync(ActionRunStage stage) | |
var parsed = ScriptHandlerHelpers.ParseShellOptionString(shell); | ||
shellCommand = parsed.shellCommand; | ||
// For non-ContainerStepHost, the command must be located on the host by Which | ||
commandPath = WhichUtil.Which(parsed.shellCommand, !isContainerStepHost, Trace); | ||
commandPath = WhichUtil.Which(parsed.shellCommand, !isContainerStepHost, Trace, prependPath); | ||
argFormat = $"{parsed.shellArgs}".TrimStart(); | ||
if (string.IsNullOrEmpty(argFormat)) | ||
{ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe check all reference of the
Which
method to make sure we don't miss something else?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont see anywhere else that it would be useful. Most/all other uses are "internal" such as locating chmod, chown, and cmd/tar (in self-updater) so it seems like we should avoid letting users do things that might get in the way of runner operations
Other than that, the GitSourceProvider uses it, and some people may want to use an updated version of git, but Im not very familiar with what this is used for, since I thought we just check out via action now. Is that somewhere this would be useful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we should be good, leave the gitsourceprovider along since we already switch to checkout@v2 which has the right behavior anyway. :)