|
|
@@ -5,26 +5,39 @@ import (
|
|
|
"fmt"
|
|
|
"io"
|
|
|
"os"
|
|
|
- "os/exec"
|
|
|
)
|
|
|
|
|
|
func run(proj string, out io.Writer) error {
|
|
|
if proj == "" {
|
|
|
return fmt.Errorf("project directory is required: %w", ErrValidation)
|
|
|
}
|
|
|
+ pipeline := make([]step, 2)
|
|
|
+ pipeline[0] = newStep(
|
|
|
+ "go build",
|
|
|
+ "Go Build: SUCCESS",
|
|
|
+ proj,
|
|
|
+ "go",
|
|
|
+ []string{"build", ".", "errors"},
|
|
|
+ )
|
|
|
+ pipeline[1] = newStep(
|
|
|
+ "go test",
|
|
|
+ "Go Test: SUCCESS",
|
|
|
+ proj,
|
|
|
+ "go",
|
|
|
+ []string{"test", "-v"},
|
|
|
+ )
|
|
|
|
|
|
- args := []string{"build", ".", "errors"}
|
|
|
- cmd := exec.Command("go", args...)
|
|
|
- cmd.Dir = proj
|
|
|
- if err := cmd.Run(); err != nil {
|
|
|
- return &stepErr{
|
|
|
- step: "go build",
|
|
|
- msg: "go build failed",
|
|
|
- cause: err,
|
|
|
+ for _, s := range pipeline {
|
|
|
+ msg, err := s.execute()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ _, err = fmt.Fprintln(out, msg)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
}
|
|
|
}
|
|
|
- _, err := fmt.Fprintln(out, "Go Build: SUCCESS")
|
|
|
- return err
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
func main() {
|