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>
This commit is contained in:
parent
93575124d3
commit
77ddc89444
3 changed files with 37 additions and 7 deletions
pkg
|
@ -1,6 +1,7 @@
|
||||||
package exprparser
|
package exprparser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
@ -224,7 +225,16 @@ func (impl *interperterImpl) getPropertyValue(left reflect.Value, property strin
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return fieldValue.Interface(), nil
|
i := fieldValue.Interface()
|
||||||
|
// The type stepStatus int is an integer, but should be treated as string
|
||||||
|
if m, ok := i.(encoding.TextMarshaler); ok {
|
||||||
|
text, err := m.MarshalText()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return string(text), nil
|
||||||
|
}
|
||||||
|
return i, nil
|
||||||
|
|
||||||
case reflect.Map:
|
case reflect.Map:
|
||||||
iter := left.MapRange()
|
iter := left.MapRange()
|
||||||
|
|
|
@ -534,6 +534,22 @@ func TestContexts(t *testing.T) {
|
||||||
{"env.TEST", "value", "env-context"},
|
{"env.TEST", "value", "env-context"},
|
||||||
{"job.status", "success", "job-context"},
|
{"job.status", "success", "job-context"},
|
||||||
{"steps.step-id.outputs.name", "value", "steps-context"},
|
{"steps.step-id.outputs.name", "value", "steps-context"},
|
||||||
|
{"steps.step-id.conclusion", "success", "steps-context-conclusion"},
|
||||||
|
{"steps.step-id.conclusion && true", true, "steps-context-conclusion"},
|
||||||
|
{"steps.step-id2.conclusion", "skipped", "steps-context-conclusion"},
|
||||||
|
{"steps.step-id2.conclusion && true", true, "steps-context-conclusion"},
|
||||||
|
{"steps.step-id.outcome", "success", "steps-context-outcome"},
|
||||||
|
{"steps.step-id['outcome']", "success", "steps-context-outcome"},
|
||||||
|
{"steps.step-id.outcome == 'success'", true, "steps-context-outcome"},
|
||||||
|
{"steps.step-id['outcome'] == 'success'", true, "steps-context-outcome"},
|
||||||
|
{"steps.step-id.outcome && true", true, "steps-context-outcome"},
|
||||||
|
{"steps['step-id']['outcome'] && true", true, "steps-context-outcome"},
|
||||||
|
{"steps.step-id2.outcome", "failure", "steps-context-outcome"},
|
||||||
|
{"steps.step-id2.outcome && true", true, "steps-context-outcome"},
|
||||||
|
// Disabled, since the interpreter is still too broken
|
||||||
|
// {"contains(steps.*.outcome, 'success')", true, "steps-context-array-outcome"},
|
||||||
|
// {"contains(steps.*.outcome, 'failure')", true, "steps-context-array-outcome"},
|
||||||
|
// {"contains(steps.*.outputs.name, 'value')", true, "steps-context-array-outputs"},
|
||||||
{"runner.os", "Linux", "runner-context"},
|
{"runner.os", "Linux", "runner-context"},
|
||||||
{"secrets.name", "value", "secrets-context"},
|
{"secrets.name", "value", "secrets-context"},
|
||||||
{"strategy.fail-fast", true, "strategy-context"},
|
{"strategy.fail-fast", true, "strategy-context"},
|
||||||
|
@ -558,6 +574,10 @@ func TestContexts(t *testing.T) {
|
||||||
"name": "value",
|
"name": "value",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"step-id2": {
|
||||||
|
Outcome: model.StepStatusFailure,
|
||||||
|
Conclusion: model.StepStatusSkipped,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Runner: map[string]interface{}{
|
Runner: map[string]interface{}{
|
||||||
"os": "Linux",
|
"os": "Linux",
|
||||||
|
|
|
@ -160,14 +160,14 @@ func TestEvaluateStep(t *testing.T) {
|
||||||
out interface{}
|
out interface{}
|
||||||
errMesg string
|
errMesg string
|
||||||
}{
|
}{
|
||||||
{"steps.idwithnothing.conclusion", model.StepStatusSuccess, ""},
|
{"steps.idwithnothing.conclusion", model.StepStatusSuccess.String(), ""},
|
||||||
{"steps.idwithnothing.outcome", model.StepStatusFailure, ""},
|
{"steps.idwithnothing.outcome", model.StepStatusFailure.String(), ""},
|
||||||
{"steps.idwithnothing.outputs.foowithnothing", "barwithnothing", ""},
|
{"steps.idwithnothing.outputs.foowithnothing", "barwithnothing", ""},
|
||||||
{"steps.id-with-hyphens.conclusion", model.StepStatusSuccess, ""},
|
{"steps.id-with-hyphens.conclusion", model.StepStatusSuccess.String(), ""},
|
||||||
{"steps.id-with-hyphens.outcome", model.StepStatusFailure, ""},
|
{"steps.id-with-hyphens.outcome", model.StepStatusFailure.String(), ""},
|
||||||
{"steps.id-with-hyphens.outputs.foo-with-hyphens", "bar-with-hyphens", ""},
|
{"steps.id-with-hyphens.outputs.foo-with-hyphens", "bar-with-hyphens", ""},
|
||||||
{"steps.id_with_underscores.conclusion", model.StepStatusSuccess, ""},
|
{"steps.id_with_underscores.conclusion", model.StepStatusSuccess.String(), ""},
|
||||||
{"steps.id_with_underscores.outcome", model.StepStatusFailure, ""},
|
{"steps.id_with_underscores.outcome", model.StepStatusFailure.String(), ""},
|
||||||
{"steps.id_with_underscores.outputs.foo_with_underscores", "bar_with_underscores", ""},
|
{"steps.id_with_underscores.outputs.foo_with_underscores", "bar_with_underscores", ""},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue