Skip to content

Commit 38b7acf

Browse files
committed
Support return
Signed-off-by: Matheus Cruz <[email protected]>
1 parent 94e6fa6 commit 38b7acf

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

impl/core/src/main/java/io/serverlessworkflow/impl/executors/RunShellExecutor.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.serverlessworkflow.impl.WorkflowContext;
2424
import io.serverlessworkflow.impl.WorkflowDefinition;
2525
import io.serverlessworkflow.impl.WorkflowModel;
26+
import io.serverlessworkflow.impl.WorkflowModelFactory;
2627
import io.serverlessworkflow.impl.WorkflowUtils;
2728
import io.serverlessworkflow.impl.expressions.ExpressionUtils;
2829
import java.io.IOException;
@@ -109,12 +110,21 @@ public void init(RunShell taskConfiguration, WorkflowDefinition definition) {
109110
process.getInputStream().transferTo(the(stdout));
110111
process.getErrorStream().transferTo(the(stderr));
111112
int exitCode = process.waitFor();
112-
return definition
113-
.application()
114-
.modelFactory()
115-
.fromAny(
116-
new ProcessResult(
117-
exitCode, stdout.toString().trim(), stderr.toString().trim()));
113+
114+
RunTaskConfiguration.ProcessReturnType returnType = taskConfiguration.getReturn();
115+
116+
WorkflowModelFactory modelFactory = definition.application().modelFactory();
117+
118+
return switch (returnType) {
119+
case ALL ->
120+
modelFactory.fromAny(
121+
new ProcessResult(
122+
exitCode, stdout.toString().trim(), stderr.toString().trim()));
123+
case NONE -> modelFactory.fromNull();
124+
case CODE -> modelFactory.from(exitCode);
125+
case STDOUT -> modelFactory.from(stdout.toString().trim());
126+
case STDERR -> modelFactory.from(stderr.toString().trim());
127+
};
118128
} else {
119129
return input;
120130
}

impl/test/src/test/resources/workflows-samples/run-shell/echo-jq.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ do:
88
run:
99
shell:
1010
command: ${ "echo Hello, \(.user.name)" }
11+
return: all

impl/test/src/test/resources/workflows-samples/run-shell/echo-with-env.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ do:
1111
environment:
1212
FIRST_NAME: John
1313
LAST_NAME: ${.lastName}
14-
14+
return: all

impl/test/src/test/resources/workflows-samples/run-shell/echo.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ do:
77
- runShell:
88
run:
99
shell:
10-
command: 'echo "Hello, anonymous"'
10+
command: 'echo "Hello, anonymous"'
11+
return: all

impl/test/src/test/resources/workflows-samples/run-shell/touch-cat.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ do:
77
- runShell:
88
run:
99
shell:
10-
# write hello world to a file and then cat it
1110
command: echo "hello world" > /tmp/hello.txt && cat /tmp/hello.txt
1211
environment:
1312
FIRST_NAME: John
1413
LAST_NAME: ${.lastName}
14+
return: all
1515

0 commit comments

Comments
 (0)