-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: update reusable workflow input handling #2349
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expressions can return boolean and number types for parameters so EvaluateYamlNode can do it better than the typeless Interpolate |
||
} | ||
_ = 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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,23 +45,23 @@ jobs: | |
|
||
- name: test required bool | ||
run: | | ||
echo inputs.bool_required=${{ inputs.bool_required }} | ||
[[ "${{ inputs.bool_required }}" = "true" ]] || exit 1 | ||
echo inputs.bool_required=${{ tojson(inputs.bool_required) }} | ||
[[ "${{ tojson(inputs.bool_required) }}" = "true" ]] || exit 1 | ||
|
||
- name: test optional bool | ||
run: | | ||
echo inputs.bool_optional=${{ inputs.bool_optional }} | ||
[[ "${{ inputs.bool_optional }}" = "true" ]] || exit 1 | ||
echo inputs.bool_optional=${{ tojson(inputs.bool_optional) }} | ||
[[ "${{ tojson(inputs.bool_optional) }}" = "true" ]] || exit 1 | ||
|
||
- name: test required number | ||
run: | | ||
echo inputs.number_required=${{ inputs.number_required }} | ||
[[ "${{ inputs.number_required == 1 }}" = "true" ]] || exit 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tojson force string equal, to avoid any possible automatic type conversion |
||
echo inputs.number_required=${{ tojson(inputs.number_required) }} | ||
[[ "${{ tojson(inputs.number_required) == '1' }}" = "true" ]] || exit 1 | ||
|
||
- name: test optional number | ||
run: | | ||
echo inputs.number_optional=${{ inputs.number_optional }} | ||
[[ "${{ inputs.number_optional == 1 }}" = "true" ]] || exit 1 | ||
echo inputs.number_optional=${{ tojson(inputs.number_optional) }} | ||
[[ "${{ tojson(inputs.number_optional) == '1' }}" = "true" ]] || exit 1 | ||
|
||
- name: test secret | ||
run: | | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preserve the original type