Describe the enhancement
Add support to exec background processes that can be detached from the NodeJS process, effectively allowing them to outlive the action step.
Additional information
I'm doing some experiments with a custom GitHub Action to run unit tests in an Android emulator. I want to do some setup, start a process in the background and run action steps that requires the background process. This concept works if I do it as a series of run in a workflow (as simple as run: command &).
When I tried to reproduce it with a custom action, I noticed the spawned process never detaches from the parent and the whole action freezes. I tried to do a nohup process & on Ubuntu and the result was the same.
After some trial-and-error, I was able to properly detach my process using this snippet in my node_modules copy of _getSpawnOptions in toolrunner.js:
result.detached = options.detached;
if (options.detached) {
result.stdio = 'ignore';
}
Ignoring stdio is mandatory, otherwise the pipes will also wait on the process. The whole thing is also doable if I replace exec with child_process, but I think exec users may benefit from the detach. I only need it for Ubuntu but NodeJS claims it works in Windows as well.
I can submit a PR if this approach is approved. I want to refactor out the getSpawnOptions method to add that option, as well as unit test it - I think that approach allows exec to expose more child_process.spawn if needed, without requiring process-spawning tests.
Describe the enhancement Add support to
exec
background processes that can be detached from the NodeJS process, effectively allowing them to outlive the action step.Code Snippet This is the expected usage in JS:
Additional information I'm doing some experiments with a custom GitHub Action to run unit tests in an Android emulator. I want to do some setup, start a process in the background and run action steps that requires the background process. This concept works if I do it as a series of
run
in a workflow (as simple asrun: command &
).When I tried to reproduce it with a custom action, I noticed the spawned process never detaches from the parent and the whole action freezes. I tried to do a
nohup process &
on Ubuntu and the result was the same.After some trial-and-error, I was able to properly detach my process using this snippet in my
node_modules
copy of_getSpawnOptions
intoolrunner.js
:Ignoring
stdio
is mandatory, otherwise the pipes will also wait on the process. The whole thing is also doable if I replaceexec
withchild_process
, but I thinkexec
users may benefit from the detach. I only need it for Ubuntu but NodeJS claims it works in Windows as well.I can submit a PR if this approach is approved. I want to refactor out the
getSpawnOptions
method to add that option, as well as unit test it - I think that approach allowsexec
to expose morechild_process.spawn
if needed, without requiring process-spawning tests.