diff --git a/cmd/root.go b/cmd/root.go index da7d345f..3bd2876e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -663,7 +663,36 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str } } - r, err := runner.New(config) + var r runner.Runner + if eventName == "workflow_call" { + // Do not use the totally broken code and instead craft a fake caller + convertedInputs := make(map[string]interface{}) + for k, v := range inputs { + var raw interface{} + if err := yaml.Unmarshal([]byte(v), &raw); err != nil { + return fmt.Errorf("failed to unmarshal input %s: %w", k, err) + } + convertedInputs[k] = raw + } + r, err = runner.NewReusableWorkflowRunner(&runner.RunContext{ + Config: config, + Name: "_", + JobName: "_", + Run: &model.Run{ + JobID: "_", + Workflow: &model.Workflow{ + Jobs: map[string]*model.Job{ + "_": { + Name: "_", + With: convertedInputs, + }, + }, + }, + }, + }) + } else { + r, err = runner.New(config) + } if err != nil { return err } diff --git a/cmd/root_test.go b/cmd/root_test.go index ec95385d..0d417434 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -82,3 +82,14 @@ func TestFlags(t *testing.T) { }) } } + +func TestWorkflowCall(t *testing.T) { + rootCmd := createRootCommand(context.Background(), &Input{}, "") + err := newRunCommand(context.Background(), &Input{ + platforms: []string{"ubuntu-latest=node:16-buster-slim"}, + workdir: "../pkg/runner/testdata/", + workflowsPath: "./workflow_call_inputs/workflow_call_inputs.yml", + inputs: []string{"required=required input", "boolean=true"}, + })(rootCmd, []string{"workflow_call"}) + assert.NoError(t, err) +} diff --git a/pkg/runner/expression.go b/pkg/runner/expression.go index 24f81ad9..d1673f94 100644 --- a/pkg/runner/expression.go +++ b/pkg/runner/expression.go @@ -514,24 +514,6 @@ func getEvaluatorInputs(ctx context.Context, rc *RunContext, step step, ghc *mod } } - if ghc.EventName == "workflow_call" { - config := rc.Run.Workflow.WorkflowCallConfig() - if config != nil && config.Inputs != nil { - for k, v := range config.Inputs { - value := nestedMapLookup(ghc.Event, "inputs", k) - if value == nil { - if err := v.Default.Decode(&value); err != nil { - common.Logger(ctx).Debugf("error decoding default value for %s: %v", k, err) - } - } - if v.Type == "boolean" { - inputs[k] = value == "true" - } else { - inputs[k] = value - } - } - } - } return inputs } diff --git a/pkg/runner/runner_test.go b/pkg/runner/runner_test.go index 39f29052..0b29020b 100644 --- a/pkg/runner/runner_test.go +++ b/pkg/runner/runner_test.go @@ -303,7 +303,6 @@ func TestRunEvent(t *testing.T) { {workdir, "docker-action-custom-path", "push", "", platforms, secrets}, {workdir, "GITHUB_ENV-use-in-env-ctx", "push", "", platforms, secrets}, {workdir, "ensure-post-steps", "push", "Job 'second-post-step-should-fail' failed", platforms, secrets}, - {workdir, "workflow_call_inputs", "workflow_call", "", platforms, secrets}, {workdir, "workflow_dispatch", "workflow_dispatch", "", platforms, secrets}, {workdir, "workflow_dispatch_no_inputs_mapping", "workflow_dispatch", "", platforms, secrets}, {workdir, "workflow_dispatch-scalar", "workflow_dispatch", "", platforms, secrets}, diff --git a/pkg/runner/testdata/workflow_call_inputs/event.json b/pkg/runner/testdata/workflow_call_inputs/event.json deleted file mode 100644 index d3ecab10..00000000 --- a/pkg/runner/testdata/workflow_call_inputs/event.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "inputs": { - "required": "required input", - "boolean": "true" - } -} diff --git a/pkg/runner/testdata/workflow_call_inputs/workflow_call_inputs.yml b/pkg/runner/testdata/workflow_call_inputs/workflow_call_inputs.yml index 1a5cca3f..1f9bd9fe 100644 --- a/pkg/runner/testdata/workflow_call_inputs/workflow_call_inputs.yml +++ b/pkg/runner/testdata/workflow_call_inputs/workflow_call_inputs.yml @@ -10,6 +10,10 @@ on: description: an input with default required: false default: default + with_default2: + description: an input with default + required: false + default: ${{ github.event_name }} boolean: description: an input of type boolean required: false @@ -27,6 +31,10 @@ jobs: run: | echo input.with_default=${{ inputs.with_default }} [[ "${{ inputs.with_default }}" = "default" ]] || exit 1 + - name: test input with default2 + run: | + echo input.with_default2=${{ inputs.with_default2 }} + [[ "${{ inputs.with_default2 }}" = "workflow_call" ]] || exit 1 - id: boolean-test name: run on boolean input if: ${{ inputs.boolean == true }}