From d1ffd58e16d8d79942e6e2facdbe6a2ef57b9a87 Mon Sep 17 00:00:00 2001 From: rhysd Date: Sun, 28 Aug 2022 22:59:16 +0900 Subject: [PATCH] fix job outputs are only passed to children (fix #151) --- rule_expression.go | 2 +- testdata/err/issue151_child_of_child_job.out | 1 + testdata/err/issue151_child_of_child_job.yaml | 26 +++++++++++++++++++ testdata/ok/issue-151-child-of-child-job.yaml | 26 +++++++++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 testdata/err/issue151_child_of_child_job.out create mode 100644 testdata/err/issue151_child_of_child_job.yaml create mode 100644 testdata/ok/issue-151-child-of-child-job.yaml diff --git a/rule_expression.go b/rule_expression.go index c09d729aa..52068c958 100644 --- a/rule_expression.go +++ b/rule_expression.go @@ -795,7 +795,7 @@ func (rule *RuleExpression) populateDependantNeedsTypes(out *ObjectType, job *Jo "result": StringType{}, }) - rule.populateDependantNeedsTypes(out, j, root) // Add necessary needs props recursively + // Do not collect outputs type from parent of parent recursively. (#151) } } diff --git a/testdata/err/issue151_child_of_child_job.out b/testdata/err/issue151_child_of_child_job.out new file mode 100644 index 000000000..5dbf5bc3a --- /dev/null +++ b/testdata/err/issue151_child_of_child_job.out @@ -0,0 +1 @@ +/test\.yaml:26:31: property "first" is not defined in object type {second: {.*outputs: {second: string}.*}} \[expression\]/ diff --git a/testdata/err/issue151_child_of_child_job.yaml b/testdata/err/issue151_child_of_child_job.yaml new file mode 100644 index 000000000..0bf446d80 --- /dev/null +++ b/testdata/err/issue151_child_of_child_job.yaml @@ -0,0 +1,26 @@ +name: Test + +on: push + +jobs: + first: + runs-on: ubuntu-latest + outputs: + first: 'output from parent' + steps: + - run: echo 'first' + + second: + needs: [first] + runs-on: ubuntu-latest + outputs: + second: 'output from second' + steps: + - run: echo 'second' + + third: + needs: [second] + runs-on: ubuntu-latest + steps: + - run: echo '${{ toJSON(needs.second.outputs) }}' + - run: echo '${{ toJSON(needs.first.outputs) }}' diff --git a/testdata/ok/issue-151-child-of-child-job.yaml b/testdata/ok/issue-151-child-of-child-job.yaml new file mode 100644 index 000000000..0567b5b90 --- /dev/null +++ b/testdata/ok/issue-151-child-of-child-job.yaml @@ -0,0 +1,26 @@ +name: Test + +on: push + +jobs: + first: + runs-on: ubuntu-latest + outputs: + first: 'output from parent' + steps: + - run: echo 'first' + + second: + needs: [first] + runs-on: ubuntu-latest + outputs: + second: 'output from second' + steps: + - run: echo 'second' + + third: + needs: [first, second] + runs-on: ubuntu-latest + steps: + - run: echo '${{ toJSON(needs.second.outputs) }}' + - run: echo '${{ toJSON(needs.first.outputs) }}'