fix: update reusable workflow input handling (#2349)

* update reusable workflow input handling

* make test stricter

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
ChristopherHX
2024-06-05 16:30:12 +02:00
committed by GitHub
parent 55a8f9afc5
commit b917ecc184
3 changed files with 23 additions and 20 deletions

View File

@@ -512,7 +512,7 @@ func getEvaluatorInputs(ctx context.Context, rc *RunContext, step step, ghc *mod
for k, v := range config.Inputs {
value := nestedMapLookup(ghc.Event, "inputs", k)
if value == nil {
value = v.Default
v.Default.Decode(&value)
}
if v.Type == "boolean" {
inputs[k] = value == "true"
@@ -531,21 +531,24 @@ func setupWorkflowInputs(ctx context.Context, inputs *map[string]interface{}, rc
for name, input := range config.Inputs {
value := rc.caller.runContext.Run.Job().With[name]
if value != nil {
if str, ok := value.(string); ok {
node := yaml.Node{}
_ = node.Encode(value)
if rc.caller.runContext.ExprEval != nil {
// evaluate using the calling RunContext (outside)
value = rc.caller.runContext.ExprEval.Interpolate(ctx, str)
_ = rc.caller.runContext.ExprEval.EvaluateYamlNode(ctx, &node)
}
_ = node.Decode(&value)
}
if value == nil && config != nil && config.Inputs != nil {
value = input.Default
def := input.Default
if rc.ExprEval != nil {
if str, ok := value.(string); ok {
// evaluate using the called RunContext (inside)
value = rc.ExprEval.Interpolate(ctx, str)
}
// evaluate using the called RunContext (inside)
_ = rc.ExprEval.EvaluateYamlNode(ctx, &def)
}
_ = def.Decode(&value)
}
(*inputs)[name] = value