Skip to content

Commit

Permalink
fix(2973): setup commands stuck with xterm (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yoshika authored Dec 28, 2023
1 parent ec83f2e commit 5f9a448
Showing 1 changed file with 11 additions and 33 deletions.
44 changes: 11 additions & 33 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,40 +104,15 @@ func copyLinesUntil(r io.Reader, w io.Writer, match string) (int, error) {
return ExitOk, nil
}

func doRunSetupCommand(emitter screwdriver.Emitter, f *os.File, r io.Reader, setupCommands []string) error {
var (
t string
err error
reader = bufio.NewReader(r)
reEcho = regexp.MustCompile("^$")
)

func doRunSetupCommand(guid string, emitter screwdriver.Emitter, f *os.File, r io.Reader, setupCommands []string) error {
shargs := strings.Join(setupCommands, " && ")

f.Write([]byte(shargs))

t, err = readln(reader)
for err == nil {
t = strings.TrimLeft(t, "# ")
t = strings.TrimLeft(t, "$ ")
echoCmd := reEcho.FindStringSubmatch(t)
if len(echoCmd) != 0 {
_, werr := fmt.Fprintln(emitter, t)
if werr != nil {
return fmt.Errorf("Error piping logs to emitter: %v", werr)
}
return nil
}
_, werr := fmt.Fprintln(emitter, t)
if werr != nil {
return fmt.Errorf("Error piping logs to emitter: %v", werr)
}
t, err = readln(reader)
}
if err != nil {
return fmt.Errorf("Error with reader: %v", err)
}
return nil
// ignore exit code in setup commands
_, err := copyLinesUntil(r, emitter, guid)

return err
}

func doRunCommand(guid, path string, emitter screwdriver.Emitter, f *os.File, fReader io.Reader, stepName string) (int, error) {
Expand Down Expand Up @@ -275,6 +250,9 @@ func Run(path string, env []string, emitter screwdriver.Emitter, build screwdriv
return fmt.Errorf("Cannot start shell: %v", err)
}

// Generate guid v4 for the setup commands
guid := uuid.Must(uuid.NewRandom()).String()

// Command to Export Env. Use tmpfile just in case export -p takes some time
exportEnvCmd :=
"tmpfile=" + tmpFile + "; exportfile=" + exportFile + "; " +
Expand All @@ -289,11 +267,11 @@ func Run(path string, env []string, emitter screwdriver.Emitter, build screwdriv
"EXITCODE=$?; " +
exportEnvCmd +
"echo $SD_STEP_ID $EXITCODE; }", //mv newfile to file
"trap finish ABRT EXIT;\necho ;\n",
"trap finish ABRT EXIT;echo " + guid + " $?\n",
}

setupReader := bufio.NewReader(f)
if err := doRunSetupCommand(emitter, f, setupReader, setupCommands); err != nil {
if err := doRunSetupCommand(guid, emitter, f, setupReader, setupCommands); err != nil {
return err
}

Expand Down Expand Up @@ -333,7 +311,7 @@ func Run(path string, env []string, emitter screwdriver.Emitter, build screwdriv
}

// Generate guid v4 for the step
guid := uuid.Must(uuid.NewRandom()).String()
guid = uuid.Must(uuid.NewRandom()).String()

runErr := make(chan error, 1)
eCode := make(chan int, 1)
Expand Down

0 comments on commit 5f9a448

Please sign in to comment.