actions / actions/toolkit

exec - Support for detachable processes

Open
#715 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement exec
Dominant language
TypeScript
Stars
5.9k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

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:

const { exec } = require('@actions/exec');
exec(process, args, {
  detached: true,
});

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the exec entry point and the _getSpawnOptions method in toolrunner.js, then review the proposed detached-process usage and the stated unit-test plan. Done means exec accepts the detached option and detached processes can outlive the action step without inherited stdio pipes keeping the action open.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.