mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-09-15 18:57:01 +00:00
fix: update reusable workflow input handling (#834)
Refs https://github.com/nektos/act/pull/2349 --- * update reusable workflow input handling * make test stricter --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit 44d7ad54b07530793bbf965598636c8378beb3f9) <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - bug fixes - [PR](https://code.forgejo.org/forgejo/runner/pulls/834): <!--number 834 --><!--line 0 --><!--description Zml4OiB1cGRhdGUgcmV1c2FibGUgd29ya2Zsb3cgaW5wdXQgaGFuZGxpbmc=-->fix: update reusable workflow input handling<!--description--> <!--end release-notes-assistant--> Co-authored-by: ChristopherHX <christopher.homberger@web.de> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/834 Reviewed-by: Michael Kriese <michael.kriese@gmx.de> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
parent
432ea9fdad
commit
555b322ce5
3 changed files with 23 additions and 20 deletions
|
@ -160,10 +160,10 @@ func (w *Workflow) WorkflowDispatchConfig() *WorkflowDispatch {
|
||||||
}
|
}
|
||||||
|
|
||||||
type WorkflowCallInput struct {
|
type WorkflowCallInput struct {
|
||||||
Description string `yaml:"description"`
|
Description string `yaml:"description"`
|
||||||
Required bool `yaml:"required"`
|
Required bool `yaml:"required"`
|
||||||
Default string `yaml:"default"`
|
Default yaml.Node `yaml:"default"`
|
||||||
Type string `yaml:"type"`
|
Type string `yaml:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type WorkflowCallOutput struct {
|
type WorkflowCallOutput struct {
|
||||||
|
|
|
@ -520,7 +520,7 @@ func getEvaluatorInputs(ctx context.Context, rc *RunContext, step step, ghc *mod
|
||||||
for k, v := range config.Inputs {
|
for k, v := range config.Inputs {
|
||||||
value := nestedMapLookup(ghc.Event, "inputs", k)
|
value := nestedMapLookup(ghc.Event, "inputs", k)
|
||||||
if value == nil {
|
if value == nil {
|
||||||
value = v.Default
|
_ = v.Default.Decode(&value)
|
||||||
}
|
}
|
||||||
if v.Type == "boolean" {
|
if v.Type == "boolean" {
|
||||||
inputs[k] = value == "true"
|
inputs[k] = value == "true"
|
||||||
|
@ -539,21 +539,24 @@ func setupWorkflowInputs(ctx context.Context, inputs *map[string]interface{}, rc
|
||||||
|
|
||||||
for name, input := range config.Inputs {
|
for name, input := range config.Inputs {
|
||||||
value := rc.caller.runContext.Run.Job().With[name]
|
value := rc.caller.runContext.Run.Job().With[name]
|
||||||
|
|
||||||
if value != nil {
|
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)
|
// 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 {
|
if value == nil && config != nil && config.Inputs != nil {
|
||||||
value = input.Default
|
def := input.Default
|
||||||
if rc.ExprEval != nil {
|
if rc.ExprEval != nil {
|
||||||
if str, ok := value.(string); ok {
|
// evaluate using the called RunContext (inside)
|
||||||
// evaluate using the called RunContext (inside)
|
_ = rc.ExprEval.EvaluateYamlNode(ctx, &def)
|
||||||
value = rc.ExprEval.Interpolate(ctx, str)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
_ = def.Decode(&value)
|
||||||
}
|
}
|
||||||
|
|
||||||
(*inputs)[name] = value
|
(*inputs)[name] = value
|
||||||
|
|
|
@ -45,23 +45,23 @@ jobs:
|
||||||
|
|
||||||
- name: test required bool
|
- name: test required bool
|
||||||
run: |
|
run: |
|
||||||
echo inputs.bool_required=${{ inputs.bool_required }}
|
echo inputs.bool_required=${{ tojson(inputs.bool_required) }}
|
||||||
[[ "${{ inputs.bool_required }}" = "true" ]] || exit 1
|
[[ "${{ tojson(inputs.bool_required) }}" = "true" ]] || exit 1
|
||||||
|
|
||||||
- name: test optional bool
|
- name: test optional bool
|
||||||
run: |
|
run: |
|
||||||
echo inputs.bool_optional=${{ inputs.bool_optional }}
|
echo inputs.bool_optional=${{ tojson(inputs.bool_optional) }}
|
||||||
[[ "${{ inputs.bool_optional }}" = "true" ]] || exit 1
|
[[ "${{ tojson(inputs.bool_optional) }}" = "true" ]] || exit 1
|
||||||
|
|
||||||
- name: test required number
|
- name: test required number
|
||||||
run: |
|
run: |
|
||||||
echo inputs.number_required=${{ inputs.number_required }}
|
echo inputs.number_required=${{ tojson(inputs.number_required) }}
|
||||||
[[ "${{ inputs.number_required == 1 }}" = "true" ]] || exit 1
|
[[ "${{ tojson(inputs.number_required) == '1' }}" = "true" ]] || exit 1
|
||||||
|
|
||||||
- name: test optional number
|
- name: test optional number
|
||||||
run: |
|
run: |
|
||||||
echo inputs.number_optional=${{ inputs.number_optional }}
|
echo inputs.number_optional=${{ tojson(inputs.number_optional) }}
|
||||||
[[ "${{ inputs.number_optional == 1 }}" = "true" ]] || exit 1
|
[[ "${{ tojson(inputs.number_optional) == '1' }}" = "true" ]] || exit 1
|
||||||
|
|
||||||
- name: test secret
|
- name: test secret
|
||||||
run: |
|
run: |
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue