Skip to content

Commit 2d0aaa2

Browse files
committed
Add group command
1 parent 9ad3989 commit 2d0aaa2

File tree

3 files changed

+79
-4
lines changed

3 files changed

+79
-4
lines changed

action-runner/dist/index.js

Lines changed: 32 additions & 2 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: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ export async function onMessage(ws: WebSocket, msg: any) {
6060
})
6161
.then(executed => {
6262
core.endGroup()
63-
console.log(`Command returned exit code ${executed.exitCode}`)
63+
64+
let log = core.info
65+
if (executed.exitCode != 0) {
66+
log = core.error
67+
}
68+
log(`Command returned exit code ${executed.exitCode}`)
69+
6470
if (!optional && executed.exitCode != 0) {
6571
ws.send(JSON.stringify({
6672
stderr: executed.stderr
@@ -98,7 +104,19 @@ export async function onMessage(ws: WebSocket, msg: any) {
98104
}
99105
console.log(`Read file from ${pth}`)
100106
} else if (json.type == "log") {
101-
core.warning(json.message)
107+
const type: string = json.logType
108+
const message: string = json.message
109+
110+
if (type == 'error') {
111+
core.error(message)
112+
} else if (type == 'warning' || !type) {
113+
core.warning(message)
114+
} else if (type == 'info') {
115+
core.info(message)
116+
} else if (type == 'debug') {
117+
core.debug(message)
118+
}
119+
102120
ws.send("{}")
103121
} else if (json.type == 'eval') {
104122
const expression = json.expression
@@ -129,6 +147,16 @@ export async function onMessage(ws: WebSocket, msg: any) {
129147
if (ch) console.log(`Restored cache to ` + json.paths)
130148
else console.log(`No cache hit`)
131149
ws.send("{}")
150+
} else if (json.type == 'mask') {
151+
core.setSecret(json.value)
152+
ws.send("{}")
153+
} else if (json.type == 'group') {
154+
const title = json.title
155+
if (title) {
156+
core.startGroup(title)
157+
} else {
158+
core.endGroup()
159+
}
132160
}
133161
}
134162

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,23 @@ public void log(String message) {
234234
sendAndExpect("log", n -> n.put("message", message));
235235
}
236236

237+
public <E extends Exception> void group(String title, ThrowingRunnable<E> toRun) throws E {
238+
pushGroup(title);
239+
try {
240+
toRun.run();
241+
} finally {
242+
popGroup();
243+
}
244+
}
245+
246+
public void pushGroup(String title) {
247+
sendAndExpect("group", o -> o.put("title", title));
248+
}
249+
250+
public void popGroup() {
251+
sendAndExpect("group");
252+
}
253+
237254
public void stop() {
238255
context.closeSession(WsCloseStatus.NORMAL_CLOSURE, "actions executed");
239256
handler.close(this, false);

0 commit comments

Comments
 (0)