main.go 803 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "io"
  6. "os"
  7. )
  8. func run(proj string, out io.Writer) error {
  9. if proj == "" {
  10. return fmt.Errorf("project directory is required: %w", ErrValidation)
  11. }
  12. pipeline := make([]step, 2)
  13. pipeline[0] = newStep(
  14. "go build",
  15. "Go Build: SUCCESS",
  16. proj,
  17. "go",
  18. []string{"build", ".", "errors"},
  19. )
  20. pipeline[1] = newStep(
  21. "go test",
  22. "Go Test: SUCCESS",
  23. proj,
  24. "go",
  25. []string{"test", "-v"},
  26. )
  27. for _, s := range pipeline {
  28. msg, err := s.execute()
  29. if err != nil {
  30. return err
  31. }
  32. _, err = fmt.Fprintln(out, msg)
  33. if err != nil {
  34. return err
  35. }
  36. }
  37. return nil
  38. }
  39. func main() {
  40. proj := flag.String("p", "", "Project directory")
  41. flag.Parse()
  42. if err := run(*proj, os.Stdout); err != nil {
  43. _, _ = fmt.Fprintln(os.Stderr, err)
  44. os.Exit(1)
  45. }
  46. }