Skip to content

Commit 5e11518

Browse files
PuneetPunamiyatekton-robot
authored andcommitted
cleanup: move pipeline types
Signed-off-by: PuneetPunamiya <[email protected]>
1 parent 44a7e35 commit 5e11518

File tree

9 files changed

+552
-5
lines changed

9 files changed

+552
-5
lines changed

cmd/entrypoint/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ import (
2929
"time"
3030

3131
"github.com/tektoncd/pipeline/cmd/entrypoint/subcommands"
32-
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
33-
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
32+
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1/types"
3433
"github.com/tektoncd/pipeline/pkg/credentials"
3534
"github.com/tektoncd/pipeline/pkg/credentials/dockercreds"
3635
"github.com/tektoncd/pipeline/pkg/credentials/gitcreds"
3736
"github.com/tektoncd/pipeline/pkg/entrypoint"
37+
"github.com/tektoncd/pipeline/pkg/entrypoint/pipeline"
3838
"github.com/tektoncd/pipeline/pkg/platforms"
3939
"github.com/tektoncd/pipeline/pkg/termination"
4040
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
Copyright 2025 The Tekton Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package types
18+
19+
import (
20+
"github.com/google/go-cmp/cmp"
21+
)
22+
23+
// Algorithm Standard cryptographic hash algorithm
24+
type Algorithm string
25+
26+
// Artifact represents an artifact within a system, potentially containing multiple values
27+
// associated with it.
28+
type Artifact struct {
29+
// The artifact's identifying category name
30+
Name string `json:"name,omitempty"`
31+
// A collection of values related to the artifact
32+
Values []ArtifactValue `json:"values,omitempty"`
33+
// Indicate if the artifact is a build output or a by-product
34+
BuildOutput bool `json:"buildOutput,omitempty"`
35+
}
36+
37+
// ArtifactValue represents a specific value or data element within an Artifact.
38+
type ArtifactValue struct {
39+
Digest map[Algorithm]string `json:"digest,omitempty"` // Algorithm-specific digests for verifying the content (e.g., SHA256)
40+
Uri string `json:"uri,omitempty"` // Location where the artifact value can be retrieved
41+
}
42+
43+
// TaskRunStepArtifact represents an artifact produced or used by a step within a task run.
44+
// It directly uses the Artifact type for its structure.
45+
type TaskRunStepArtifact = Artifact
46+
47+
// Artifacts represents the collection of input and output artifacts associated with
48+
// a task run or a similar process. Artifacts in this context are units of data or resources
49+
// that the process either consumes as input or produces as output.
50+
type Artifacts struct {
51+
Inputs []Artifact `json:"inputs,omitempty"`
52+
Outputs []Artifact `json:"outputs,omitempty"`
53+
}
54+
55+
func (a *Artifacts) Merge(another *Artifacts) {
56+
inputMap := make(map[string][]ArtifactValue)
57+
var newInputs []Artifact
58+
59+
for _, v := range a.Inputs {
60+
inputMap[v.Name] = v.Values
61+
}
62+
if another != nil {
63+
for _, v := range another.Inputs {
64+
_, ok := inputMap[v.Name]
65+
if !ok {
66+
inputMap[v.Name] = []ArtifactValue{}
67+
}
68+
for _, vv := range v.Values {
69+
exists := false
70+
for _, av := range inputMap[v.Name] {
71+
if cmp.Equal(vv, av) {
72+
exists = true
73+
break
74+
}
75+
}
76+
if !exists {
77+
inputMap[v.Name] = append(inputMap[v.Name], vv)
78+
}
79+
}
80+
}
81+
}
82+
83+
for k, v := range inputMap {
84+
newInputs = append(newInputs, Artifact{
85+
Name: k,
86+
Values: v,
87+
})
88+
}
89+
90+
outputMap := make(map[string]Artifact)
91+
var newOutputs []Artifact
92+
for _, v := range a.Outputs {
93+
outputMap[v.Name] = v
94+
}
95+
96+
if another != nil {
97+
for _, v := range another.Outputs {
98+
_, ok := outputMap[v.Name]
99+
if !ok {
100+
outputMap[v.Name] = Artifact{Name: v.Name, Values: []ArtifactValue{}, BuildOutput: v.BuildOutput}
101+
}
102+
// only update buildOutput to true.
103+
// Do not convert to false if it was true before.
104+
if v.BuildOutput {
105+
art := outputMap[v.Name]
106+
art.BuildOutput = v.BuildOutput
107+
outputMap[v.Name] = art
108+
}
109+
for _, vv := range v.Values {
110+
exists := false
111+
for _, av := range outputMap[v.Name].Values {
112+
if cmp.Equal(vv, av) {
113+
exists = true
114+
break
115+
}
116+
}
117+
if !exists {
118+
art := outputMap[v.Name]
119+
art.Values = append(art.Values, vv)
120+
outputMap[v.Name] = art
121+
}
122+
}
123+
}
124+
}
125+
126+
for _, v := range outputMap {
127+
newOutputs = append(newOutputs, Artifact{
128+
Name: v.Name,
129+
Values: v.Values,
130+
BuildOutput: v.BuildOutput,
131+
})
132+
}
133+
a.Inputs = newInputs
134+
a.Outputs = newOutputs
135+
}
+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
Copyright 2025 The Tekton Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package types
18+
19+
import (
20+
"encoding/json"
21+
"strings"
22+
)
23+
24+
// ParamType indicates the type of an input parameter;
25+
// Used to distinguish between a single string and an array of strings.
26+
type ParamType string
27+
28+
// Valid ParamTypes:
29+
const (
30+
ParamTypeString ParamType = "string"
31+
ParamTypeArray ParamType = "array"
32+
ParamTypeObject ParamType = "object"
33+
)
34+
35+
// AllParamTypes can be used for ParamType validation.
36+
var AllParamTypes = []ParamType{ParamTypeString, ParamTypeArray, ParamTypeObject}
37+
38+
// ParamValues is modeled after IntOrString in kubernetes/apimachinery:
39+
40+
// ParamValue is a type that can hold a single string, string array, or string map.
41+
// Used in JSON unmarshalling so that a single JSON field can accept
42+
// either an individual string or an array of strings.
43+
type ParamValue struct {
44+
Type ParamType // Represents the stored type of ParamValues.
45+
StringVal string
46+
// +listType=atomic
47+
ArrayVal []string
48+
ObjectVal map[string]string
49+
}
50+
51+
// PropertySpec defines the struct for object keys
52+
type PropertySpec struct {
53+
Type ParamType `json:"type,omitempty"`
54+
}
55+
56+
// ParamsPrefix is the prefix used in $(...) expressions referring to parameters
57+
const ParamsPrefix = "params"
58+
59+
// ArrayReference returns the name of the parameter from array parameter reference
60+
// returns arrayParam from $(params.arrayParam[*])
61+
func ArrayReference(a string) string {
62+
return strings.TrimSuffix(strings.TrimPrefix(a, "$("+ParamsPrefix+"."), "[*])")
63+
}
64+
65+
// UnmarshalJSON implements the json.Unmarshaller interface.
66+
func (paramValues *ParamValue) UnmarshalJSON(value []byte) error {
67+
// ParamValues is used for Results Value as well, the results can be any kind of
68+
// data so we need to check if it is empty.
69+
if len(value) == 0 {
70+
paramValues.Type = ParamTypeString
71+
return nil
72+
}
73+
if value[0] == '[' {
74+
// We're trying to Unmarshal to []string, but for cases like []int or other types
75+
// of nested array which we don't support yet, we should continue and Unmarshal
76+
// it to String. If the Type being set doesn't match what it actually should be,
77+
// it will be captured by validation in reconciler.
78+
// if failed to unmarshal to array, we will convert the value to string and marshal it to string
79+
var a []string
80+
if err := json.Unmarshal(value, &a); err == nil {
81+
paramValues.Type = ParamTypeArray
82+
paramValues.ArrayVal = a
83+
return nil
84+
}
85+
}
86+
if value[0] == '{' {
87+
// if failed to unmarshal to map, we will convert the value to string and marshal it to string
88+
var m map[string]string
89+
if err := json.Unmarshal(value, &m); err == nil {
90+
paramValues.Type = ParamTypeObject
91+
paramValues.ObjectVal = m
92+
return nil
93+
}
94+
}
95+
96+
// By default we unmarshal to string
97+
paramValues.Type = ParamTypeString
98+
if err := json.Unmarshal(value, &paramValues.StringVal); err == nil {
99+
return nil
100+
}
101+
paramValues.StringVal = string(value)
102+
103+
return nil
104+
}
+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
Copyright 2025 The Tekton Authors
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package types
15+
16+
import "strings"
17+
18+
// TaskResult used to describe the results of a task
19+
type TaskResult struct {
20+
// Name the given name
21+
Name string `json:"name"`
22+
23+
// Type is the user-specified type of the result. The possible type
24+
// is currently "string" and will support "array" in following work.
25+
// +optional
26+
Type ResultsType `json:"type,omitempty"`
27+
28+
// Properties is the JSON Schema properties to support key-value pairs results.
29+
// +optional
30+
Properties map[string]PropertySpec `json:"properties,omitempty"`
31+
32+
// Description is a human-readable description of the result
33+
// +optional
34+
Description string `json:"description,omitempty"`
35+
36+
// Value the expression used to retrieve the value of the result from an underlying Step.
37+
// +optional
38+
Value *ResultValue `json:"value,omitempty"`
39+
}
40+
41+
// StepResult used to describe the Results of a Step.
42+
//
43+
// This is field is at an BETA stability level and gated by "enable-step-actions" feature flag.
44+
type StepResult struct {
45+
// Name the given name
46+
Name string `json:"name"`
47+
48+
// The possible types are 'string', 'array', and 'object', with 'string' as the default.
49+
// +optional
50+
Type ResultsType `json:"type,omitempty"`
51+
52+
// Properties is the JSON Schema properties to support key-value pairs results.
53+
// +optional
54+
Properties map[string]PropertySpec `json:"properties,omitempty"`
55+
56+
// Description is a human-readable description of the result
57+
// +optional
58+
Description string `json:"description,omitempty"`
59+
}
60+
61+
// TaskRunResult used to describe the results of a task
62+
type TaskRunResult struct {
63+
// Name the given name
64+
Name string `json:"name"`
65+
66+
// Type is the user-specified type of the result. The possible type
67+
// is currently "string" and will support "array" in following work.
68+
// +optional
69+
Type ResultsType `json:"type,omitempty"`
70+
71+
// Value the given value of the result
72+
Value ResultValue `json:"value"`
73+
}
74+
75+
// TaskRunStepResult is a type alias of TaskRunResult
76+
type TaskRunStepResult = TaskRunResult
77+
78+
// ResultValue is a type alias of ParamValue
79+
type ResultValue = ParamValue
80+
81+
// ResultsType indicates the type of a result;
82+
// Used to distinguish between a single string and an array of strings.
83+
// Note that there is ResultType used to find out whether a
84+
// RunResult is from a task result or not, which is different from
85+
// this ResultsType.
86+
type ResultsType string
87+
88+
// Valid ResultsType:
89+
const (
90+
ResultsTypeString ResultsType = "string"
91+
ResultsTypeArray ResultsType = "array"
92+
ResultsTypeObject ResultsType = "object"
93+
)
94+
95+
// AllResultsTypes can be used for ResultsTypes validation.
96+
var AllResultsTypes = []ResultsType{ResultsTypeString, ResultsTypeArray, ResultsTypeObject}
97+
98+
// ResultsArrayReference returns the reference of the result. e.g. results.resultname from $(results.resultname[*])
99+
func ResultsArrayReference(a string) string {
100+
return strings.TrimSuffix(strings.TrimSuffix(strings.TrimPrefix(a, "$("), ")"), "[*]")
101+
}

0 commit comments

Comments
 (0)