From d70b225e85b44efdcd97452959a3bbabec5eb6ed Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Thu, 13 Apr 2023 15:47:59 +0200 Subject: [PATCH] fix: reusable workflow panic (#1728) Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- pkg/model/workflow.go | 3 ++- .../local-reusable-workflow-no-inputs-array.yml | 10 ++++++++++ .../local-reusable-workflow-no-inputs-string.yml | 9 +++++++++ pkg/runner/testdata/uses-workflow/local-workflow.yml | 6 ++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 pkg/runner/testdata/.github/workflows/local-reusable-workflow-no-inputs-array.yml create mode 100644 pkg/runner/testdata/.github/workflows/local-reusable-workflow-no-inputs-string.yml diff --git a/pkg/model/workflow.go b/pkg/model/workflow.go index d7e2922..35e4587 100644 --- a/pkg/model/workflow.go +++ b/pkg/model/workflow.go @@ -123,7 +123,8 @@ type WorkflowCallResult struct { func (w *Workflow) WorkflowCallConfig() *WorkflowCall { if w.RawOn.Kind != yaml.MappingNode { - return nil + // The callers expect for "on: workflow_call" and "on: [ workflow_call ]" a non nil return value + return &WorkflowCall{} } var val map[string]yaml.Node diff --git a/pkg/runner/testdata/.github/workflows/local-reusable-workflow-no-inputs-array.yml b/pkg/runner/testdata/.github/workflows/local-reusable-workflow-no-inputs-array.yml new file mode 100644 index 0000000..3df4ae3 --- /dev/null +++ b/pkg/runner/testdata/.github/workflows/local-reusable-workflow-no-inputs-array.yml @@ -0,0 +1,10 @@ +name: reusable + +on: +- workflow_call + +jobs: + reusable_workflow_job: + runs-on: ubuntu-latest + steps: + - run: echo Test \ No newline at end of file diff --git a/pkg/runner/testdata/.github/workflows/local-reusable-workflow-no-inputs-string.yml b/pkg/runner/testdata/.github/workflows/local-reusable-workflow-no-inputs-string.yml new file mode 100644 index 0000000..7558c1c --- /dev/null +++ b/pkg/runner/testdata/.github/workflows/local-reusable-workflow-no-inputs-string.yml @@ -0,0 +1,9 @@ +name: reusable + +on: workflow_call + +jobs: + reusable_workflow_job: + runs-on: ubuntu-latest + steps: + - run: echo Test \ No newline at end of file diff --git a/pkg/runner/testdata/uses-workflow/local-workflow.yml b/pkg/runner/testdata/uses-workflow/local-workflow.yml index 070e4d0..2e9a08d 100644 --- a/pkg/runner/testdata/uses-workflow/local-workflow.yml +++ b/pkg/runner/testdata/uses-workflow/local-workflow.yml @@ -19,6 +19,12 @@ jobs: number_required: 1 secrets: inherit + reusable-workflow-with-on-string-notation: + uses: ./.github/workflows/local-reusable-workflow-no-inputs-string.yml + + reusable-workflow-with-on-array-notation: + uses: ./.github/workflows/local-reusable-workflow-no-inputs-array.yml + output-test: runs-on: ubuntu-latest needs: