Skip to content
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

Job hook provider now sets shell name for script handler #1826

Merged
merged 9 commits into from
Jun 8, 2022

Conversation

nikola-jokic
Copy link
Contributor

Closes #1825

@nikola-jokic nikola-jokic requested a review from a team as a code owner April 14, 2022 13:10
@@ -82,18 +82,23 @@ internal static (string shellCommand, string shellArgs) ParseShellOptionString(s
}
}

internal static string GetDefaultShellForScript(string path, Common.Tracing trace, string prependPath)
internal static string GetDefaultShellNameForScript(string path, Common.Tracing trace, string prependPath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: This will cause conflicts for the container hook PR, but I'd rather solve them there

if (string.IsNullOrEmpty(argFormat))
// For these shells, we want to use system binaries
var systemShells = new string[] { "bash", "sh", "powershell", "pwsh" };
if (!IsActionStep && systemShells.Contains(shell))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using !IsActionStep to explicitly limit the scope of this change to job hooks (and later container hooks - even if a container hook is a run-script-step or run-container-step, the ScriptHandler object executing the hook will not have an associated action)

@@ -13,8 +13,8 @@ internal class ScriptHandlerHelpers
["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}\"",
Copy link
Contributor

@fhammerl fhammerl Jun 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relevant to 'Runner cannot execute a script with space in its filePath’ issue:

We added "" quotes around the {0} which will eventually become the filepath.
If we don’t quote it, a space in the middle would be a path termination and only a part of the path would be read.

A runner located at /home/user/space dir/runner/ cannot even run a step like run: echo hw, because it first flushes it to disc at /home/user/space dir/runner/_work/_temp/guid.sh, then gives it as a parameter to bash. It then becomes bash --noprofile --norc -e -o pipefail /home/user/space dir/runner/_work/_temp/guid.sh, meaning bash would try to execute a non-existent script at /home/user/space. Quotes solve this problem.

Possible problems:

  • Do we perhaps ever substitute {0} with a filePath that is already quoted?

@fhammerl
Copy link
Contributor

fhammerl commented Jun 7, 2022

ericsciple
one small nit to consider, would single quotes be help guard against a greater breadth of characters
i'm trying to figure out how the command is run, single-quotes might not work on windows...

fhammerl

single-quotes might not work on windows...
Should the user execute a .sh file using bash on windows, right? We do use single quotes for the default args of pwsh and powershell though, but those are wrapped in double quotes so they are irrelevant I suppose.

would single quotes be help guard against a greater breadth of characters
Afaik the substitute value of {0} can be either a filePath (e.g. a script flushed to disc before the runner executes it, like - run: echo "hw" in the yml), or an ENV set by the user. The second case means they can get it wrong, but I think "" s are a good best effort on our part.

nikola-jokic and others added 2 commits June 8, 2022 13:22
Co-authored-by: Ferenc Hammerl <31069338+fhammerl@users.noreply.github.com>
Co-authored-by: Ferenc Hammerl <31069338+fhammerl@users.noreply.github.com>
@nikola-jokic nikola-jokic requested a review from fhammerl June 8, 2022 11:23
Copy link
Contributor

@fhammerl fhammerl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

            ["bash"] = "--noprofile --norc -e -o pipefail '{0}'",
            ["sh"] = "-e '{0}'",

Added quotes to allow spaces in executable path.

For the above case, we elected to go with single quotes to be more opinionated, as single quotes don't support string interpolation.

Considering that the possible sources of the value substituting {0} are either a user set ENV (set to a path) or a runner generated path, a literal reading of the string is the simplest solution.

@fhammerl fhammerl merged commit c3d5449 into actions:main Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants