Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ func EvaluateToStringExpression(ctx *ExecutionState, raw string) (string, error)

strRes, ok := res.(string)
if !ok {
return "", fmt.Errorf("expression did not evaluate to a string: %T", res)
return fmt.Sprintf("%v", res), nil
}

return strRes, nil
Expand Down
6 changes: 6 additions & 0 deletions tests_e2e/references/reference_expression_to_bool.sh_l27
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
true
true
false
42
3.14
true
6 changes: 6 additions & 0 deletions tests_e2e/references/reference_expression_to_bool.sh_l46
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
false
true
false
42
3.14
true
169 changes: 169 additions & 0 deletions tests_e2e/scripts/expression_to_bool.act
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
editor:
version:
created: v1.58.0
entry: start
type: standard
nodes:
- id: start
type: core/start@v1
position:
x: 20
y: 10
- id: const-starts-with
type: core/const-string@v1
position:
x: 30
y: 210
inputs:
value: ${{ startsWith(github.ref, 'refs/tags/') }}
- id: const-bool-true
type: core/const-string@v1
position:
x: 310
y: 280
inputs:
value: ${{ true }}
- id: const-bool-false
type: core/const-string@v1
position:
x: 590
y: 350
inputs:
value: ${{ false }}
- id: const-int
type: core/const-string@v1
position:
x: 880
y: 420
inputs:
value: ${{ 42 }}
- id: const-float
type: core/const-string@v1
position:
x: 1160
y: 490
inputs:
value: ${{ 3.14 }}
- id: const-comparison
type: core/const-string@v1
position:
x: 1440
y: 560
inputs:
value: ${{ 1 == 1 }}
- id: print-starts-with
type: core/print@v1
position:
x: 320
y: 70
inputs:
values[0]: null
- id: print-bool-true
type: core/print@v1
position:
x: 610
y: 140
inputs:
values[0]: null
- id: print-bool-false
type: core/print@v1
position:
x: 890
y: 210
inputs:
values[0]: null
- id: print-int
type: core/print@v1
position:
x: 1170
y: 280
inputs:
values[0]: null
- id: print-float
type: core/print@v1
position:
x: 1460
y: 350
inputs:
values[0]: null
- id: print-comparison
type: core/print@v1
position:
x: 1730
y: 420
inputs:
values[0]: null
connections:
- src:
node: const-starts-with
port: result
dst:
node: print-starts-with
port: values[0]
- src:
node: const-bool-true
port: result
dst:
node: print-bool-true
port: values[0]
- src:
node: const-bool-false
port: result
dst:
node: print-bool-false
port: values[0]
- src:
node: const-int
port: result
dst:
node: print-int
port: values[0]
- src:
node: const-float
port: result
dst:
node: print-float
port: values[0]
- src:
node: const-comparison
port: result
dst:
node: print-comparison
port: values[0]
executions:
- src:
node: start
port: exec
dst:
node: print-starts-with
port: exec
- src:
node: print-starts-with
port: exec
dst:
node: print-bool-true
port: exec
- src:
node: print-bool-true
port: exec
dst:
node: print-bool-false
port: exec
- src:
node: print-bool-false
port: exec
dst:
node: print-int
port: exec
- src:
node: print-int
port: exec
dst:
node: print-float
port: exec
- src:
node: print-float
port: exec
dst:
node: print-comparison
port: exec
46 changes: 46 additions & 0 deletions tests_e2e/scripts/expression_to_bool.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
echo "Test expressions evaluating to non-string types are converted to string"

TEST_NAME=expression_to_bool
GRAPH_FILE="${ACT_GRAPH_FILES_DIR}${PATH_SEPARATOR}${TEST_NAME}.act"
cp $GRAPH_FILE $TEST_NAME.act
export ACT_GRAPH_FILE=$TEST_NAME.act
export GITHUB_ACTIONS=true
export GITHUB_WORKSPACE=$ACT_GRAPH_FILES_DIR
export GITHUB_EVENT_NAME=push
export GITHUB_REF=refs/tags/v1.0.0

# here run only the printed values (no info output)
ACTUAL=$(ACT_LOGLEVEL=verbose ACT_NOCOLOR=true actrun 2>&1)

EXPECTED=$(printf "true\ntrue\nfalse\n42\n3.14\ntrue")

if [ "$ACTUAL" = "$EXPECTED" ]; then
echo "PASS"
else
echo "FAIL"
echo "expected:"
echo "$EXPECTED"
echo "actual:"
echo "$ACTUAL"
fi

#! test echo "$ACTUAL"

# now test with a branch ref, only startsWith changes to false
export GITHUB_REF=refs/heads/main

ACTUAL=$(ACT_LOGLEVEL=verbose ACT_NOCOLOR=true actrun 2>&1)

EXPECTED=$(printf "false\ntrue\nfalse\n42\n3.14\ntrue")

if [ "$ACTUAL" = "$EXPECTED" ]; then
echo "PASS"
else
echo "FAIL"
echo "expected:"
echo "$EXPECTED"
echo "actual:"
echo "$ACTUAL"
fi

#! test echo "$ACTUAL"
Loading