Skip to content

Commit 77ddc89

Browse files
fix: conclusion and outcome are no integers (#1136)
* fix: conclusion and outcome are no integers * Change Test Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 9357512 commit 77ddc89

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

Diff for: pkg/exprparser/interpreter.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package exprparser
22

33
import (
4+
"encoding"
45
"fmt"
56
"math"
67
"reflect"
@@ -224,7 +225,16 @@ func (impl *interperterImpl) getPropertyValue(left reflect.Value, property strin
224225
return "", nil
225226
}
226227

227-
return fieldValue.Interface(), nil
228+
i := fieldValue.Interface()
229+
// The type stepStatus int is an integer, but should be treated as string
230+
if m, ok := i.(encoding.TextMarshaler); ok {
231+
text, err := m.MarshalText()
232+
if err != nil {
233+
return nil, err
234+
}
235+
return string(text), nil
236+
}
237+
return i, nil
228238

229239
case reflect.Map:
230240
iter := left.MapRange()

Diff for: pkg/exprparser/interpreter_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,22 @@ func TestContexts(t *testing.T) {
534534
{"env.TEST", "value", "env-context"},
535535
{"job.status", "success", "job-context"},
536536
{"steps.step-id.outputs.name", "value", "steps-context"},
537+
{"steps.step-id.conclusion", "success", "steps-context-conclusion"},
538+
{"steps.step-id.conclusion && true", true, "steps-context-conclusion"},
539+
{"steps.step-id2.conclusion", "skipped", "steps-context-conclusion"},
540+
{"steps.step-id2.conclusion && true", true, "steps-context-conclusion"},
541+
{"steps.step-id.outcome", "success", "steps-context-outcome"},
542+
{"steps.step-id['outcome']", "success", "steps-context-outcome"},
543+
{"steps.step-id.outcome == 'success'", true, "steps-context-outcome"},
544+
{"steps.step-id['outcome'] == 'success'", true, "steps-context-outcome"},
545+
{"steps.step-id.outcome && true", true, "steps-context-outcome"},
546+
{"steps['step-id']['outcome'] && true", true, "steps-context-outcome"},
547+
{"steps.step-id2.outcome", "failure", "steps-context-outcome"},
548+
{"steps.step-id2.outcome && true", true, "steps-context-outcome"},
549+
// Disabled, since the interpreter is still too broken
550+
// {"contains(steps.*.outcome, 'success')", true, "steps-context-array-outcome"},
551+
// {"contains(steps.*.outcome, 'failure')", true, "steps-context-array-outcome"},
552+
// {"contains(steps.*.outputs.name, 'value')", true, "steps-context-array-outputs"},
537553
{"runner.os", "Linux", "runner-context"},
538554
{"secrets.name", "value", "secrets-context"},
539555
{"strategy.fail-fast", true, "strategy-context"},
@@ -558,6 +574,10 @@ func TestContexts(t *testing.T) {
558574
"name": "value",
559575
},
560576
},
577+
"step-id2": {
578+
Outcome: model.StepStatusFailure,
579+
Conclusion: model.StepStatusSkipped,
580+
},
561581
},
562582
Runner: map[string]interface{}{
563583
"os": "Linux",

Diff for: pkg/runner/expression_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,14 @@ func TestEvaluateStep(t *testing.T) {
160160
out interface{}
161161
errMesg string
162162
}{
163-
{"steps.idwithnothing.conclusion", model.StepStatusSuccess, ""},
164-
{"steps.idwithnothing.outcome", model.StepStatusFailure, ""},
163+
{"steps.idwithnothing.conclusion", model.StepStatusSuccess.String(), ""},
164+
{"steps.idwithnothing.outcome", model.StepStatusFailure.String(), ""},
165165
{"steps.idwithnothing.outputs.foowithnothing", "barwithnothing", ""},
166-
{"steps.id-with-hyphens.conclusion", model.StepStatusSuccess, ""},
167-
{"steps.id-with-hyphens.outcome", model.StepStatusFailure, ""},
166+
{"steps.id-with-hyphens.conclusion", model.StepStatusSuccess.String(), ""},
167+
{"steps.id-with-hyphens.outcome", model.StepStatusFailure.String(), ""},
168168
{"steps.id-with-hyphens.outputs.foo-with-hyphens", "bar-with-hyphens", ""},
169-
{"steps.id_with_underscores.conclusion", model.StepStatusSuccess, ""},
170-
{"steps.id_with_underscores.outcome", model.StepStatusFailure, ""},
169+
{"steps.id_with_underscores.conclusion", model.StepStatusSuccess.String(), ""},
170+
{"steps.id_with_underscores.outcome", model.StepStatusFailure.String(), ""},
171171
{"steps.id_with_underscores.outputs.foo_with_underscores", "bar_with_underscores", ""},
172172
}
173173

0 commit comments

Comments
 (0)