Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
chitrangpatel committed Dec 14, 2023
1 parent af084a9 commit e2a3c2b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions pkg/apis/pipeline/v1/resultref.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,18 @@ func parseExpression(substitutionExpression string) (string, string, *int, strin
return "", "", nil, "", ParamTypeString, fmt.Errorf("must be one of the form 1). %q; 2). %q", resultExpressionFormat, objectResultExpressionFormat)
}

func parseTaskExpression(substitutionExpression string) (string, string, int, string, ParamType, error) {
func parseTaskExpression(substitutionExpression string) (string, string, *int, string, ParamType, error) {
if looksLikeResultRef(substitutionExpression) {
return parseExpression(substitutionExpression)
}
return "", "", 0, "", ParamTypeString, fmt.Errorf("must be one of the form 1). %q; 2). %q", resultExpressionFormat, objectResultExpressionFormat)
return "", "", nil, "", ParamTypeString, fmt.Errorf("must be one of the form 1). %q; 2). %q", resultExpressionFormat, objectResultExpressionFormat)
}

func ParseStepExpression(substitutionExpression string) (string, string, int, string, ParamType, error) {
func ParseStepExpression(substitutionExpression string) (string, string, *int, string, ParamType, error) {
if looksLikeStepResultRef(substitutionExpression) {
return parseExpression(substitutionExpression)
}
return "", "", 0, "", ParamTypeString, fmt.Errorf("must be one of the form 1). %q; 2). %q", resultExpressionFormat, objectResultExpressionFormat)
return "", "", nil, "", ParamTypeString, fmt.Errorf("must be one of the form 1). %q; 2). %q", resultExpressionFormat, objectResultExpressionFormat)
}

// ParseResultName parse the input string to extract resultName and result index.
Expand Down
20 changes: 10 additions & 10 deletions pkg/entrypoint/entrypointer.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,10 @@ func findReplacement(s string) (string, []string, error) {
if paramType == v1.ParamTypeObject && objectKey != "" {
replaceWithString = result.ObjectVal[objectKey]
} else if paramType == v1.ParamTypeArray {
if arrayIdx == -1 {
replaceWithArray = append(replaceWithArray, result.ArrayVal...)
if arrayIdx != nil {
replaceWithString = result.ArrayVal[*arrayIdx]
} else {
replaceWithString = result.ArrayVal[arrayIdx]
replaceWithArray = append(replaceWithArray, result.ArrayVal...)
}
} else {
replaceWithString = result.StringVal
Expand All @@ -391,7 +391,7 @@ func findReplacement(s string) (string, []string, error) {
}

// replaceCommandAndArgs performs replacements for step results in environment variables.
func replaceEnv() error {
func replaceEnv(stepResultRegex *regexp.Regexp) error {
for _, e := range os.Environ() {
pair := strings.SplitN(e, "=", 2)
matches := stepResultRegex.FindAllStringSubmatch(pair[1], -1)
Expand All @@ -410,7 +410,7 @@ func replaceEnv() error {
// It reads the original script file, performs the replacements and writes a new file
// since the original script location is unknown.
// It then updates the command to execute the new file.
func replaceScript(e *Entrypointer) error {
func replaceScript(e *Entrypointer, stepResultRegex *regexp.Regexp) error {
if strings.HasPrefix(e.Command[0], "/tekton/scripts") {
fileContentBytes, err := os.ReadFile(e.Command[0])
if err != nil {
Expand Down Expand Up @@ -440,9 +440,9 @@ func replaceScript(e *Entrypointer) error {
}

// replaceCommandAndArgs performs replacements for step results in e.Command
func replaceCommandAndArgs(command []string) ([]string, error) {
func replaceCommandAndArgs(command []string, stepResultRegex *regexp.Regexp) ([]string, error) {
newCommand := []string{}
for _, c := range e.Command {
for _, c := range command {
matches := stepResultRegex.FindAllStringSubmatch(c, -1)
if len(matches) > 0 {
for _, m := range matches {
Expand Down Expand Up @@ -472,15 +472,15 @@ func (e *Entrypointer) applyStepResultSubstitutions() error {
pattern := `\$\(steps\..*\.results\..*\)`
stepResultRegex := regexp.MustCompile(pattern)
// env
if err := replaceEnv(); err != nil {
if err := replaceEnv(stepResultRegex); err != nil {
return err
}
// script
if err := replaceScript(e); err != nil {
if err := replaceScript(e, stepResultRegex); err != nil {
return err
}
// command + args
newCommand, err := replaceCommandAndArgs(e.Command)
newCommand, err := replaceCommandAndArgs(e.Command, stepResultRegex)
if err != nil {
return err
}
Expand Down

0 comments on commit e2a3c2b

Please sign in to comment.