bugfix: Fixed unusual issues that slipped through with shellAfterCompleted (#425)

* bugfix: Fixed unusual issues that slipped through with shellAfterCompleted #419 #420

* cicd: Fix broken style lint
This commit is contained in:
James Read 2024-10-11 00:15:03 +01:00 committed by GitHub
parent 5d82ae7680
commit 6c289506c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 46 additions and 23 deletions

View File

@ -23,35 +23,51 @@ var (
}
)
func parseCommandForReplacements(rawShellCommand string, values map[string]string) (string, map[string]string, error) {
r := regexp.MustCompile("{{ *?([a-zA-Z0-9_]+?) *?}}")
foundArgumentNames := r.FindAllStringSubmatch(rawShellCommand, -1)
usedArguments := make(map[string]string)
for _, match := range foundArgumentNames {
argName := match[1]
argValue, argProvided := values[argName]
if !argProvided {
return "", nil, errors.New("Required arg not provided: " + argName)
}
usedArguments[argName] = argValue
rawShellCommand = strings.ReplaceAll(rawShellCommand, match[0], argValue)
}
return rawShellCommand, usedArguments, nil
}
func parseActionArguments(rawShellCommand string, values map[string]string, action *config.Action, actionTitle string, entityPrefix string) (string, error) {
log.WithFields(log.Fields{
"actionTitle": actionTitle,
"cmd": rawShellCommand,
}).Infof("Action parse args - Before")
r := regexp.MustCompile("{{ *?([a-zA-Z0-9_]+?) *?}}")
matches := r.FindAllStringSubmatch(rawShellCommand, -1)
rawShellCommand, usedArgs, err := parseCommandForReplacements(rawShellCommand, values)
for _, match := range matches {
argValue, argProvided := values[match[1]]
if err != nil {
return "", err
}
if !argProvided {
log.Infof("%v", values)
return "", errors.New("Required arg not provided: " + match[1])
}
err := typecheckActionArgument(match[1], argValue, action)
for argName, argValue := range usedArgs {
err := typecheckActionArgument(argName, argValue, action)
if err != nil {
return "", err
}
log.WithFields(log.Fields{
"name": match[1],
"name": argName,
"value": argValue,
}).Debugf("Arg assigned")
rawShellCommand = strings.ReplaceAll(rawShellCommand, match[0], argValue)
}
rawShellCommand = sv.ReplaceEntityVars(entityPrefix, rawShellCommand)

View File

@ -528,7 +528,14 @@ func stepExecAfter(req *ExecutionRequest) bool {
"exitCode": fmt.Sprintf("%v", req.logEntry.ExitCode),
}
finalParsedCommand, _ := parseActionArguments(req.Action.ShellAfterCompleted, args, req.Action, req.logEntry.ActionTitle, req.EntityPrefix)
finalParsedCommand, _, err := parseCommandForReplacements(req.Action.ShellAfterCompleted, args)
if err != nil {
msg := "Could not prepare shellAfterCompleted command: " + err.Error() + "\n"
req.logEntry.Output += msg
log.Warnf(msg)
return true
}
cmd := wrapCommandInShell(ctx, finalParsedCommand)
cmd.Stdout = &stdout
@ -538,14 +545,14 @@ func stepExecAfter(req *ExecutionRequest) bool {
waiterr := cmd.Wait()
req.logEntry.Output += "\n" + stdout.String()
req.logEntry.Output += "OliveTin::shellAfterCompleted stdout\n" + stdout.String()
req.logEntry.Output += "\n"
req.logEntry.Output += "OliveTin::shellAfterCompleted stdout\n"
req.logEntry.Output += stdout.String()
req.logEntry.Output += "OliveTin::shellAfterCompleted stderr\n" + stdout.String()
req.logEntry.Output += "OliveTin::shellAfterCompleted stderr\n"
req.logEntry.Output += stderr.String()
req.logEntry.Output += "OliveTin::shellAfterCompleted errors and summary\n" + stdout.String()
req.logEntry.Output += "OliveTin::shellAfterCompleted errors and summary\n"
appendErrorToStderr(runerr, req.logEntry)
appendErrorToStderr(waiterr, req.logEntry)
@ -555,7 +562,7 @@ func stepExecAfter(req *ExecutionRequest) bool {
req.logEntry.Output += fmt.Sprintf("Your shellAfterCompleted exited with code %v\n", cmd.ProcessState.ExitCode())
req.logEntry.Output += "OliveTin::shellAfterCompleted output complete\n" + stdout.String()
req.logEntry.Output += "OliveTin::shellAfterCompleted output complete\n"
return true
}

View File

@ -34,12 +34,12 @@ function createAnnotation (key, val) {
domAnnotation.appendChild(createElement('span', {
innerText: key,
classNames: ['annotationKey']
classNames: ['annotation-key']
}))
domAnnotation.appendChild(createElement('span', {
innerText: val,
classNames: ['annotationValue']
classNames: ['annotation-value']
}))
return domAnnotation

View File

@ -472,7 +472,7 @@ span.annotation {
margin-right: .2em;
}
span.annotationKey {
span.annotation-key {
padding: 0.4em;
border-radius: 0.4em 0 0 .4em;
display: inline-block;
@ -480,7 +480,7 @@ span.annotationKey {
color: #666;
}
span.annotationValue {
span.annotation-value {
padding: 0.4em;
border-radius: 0 .4em .4em 0;
display: inline-block;