Skip to content

Commit

Permalink
TEP-0118: Update PipelineTaskResultRefs for Matrix Include Parameters
Browse files Browse the repository at this point in the history
This commit updates PipelineTaskResultRefs to include result references from matrix.params.include in the list of all result references from a PipelineTas.

Note: This feature is still in preview mode.
  • Loading branch information
EmmaMunley authored and tekton-robot committed Mar 14, 2023
1 parent b7e49f2 commit f14b518
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
8 changes: 1 addition & 7 deletions pkg/apis/pipeline/v1/resultref.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,19 +200,13 @@ func ParseResultName(resultName string) (string, string) {
// in a PipelineTask and returns a list of any references that are found.
func PipelineTaskResultRefs(pt *PipelineTask) []*ResultRef {
refs := []*ResultRef{}
var matrixParams []Param
if pt.IsMatrixed() {
matrixParams = pt.Matrix.Params
}
for _, p := range append(pt.Params, matrixParams...) {
for _, p := range pt.extractAllParams() {
expressions, _ := GetVarSubstitutionExpressionsForParam(p)
refs = append(refs, NewResultRefs(expressions)...)
}

for _, whenExpression := range pt.When {
expressions, _ := whenExpression.GetVarSubstitutionExpressions()
refs = append(refs, NewResultRefs(expressions)...)
}

return refs
}
9 changes: 9 additions & 0 deletions pkg/apis/pipeline/v1/resultref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,12 @@ func TestPipelineTaskResultRefs(t *testing.T) {
},
}},
Matrix: &v1.Matrix{
Include: []v1.MatrixInclude{{
Name: "build-1",
Params: []v1.Param{{
Name: "a-param", Value: *v1.NewStructuredValues("$(tasks.pt9.results.r9)"),
}},
}},
Params: []v1.Param{{
Value: *v1.NewStructuredValues("$(tasks.pt5.results.r5)", "$(tasks.pt6.results.r6)"),
}, {
Expand Down Expand Up @@ -670,6 +676,9 @@ func TestPipelineTaskResultRefs(t *testing.T) {
}, {
PipelineTask: "pt8",
Result: "r8",
}, {
PipelineTask: "pt9",
Result: "r9",
}}
if d := cmp.Diff(refs, expectedRefs, cmpopts.SortSlices(lessResultRef)); d != "" {
t.Errorf("%v", d)
Expand Down
8 changes: 1 addition & 7 deletions pkg/apis/pipeline/v1beta1/resultref.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,13 @@ func ParseResultName(resultName string) (string, string) {
// in a PipelineTask and returns a list of any references that are found.
func PipelineTaskResultRefs(pt *PipelineTask) []*ResultRef {
refs := []*ResultRef{}
var matrixParams []Param
if pt.IsMatrixed() {
matrixParams = pt.Matrix.Params
}
for _, p := range append(pt.Params, matrixParams...) {
for _, p := range pt.extractAllParams() {
expressions, _ := GetVarSubstitutionExpressionsForParam(p)
refs = append(refs, NewResultRefs(expressions)...)
}

for _, whenExpression := range pt.WhenExpressions {
expressions, _ := whenExpression.GetVarSubstitutionExpressions()
refs = append(refs, NewResultRefs(expressions)...)
}

return refs
}
9 changes: 9 additions & 0 deletions pkg/apis/pipeline/v1beta1/resultref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,12 @@ func TestPipelineTaskResultRefs(t *testing.T) {
},
}},
Matrix: &v1beta1.Matrix{
Include: []v1beta1.MatrixInclude{{
Name: "build-1",
Params: []v1beta1.Param{{
Name: "a-param", Value: *v1beta1.NewStructuredValues("$(tasks.pt9.results.r9)"),
}},
}},
Params: []v1beta1.Param{{
Value: *v1beta1.NewStructuredValues("$(tasks.pt5.results.r5)", "$(tasks.pt6.results.r6)"),
}, {
Expand Down Expand Up @@ -670,6 +676,9 @@ func TestPipelineTaskResultRefs(t *testing.T) {
}, {
PipelineTask: "pt8",
Result: "r8",
}, {
PipelineTask: "pt9",
Result: "r9",
}}
if d := cmp.Diff(refs, expectedRefs, cmpopts.SortSlices(lessResultRef)); d != "" {
t.Errorf("%v", d)
Expand Down

0 comments on commit f14b518

Please sign in to comment.