Skip to content

Commit 97df7c9

Browse files
committed
Add option to run command in the background
1 parent 82d59f0 commit 97df7c9

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

action-runner/dist/index.js

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

action-runner/src/main.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import nodeEval from "eval";
1616
let workspace: string;
1717
let currentCommand: Promise<ExecOutput> | null = null;
1818

19+
const backgroundCommands: Map<string, Promise<number>> = new Map<string, Promise<number>>()
20+
1921
export async function run() {
2022
const githubWorkspacePath = process.env['GITHUB_WORKSPACE']
2123
if (!githubWorkspacePath) {
@@ -81,6 +83,22 @@ export async function onMessage(ws: WebSocket, msg: any) {
8183
currentCommand = null
8284
})
8385

86+
} else if (json.type == "background-command") {
87+
const id: string = json.id
88+
const command: string[] = json.command
89+
90+
core.info(`Executing "${command.join(' ')}" in the background`)
91+
92+
const cmdLine = command.shift()!
93+
94+
const promise = exec.exec(cmdLine, command, {
95+
cwd: workspace,
96+
ignoreReturnCode: true,
97+
silent: true
98+
}).finally(() => backgroundCommands.delete(id))
99+
backgroundCommands.set(id, promise)
100+
101+
ws.send("{}")
84102
} else if (json.type == "set-env") {
85103
const name: string = json.name
86104
const value: string = json.value

src/main/java/net/neoforged/automation/runner/ActionRunner.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,16 @@ public String exec(String... command) {
224224
return res.get("stdout").asText();
225225
}
226226

227+
public void backgroundExec(String id, String... command) {
228+
sendAndExpect("background-command", node -> {
229+
var arr = node.putArray("command");
230+
for (String cmd : command) {
231+
arr.add(cmd);
232+
}
233+
node.put("id", id);
234+
});
235+
}
236+
227237
public String execFullCommand(String command) {
228238
return exec(toArgs(command).stream()
229239
.filter(Predicate.not(String::isBlank))

0 commit comments

Comments
 (0)