Skip to content

Commit c23e175

Browse files
Merge pull request #18 from actionforge/bugfix/expression
Fix type conversion to string in GitHub evaluator
2 parents 07b5dfd + 54e1a30 commit c23e175

5 files changed

Lines changed: 228 additions & 1 deletion

File tree

core/inputs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ func EvaluateToStringExpression(ctx *ExecutionState, raw string) (string, error)
10401040

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

10461046
return strRes, nil
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
true
2+
true
3+
false
4+
42
5+
3.14
6+
true
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
false
2+
true
3+
false
4+
42
5+
3.14
6+
true
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
editor:
2+
version:
3+
created: v1.58.0
4+
entry: start
5+
type: standard
6+
nodes:
7+
- id: start
8+
type: core/start@v1
9+
position:
10+
x: 20
11+
y: 10
12+
- id: const-starts-with
13+
type: core/const-string@v1
14+
position:
15+
x: 30
16+
y: 210
17+
inputs:
18+
value: ${{ startsWith(github.ref, 'refs/tags/') }}
19+
- id: const-bool-true
20+
type: core/const-string@v1
21+
position:
22+
x: 310
23+
y: 280
24+
inputs:
25+
value: ${{ true }}
26+
- id: const-bool-false
27+
type: core/const-string@v1
28+
position:
29+
x: 590
30+
y: 350
31+
inputs:
32+
value: ${{ false }}
33+
- id: const-int
34+
type: core/const-string@v1
35+
position:
36+
x: 880
37+
y: 420
38+
inputs:
39+
value: ${{ 42 }}
40+
- id: const-float
41+
type: core/const-string@v1
42+
position:
43+
x: 1160
44+
y: 490
45+
inputs:
46+
value: ${{ 3.14 }}
47+
- id: const-comparison
48+
type: core/const-string@v1
49+
position:
50+
x: 1440
51+
y: 560
52+
inputs:
53+
value: ${{ 1 == 1 }}
54+
- id: print-starts-with
55+
type: core/print@v1
56+
position:
57+
x: 320
58+
y: 70
59+
inputs:
60+
values[0]: null
61+
- id: print-bool-true
62+
type: core/print@v1
63+
position:
64+
x: 610
65+
y: 140
66+
inputs:
67+
values[0]: null
68+
- id: print-bool-false
69+
type: core/print@v1
70+
position:
71+
x: 890
72+
y: 210
73+
inputs:
74+
values[0]: null
75+
- id: print-int
76+
type: core/print@v1
77+
position:
78+
x: 1170
79+
y: 280
80+
inputs:
81+
values[0]: null
82+
- id: print-float
83+
type: core/print@v1
84+
position:
85+
x: 1460
86+
y: 350
87+
inputs:
88+
values[0]: null
89+
- id: print-comparison
90+
type: core/print@v1
91+
position:
92+
x: 1730
93+
y: 420
94+
inputs:
95+
values[0]: null
96+
connections:
97+
- src:
98+
node: const-starts-with
99+
port: result
100+
dst:
101+
node: print-starts-with
102+
port: values[0]
103+
- src:
104+
node: const-bool-true
105+
port: result
106+
dst:
107+
node: print-bool-true
108+
port: values[0]
109+
- src:
110+
node: const-bool-false
111+
port: result
112+
dst:
113+
node: print-bool-false
114+
port: values[0]
115+
- src:
116+
node: const-int
117+
port: result
118+
dst:
119+
node: print-int
120+
port: values[0]
121+
- src:
122+
node: const-float
123+
port: result
124+
dst:
125+
node: print-float
126+
port: values[0]
127+
- src:
128+
node: const-comparison
129+
port: result
130+
dst:
131+
node: print-comparison
132+
port: values[0]
133+
executions:
134+
- src:
135+
node: start
136+
port: exec
137+
dst:
138+
node: print-starts-with
139+
port: exec
140+
- src:
141+
node: print-starts-with
142+
port: exec
143+
dst:
144+
node: print-bool-true
145+
port: exec
146+
- src:
147+
node: print-bool-true
148+
port: exec
149+
dst:
150+
node: print-bool-false
151+
port: exec
152+
- src:
153+
node: print-bool-false
154+
port: exec
155+
dst:
156+
node: print-int
157+
port: exec
158+
- src:
159+
node: print-int
160+
port: exec
161+
dst:
162+
node: print-float
163+
port: exec
164+
- src:
165+
node: print-float
166+
port: exec
167+
dst:
168+
node: print-comparison
169+
port: exec
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
echo "Test expressions evaluating to non-string types are converted to string"
2+
3+
TEST_NAME=expression_to_bool
4+
GRAPH_FILE="${ACT_GRAPH_FILES_DIR}${PATH_SEPARATOR}${TEST_NAME}.act"
5+
cp $GRAPH_FILE $TEST_NAME.act
6+
export ACT_GRAPH_FILE=$TEST_NAME.act
7+
export GITHUB_ACTIONS=true
8+
export GITHUB_WORKSPACE=$ACT_GRAPH_FILES_DIR
9+
export GITHUB_EVENT_NAME=push
10+
export GITHUB_REF=refs/tags/v1.0.0
11+
12+
# here run only the printed values (no info output)
13+
ACTUAL=$(ACT_LOGLEVEL=verbose ACT_NOCOLOR=true actrun 2>&1)
14+
15+
EXPECTED=$(printf "true\ntrue\nfalse\n42\n3.14\ntrue")
16+
17+
if [ "$ACTUAL" = "$EXPECTED" ]; then
18+
echo "PASS"
19+
else
20+
echo "FAIL"
21+
echo "expected:"
22+
echo "$EXPECTED"
23+
echo "actual:"
24+
echo "$ACTUAL"
25+
fi
26+
27+
#! test echo "$ACTUAL"
28+
29+
# now test with a branch ref, only startsWith changes to false
30+
export GITHUB_REF=refs/heads/main
31+
32+
ACTUAL=$(ACT_LOGLEVEL=verbose ACT_NOCOLOR=true actrun 2>&1)
33+
34+
EXPECTED=$(printf "false\ntrue\nfalse\n42\n3.14\ntrue")
35+
36+
if [ "$ACTUAL" = "$EXPECTED" ]; then
37+
echo "PASS"
38+
else
39+
echo "FAIL"
40+
echo "expected:"
41+
echo "$EXPECTED"
42+
echo "actual:"
43+
echo "$ACTUAL"
44+
fi
45+
46+
#! test echo "$ACTUAL"

0 commit comments

Comments
 (0)