-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Allow specifying stdin #360
Conversation
packages/exec/src/interfaces.ts
Outdated
@@ -30,6 +30,9 @@ export interface ExecOptions { | |||
/** optional. How long in ms to wait for STDIO streams to close after the exit event of the process before terminating. defaults to 10000 */ | |||
delay?: number | |||
|
|||
/** optional. input to write to the process on STDIN. */ | |||
stdin?: Buffer |
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 kept going back-and-forth about whether to accept a Buffer or Stream here. I think Buffer is a better API for most users, but it's not quite as flexible as giving users the ability to specify a stream.
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 agree that buffer is the better api for most users. Its simple and should work for most use cases here. If we end up implementing more complicated scenarios with streams in the future, we can always support passing in a stream or a buffer mutually exclusive. We some use cases for that scenario
@bryanmacfarlane , FYI.
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.
Are we sure this is a buffer? subprocess.stdin advertises it as a writable stream. Another reason I wanted to see a pure js test instead of the script. https://nodejs.org/api/child_process.html#child_process_subprocess_stdin
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.
The input we are allowing a user to pass in here is a buffer.
We write the contents of that buffer to the process's StdIn Stream.
Very similar to how node does this with the input
option you outlined below, which also takes a string and various other inputs.
https://nodejs.org/api/child_process.html#child_process_child_process_execfilesync_file_args_options
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.
Sorry I just realized node also has input
option. Should we just pass the value through and let node handle writing to the stream?
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.
...that said, seems like would be an implementation detail and wouldn't change behavior exposed by this PR. So i think this PR is OK the way it is (incremental)
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.
input
doesn't appear to be available for any of the async process creation function. In particular we use spawn. https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options
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.
oh weird, didnt realize it was only on the sync functions. makes sense now why we dont pass thru :)
Test failure seems unrelated? |
👋 Thanks for this! I've added @bryanmacfarlane and @ericsciple to help review this change. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
adding to @thboop's radar |
Would be great to solve in a way that enables #346 (chain output of one tool runner to input of second) Might be good to start with generic bare minimum to enable the scenario, before adding specific helpers like "execWithPiping". Workaround today, piping can be achieved today by running command line, but then lose arg escaping goodness built into tool runner. Extremely leary of adding piping into toolrunner. Was in a lib before and weird race never solved. I think the second process shouldnt be started until output is actually ready from the first process? Worried about adding solution into toolrunner but not finishing. |
Hey @ericsciple thanks for the feedback. I think this does solve it in a way that supports #346. This is a lower-level API that enables Action authors to accept an input stream in their action. The framework itself could be extended to leverage this API to chain action output, but I don't think that belongs in this PR. The proposed solution in #346 wouldn't solve the use case this PR is solving. I have actions that invoke a command. The command accepts either a filepath on disk or input on stdin. The current action performs additional work to write the contents to disk before executing the command, but the extra steps could be removed if the toolrunner accepted a stream instead.
|
@sethvargo sorry i intended much of the feedback for @thboop to consider when reviewing. @thboop two scenarios i think we should cover: stdin, and piping. |
@imjohnbo could you PTAL. |
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.
Handles stdin is failing on windows. Do you have some time to fix that? If not, I can take over the PR to get this merged in.
Thanks for the contribution!
packages/exec/src/interfaces.ts
Outdated
@@ -30,6 +30,9 @@ export interface ExecOptions { | |||
/** optional. How long in ms to wait for STDIO streams to close after the exit event of the process before terminating. defaults to 10000 */ | |||
delay?: number | |||
|
|||
/** optional. input to write to the process on STDIN. */ | |||
stdin?: Buffer |
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 agree that buffer is the better api for most users. Its simple and should work for most use cases here. If we end up implementing more complicated scenarios with streams in the future, we can always support passing in a stream or a buffer mutually exclusive. We some use cases for that scenario
@bryanmacfarlane , FYI.
@thboop updated. seems happy now. |
if (IS_WINDOWS) { | ||
command = 'wait-for-input.cmd' | ||
} else { | ||
command = 'wait-for-input.sh' |
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 would like to see a test that shows what an action author would do. e.g. all js instead of the sh and cmd scripts.
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 added a js-specific test, although I admit I'm not sure exactly what you're asking. All of these tests spawn a childprocess using exec - there's no "all js". The test spawns a node subprocess with a node file that prints what it gets on stdin.
@@ -524,6 +524,14 @@ export class ToolRunner extends events.EventEmitter { | |||
resolve(exitCode) | |||
} | |||
}) | |||
|
|||
if (this.options.stdin) { | |||
if (!cp.stdin) { |
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.
is this a buffer or a stream? https://nodejs.org/api/child_process.html#child_process_subprocess_stdin
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.
Responded to this above: #360 (comment)
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.
LGTM
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 this change is good.
It seems like future goal is likely to align more with node's options. That is, allow more types for input
(whatever types node allows) and passthru to node.
As long as we're convinced this PR doesn't prevent ^, then i think this incremental change sounds fine.
added to todo list for one last look |
Yay! Looks like we're all green 🟢 |
Fixes GH-164