Skip to content

Commit 4be22e9

Browse files
fix: use the happy path for workflow_call (#88)
* not really supported mode
1 parent b3cd631 commit 4be22e9

File tree

6 files changed

+49
-26
lines changed

6 files changed

+49
-26
lines changed

cmd/root.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,36 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
663663
}
664664
}
665665

666-
r, err := runner.New(config)
666+
var r runner.Runner
667+
if eventName == "workflow_call" {
668+
// Do not use the totally broken code and instead craft a fake caller
669+
convertedInputs := make(map[string]interface{})
670+
for k, v := range inputs {
671+
var raw interface{}
672+
if err := yaml.Unmarshal([]byte(v), &raw); err != nil {
673+
return fmt.Errorf("failed to unmarshal input %s: %w", k, err)
674+
}
675+
convertedInputs[k] = raw
676+
}
677+
r, err = runner.NewReusableWorkflowRunner(&runner.RunContext{
678+
Config: config,
679+
Name: "_",
680+
JobName: "_",
681+
Run: &model.Run{
682+
JobID: "_",
683+
Workflow: &model.Workflow{
684+
Jobs: map[string]*model.Job{
685+
"_": {
686+
Name: "_",
687+
With: convertedInputs,
688+
},
689+
},
690+
},
691+
},
692+
})
693+
} else {
694+
r, err = runner.New(config)
695+
}
667696
if err != nil {
668697
return err
669698
}

cmd/root_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,14 @@ func TestFlags(t *testing.T) {
8282
})
8383
}
8484
}
85+
86+
func TestWorkflowCall(t *testing.T) {
87+
rootCmd := createRootCommand(context.Background(), &Input{}, "")
88+
err := newRunCommand(context.Background(), &Input{
89+
platforms: []string{"ubuntu-latest=node:16-buster-slim"},
90+
workdir: "../pkg/runner/testdata/",
91+
workflowsPath: "./workflow_call_inputs/workflow_call_inputs.yml",
92+
inputs: []string{"required=required input", "boolean=true"},
93+
})(rootCmd, []string{"workflow_call"})
94+
assert.NoError(t, err)
95+
}

pkg/runner/expression.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -514,24 +514,6 @@ func getEvaluatorInputs(ctx context.Context, rc *RunContext, step step, ghc *mod
514514
}
515515
}
516516

517-
if ghc.EventName == "workflow_call" {
518-
config := rc.Run.Workflow.WorkflowCallConfig()
519-
if config != nil && config.Inputs != nil {
520-
for k, v := range config.Inputs {
521-
value := nestedMapLookup(ghc.Event, "inputs", k)
522-
if value == nil {
523-
if err := v.Default.Decode(&value); err != nil {
524-
common.Logger(ctx).Debugf("error decoding default value for %s: %v", k, err)
525-
}
526-
}
527-
if v.Type == "boolean" {
528-
inputs[k] = value == "true"
529-
} else {
530-
inputs[k] = value
531-
}
532-
}
533-
}
534-
}
535517
return inputs
536518
}
537519

pkg/runner/runner_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ func TestRunEvent(t *testing.T) {
303303
{workdir, "docker-action-custom-path", "push", "", platforms, secrets},
304304
{workdir, "GITHUB_ENV-use-in-env-ctx", "push", "", platforms, secrets},
305305
{workdir, "ensure-post-steps", "push", "Job 'second-post-step-should-fail' failed", platforms, secrets},
306-
{workdir, "workflow_call_inputs", "workflow_call", "", platforms, secrets},
307306
{workdir, "workflow_dispatch", "workflow_dispatch", "", platforms, secrets},
308307
{workdir, "workflow_dispatch_no_inputs_mapping", "workflow_dispatch", "", platforms, secrets},
309308
{workdir, "workflow_dispatch-scalar", "workflow_dispatch", "", platforms, secrets},

pkg/runner/testdata/workflow_call_inputs/event.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

pkg/runner/testdata/workflow_call_inputs/workflow_call_inputs.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ on:
1010
description: an input with default
1111
required: false
1212
default: default
13+
with_default2:
14+
description: an input with default
15+
required: false
16+
default: ${{ github.event_name }}
1317
boolean:
1418
description: an input of type boolean
1519
required: false
@@ -27,6 +31,10 @@ jobs:
2731
run: |
2832
echo input.with_default=${{ inputs.with_default }}
2933
[[ "${{ inputs.with_default }}" = "default" ]] || exit 1
34+
- name: test input with default2
35+
run: |
36+
echo input.with_default2=${{ inputs.with_default2 }}
37+
[[ "${{ inputs.with_default2 }}" = "workflow_call" ]] || exit 1
3038
- id: boolean-test
3139
name: run on boolean input
3240
if: ${{ inputs.boolean == true }}

0 commit comments

Comments
 (0)