Skip to content

Commit ad793fb

Browse files
committed
Simplification of run:*
Signed-off-by: hiren <[email protected]>
1 parent 893cbc0 commit ad793fb

File tree

6 files changed

+146
-35
lines changed

6 files changed

+146
-35
lines changed

dsl-reference.md

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ do:
896896
- runScript:
897897
run:
898898
script:
899-
language: js
899+
language: javascript
900900
code: >
901901
Some cool multiline script
902902
@@ -928,6 +928,8 @@ Enables the execution of external processes encapsulated within a containerized
928928
| ports | `map` | `no` | The container's port mappings, if any |
929929
| volumes | `map` | `no` | The container's volume mappings, if any |
930930
| environment | `map` | `no` | A key/value mapping of the environment variables, if any, to use when running the configured process |
931+
| stdin | `string` | `no` | A runtime expression, if any, passed as standard input to the command or default container CMD|
932+
| arguments | `string[]` | `no` | A list of the arguments, if any, passed as argv to the command or default container CMD |
931933
| lifetime | [`containerLifetime`](#container-lifetime) | `no` | An object used to configure the container's lifetime. |
932934

933935
###### Examples
@@ -939,10 +941,23 @@ document:
939941
name: run-container-example
940942
version: '0.1.0'
941943
do:
944+
- setInput:
945+
set:
946+
message: Hello World
942947
- runContainer:
948+
input:
949+
from: ${ .message }
943950
run:
944951
container:
945-
image: fake-image
952+
image: alpine
953+
stdin: ${ . }
954+
command: |
955+
input=$(cat)
956+
echo "STDIN was: $input"
957+
echo "ARGS are $1 $2"
958+
arguments:
959+
- Foo
960+
- Bar
946961
```
947962

948963
> [!NOTE]
@@ -961,9 +976,11 @@ Enables the execution of custom scripts or code within a workflow, empowering wo
961976
| language | `string` | `yes` | The language of the script to run.<br>*Supported values are: [`js`](https://tc39.es/ecma262/2024/) and [`python`](https://www.python.org/downloads/release/python-3131/).* |
962977
| code | `string` | `no` | The script's code.<br>*Required if `source` has not been set.* |
963978
| source | [externalResource](#external-resource) | `no` | The script's resource.<br>*Required if `code` has not been set.* |
964-
| arguments | `map` | `no` | A list of the arguments, if any, of the script to run |
979+
| stdin | `string` | `no` | A runtime expression, if any, to the script as standard input (stdin).|
980+
| arguments | `string[]` | `no` | A list of the arguments, if any, to the script as argv |
965981
| environment | `map` | `no` | A key/value mapping of the environment variables, if any, to use when running the configured script process |
966982

983+
967984
> [!WARNING]
968985
> To ensure cross-compatibility, Serverless Workflow strictly limits the versions of supported scripting languages. These versions may evolve with future releases. If you wish to use a different version of a language, you may do so by utilizing the [`container process`](#container-process).
969986

@@ -977,19 +994,21 @@ Enables the execution of custom scripts or code within a workflow, empowering wo
977994

978995
```yaml
979996
document:
980-
dsl: '1.0.2'
981-
namespace: test
997+
dsl: 1.0.2
998+
namespace: examples
982999
name: run-script-example
983-
version: '0.1.0'
1000+
version: 1.0.0
9841001
do:
9851002
- runScript:
9861003
run:
9871004
script:
988-
language: js
1005+
language: javascript
9891006
arguments:
990-
greetings: Hello, world!
991-
code: >
992-
console.log(greetings)
1007+
- hello
1008+
- world
1009+
code: |
1010+
const [_, __, arg0, arg1] = process.argv;
1011+
console.log('arg > ', arg0, arg1)
9931012
```
9941013

9951014
##### Shell Process
@@ -1001,7 +1020,8 @@ Enables the execution of shell commands within a workflow, enabling workflows to
10011020
| Name | Type | Required | Description |
10021021
|:--|:---:|:---:|:---|
10031022
| command | `string` | `yes` | The shell command to run |
1004-
| arguments | `map` | `no` | A list of the arguments of the shell command to run |
1023+
| stdin | `string` | `no` | A runtime expression, if any, to the shell command as standard input (stdin).|
1024+
| arguments | `string[]` | `no` | A list of the arguments, if any, to the shell command as argv |
10051025
| environment | `map` | `no` | A key/value mapping of the environment variables, if any, to use when running the configured process |
10061026

10071027
###### Examples
@@ -1013,10 +1033,22 @@ document:
10131033
name: run-shell-example
10141034
version: '0.1.0'
10151035
do:
1036+
- setInput:
1037+
set:
1038+
message: Hello World
10161039
- runShell:
1040+
input:
1041+
from: ${ .message }
10171042
run:
10181043
shell:
1019-
command: 'echo "Hello, ${ .user.name }"'
1044+
stdin: ${ . }
1045+
command: |
1046+
input=$(cat)
1047+
echo "STDIN was: $input"
1048+
echo "ARGS are $1 $2"
1049+
arguments:
1050+
- Foo
1051+
- Bar
10201052
```
10211053

10221054
##### Workflow Process
@@ -2493,7 +2525,7 @@ do:
24932525
- runScript:
24942526
run:
24952527
script:
2496-
language: js
2528+
language: javascript
24972529
code: >
24982530
Some cool multiline script
24992531
return: code
@@ -2829,4 +2861,4 @@ Describes the client of a [Model Context Protocol (MCP)](https://modelcontextpro
28292861
```yaml
28302862
name: synapse
28312863
version: '1.0.0-alpha5.2'
2832-
```
2864+
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
document:
2+
dsl: '1.0.2'
3+
namespace: test
4+
name: run-container-stdin-and-arguments
5+
version: '0.1.0'
6+
do:
7+
- setInput:
8+
set:
9+
message: Hello World
10+
- runContainer:
11+
input:
12+
from: ${ .message }
13+
run:
14+
container:
15+
image: alpine
16+
command: |
17+
input=$(cat)
18+
echo "STDIN was: $input"
19+
echo "ARGS are $1 $2"
20+
stdin: ${ . }
21+
arguments:
22+
- Foo
23+
- Bar

examples/run-script-with-arguments.yaml

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
document:
2+
dsl: 1.0.2
3+
namespace: examples
4+
name: run-script-with-stdin-and-arguments
5+
version: 1.0.0
6+
do:
7+
- runScript:
8+
run:
9+
script:
10+
language: javascript
11+
stdin: "Hello Workflow"
12+
environment:
13+
foo: bar
14+
arguments:
15+
- hello
16+
code: |
17+
// Reading Input from STDIN
18+
import { readFileSync } from 'node:fs';
19+
const stdin = readFileSync(process.stdin.fd, 'utf8');
20+
console.log('stdin > ', stdin) // Output: stdin > Hello Workflow
21+
22+
// Reading from argv
23+
const [_, __, arg] = process.argv;
24+
console.log('arg > ', arg) // Output: arg > hello
25+
26+
// Reading from env
27+
const foo = process.env.foo;
28+
console.log('env > ', foo) // Output: env > bar
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
document:
2+
dsl: 1.0.2
3+
namespace: examples
4+
name: run-shell-with-stdin-and-arguments
5+
version: 1.0.0
6+
do:
7+
- setInput:
8+
set:
9+
message: Hello World
10+
- runShell:
11+
input:
12+
from: ${ .message }
13+
run:
14+
shell:
15+
stdin: ${ . }
16+
command: |
17+
input=$(cat)
18+
echo "STDIN was: $input"
19+
echo "ARGS are $1 $2"
20+
arguments:
21+
- Foo
22+
- Bar

schema/workflow.yaml

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,16 @@ $defs:
809809
type: object
810810
title: ContainerEnvironment
811811
description: A key/value mapping of the environment variables, if any, to use when running the configured process.
812+
stdin:
813+
type: string
814+
title: ContainerStdin
815+
description: A runtime expression, if any, passed as standard input (stdin) to the command or default container CMD
816+
arguments:
817+
type: array
818+
title: ContainerArguments
819+
description: A list of the arguments, if any, passed as argv to the command or default container CMD
820+
items:
821+
type: string
812822
lifetime:
813823
$ref: '#/$defs/containerLifetime'
814824
title: ContainerLifetime
@@ -828,11 +838,16 @@ $defs:
828838
type: string
829839
title: ScriptLanguage
830840
description: The language of the script to run.
841+
stdin:
842+
type: string
843+
title: ScriptStdin
844+
description: A runtime expression, if any, to the script as standard input (stdin).
831845
arguments:
832-
type: object
846+
type: array
833847
title: ScriptArguments
834-
description: A key/value mapping of the arguments, if any, to use when running the configured script.
835-
additionalProperties: true
848+
description: A list of the arguments, if any, to the script as argv
849+
items:
850+
type: string
836851
environment:
837852
type: object
838853
title: ScriptEnvironment
@@ -870,11 +885,16 @@ $defs:
870885
type: string
871886
title: ShellCommand
872887
description: The shell command to run.
888+
stdin:
889+
type: string
890+
title: ShellStdin
891+
description: A runtime expression, if any, to the shell command as standard input (stdin).
873892
arguments:
874-
type: object
893+
type: array
875894
title: ShellArguments
876-
description: A list of the arguments of the shell command to run.
877-
additionalProperties: true
895+
description: A list of the arguments, if any, to the shell command as argv
896+
items:
897+
type: string
878898
environment:
879899
type: object
880900
title: ShellEnvironment
@@ -1928,4 +1948,4 @@ $defs:
19281948
export:
19291949
$ref: '#/$defs/export'
19301950
title: SubscriptionIteratorExport
1931-
description: An object, if any, used to customize the content of the workflow context.
1951+
description: An object, if any, used to customize the content of the workflow context.

0 commit comments

Comments
 (0)