after/before workflow fixed
This commit is contained in:
parent
965081e440
commit
51238900af
|
@ -81,7 +81,7 @@ func (p *Project) goRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
|
||||||
log.Println(p.pname(p.Name, 3), ":", p.Blue.Regular(output.Text()))
|
log.Println(p.pname(p.Name, 3), ":", p.Blue.Regular(output.Text()))
|
||||||
}
|
}
|
||||||
if p.File.Streams {
|
if p.File.Streams {
|
||||||
f := p.Create(p.base, p.parent.Resources.Output)
|
f := p.Create(p.base, p.parent.Resources.Streams)
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + output.Text() + "\r\n"); err != nil {
|
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + output.Text() + "\r\n"); err != nil {
|
||||||
p.Fatal(err, "")
|
p.Fatal(err, "")
|
||||||
|
@ -94,7 +94,6 @@ func (p *Project) goRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
|
||||||
p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "Started"})
|
p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "Started"})
|
||||||
go scanner(stopOutput, execOutput, false)
|
go scanner(stopOutput, execOutput, false)
|
||||||
go scanner(stopError, execError, true)
|
go scanner(stopError, execError, true)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-channel:
|
case <-channel:
|
||||||
|
@ -159,25 +158,26 @@ func (p *Project) goTools(dir string, name string, cmd ...string) (string, error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cmds exec a list of defined commands
|
// Cmds exec a list of defined commands
|
||||||
func (p *Project) cmds(cmds []string) (errors []string) {
|
func (p *Project) afterBefore(command string) (errors string, logs string) {
|
||||||
defer func() {
|
defer func() {
|
||||||
p.sync()
|
p.sync()
|
||||||
}()
|
}()
|
||||||
for _, cmd := range cmds {
|
var stdout bytes.Buffer
|
||||||
var out bytes.Buffer
|
|
||||||
var stderr bytes.Buffer
|
var stderr bytes.Buffer
|
||||||
cmd := strings.Replace(strings.Replace(cmd, "'", "", -1), "\"", "", -1)
|
command = strings.Replace(strings.Replace(command, "'", "", -1), "\"", "", -1)
|
||||||
c := strings.Split(cmd, " ")
|
c := strings.Split(command, " ")
|
||||||
build := exec.Command(c[0], c[1:]...)
|
build := exec.Command(c[0], c[1:]...)
|
||||||
build.Dir = p.base
|
build.Dir = p.base
|
||||||
build.Stdout = &out
|
build.Stdout = &stdout
|
||||||
build.Stderr = &stderr
|
build.Stderr = &stderr
|
||||||
if err := build.Run(); err != nil {
|
err := build.Run()
|
||||||
errors = append(errors, stderr.String())
|
// check if log
|
||||||
return errors
|
logs = stdout.String()
|
||||||
|
if err != nil {
|
||||||
|
errors = stderr.String()
|
||||||
|
return errors, logs
|
||||||
}
|
}
|
||||||
}
|
return "", logs
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync datas with the web server
|
// Sync datas with the web server
|
||||||
|
|
|
@ -83,11 +83,12 @@ func (p *Project) watching() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Install calls an implementation of "go install"
|
// Install calls an implementation of "go install"
|
||||||
func (p *Project) install() {
|
func (p *Project) install() error {
|
||||||
if p.Bin {
|
if p.Bin {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log.Println(p.pname(p.Name, 1), ":", "Installing..")
|
log.Println(p.pname(p.Name, 1), ":", "Installing..")
|
||||||
if stream, err := p.goInstall(); err != nil {
|
stream, err := p.goInstall()
|
||||||
|
if err != nil {
|
||||||
msg := fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Install"), p.Red.Regular(err.Error()))
|
msg := fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Install"), p.Red.Regular(err.Error()))
|
||||||
out := BufferOut{Time: time.Now(), Text: err.Error(), Type: "Go Install", Stream: stream}
|
out := BufferOut{Time: time.Now(), Text: err.Error(), Type: "Go Install", Stream: stream}
|
||||||
p.print("error", out, msg, stream)
|
p.print("error", out, msg, stream)
|
||||||
|
@ -97,8 +98,9 @@ func (p *Project) install() {
|
||||||
p.print("log", out, msg, stream)
|
p.print("log", out, msg, stream)
|
||||||
}
|
}
|
||||||
p.sync()
|
p.sync()
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Install calls an implementation of "go run"
|
// Install calls an implementation of "go run"
|
||||||
|
@ -121,11 +123,12 @@ func (p *Project) run(channel chan bool, wr *sync.WaitGroup) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build calls an implementation of the "go build"
|
// Build calls an implementation of the "go build"
|
||||||
func (p *Project) build() {
|
func (p *Project) build() error {
|
||||||
if p.Build {
|
if p.Build {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log.Println(p.pname(p.Name, 1), ":", "Building..")
|
log.Println(p.pname(p.Name, 1), ":", "Building..")
|
||||||
if stream, err := p.goBuild(); err != nil {
|
stream, err := p.goBuild()
|
||||||
|
if err != nil {
|
||||||
msg := fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Build"), p.Red.Regular(err.Error()))
|
msg := fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Build"), p.Red.Regular(err.Error()))
|
||||||
out := BufferOut{Time: time.Now(), Text: err.Error(), Type: "Go Build", Stream: stream}
|
out := BufferOut{Time: time.Now(), Text: err.Error(), Type: "Go Build", Stream: stream}
|
||||||
p.print("error", out, msg, stream)
|
p.print("error", out, msg, stream)
|
||||||
|
@ -135,8 +138,9 @@ func (p *Project) build() {
|
||||||
p.print("log", out, msg, stream)
|
p.print("log", out, msg, stream)
|
||||||
}
|
}
|
||||||
p.sync()
|
p.sync()
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fmt calls an implementation of the "go fmt"
|
// Fmt calls an implementation of the "go fmt"
|
||||||
|
@ -192,12 +196,26 @@ func (p *Project) cmd(exit chan bool) {
|
||||||
c := make(chan os.Signal, 2)
|
c := make(chan os.Signal, 2)
|
||||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
cast := func(commands []string) {
|
cast := func(commands []string) {
|
||||||
if errs := p.cmds(commands); errs != nil {
|
for _, command := range commands {
|
||||||
for _, err := range errs {
|
errors, logs := p.afterBefore(command)
|
||||||
msg := fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold(err))
|
msg := fmt.Sprintln(p.pname(p.Name, 5), ":", p.Green.Bold("Command"), p.Green.Bold("\"")+command+p.Green.Bold("\""))
|
||||||
out := BufferOut{Time: time.Now(), Text: err, Type: "After/Before"}
|
out := BufferOut{Time: time.Now(), Text: command, Type: "After/Before"}
|
||||||
|
if logs != "" {
|
||||||
|
p.print("log", out, msg, "")
|
||||||
|
}
|
||||||
|
if errors != "" {
|
||||||
p.print("error", out, msg, "")
|
p.print("error", out, msg, "")
|
||||||
}
|
}
|
||||||
|
if logs != "" {
|
||||||
|
msg = fmt.Sprintln(logs)
|
||||||
|
out = BufferOut{Time: time.Now(), Text: logs, Type: "After/Before"}
|
||||||
|
p.print("log", out, "", msg)
|
||||||
|
}
|
||||||
|
if errors != "" {
|
||||||
|
msg = fmt.Sprintln(p.Red.Regular(errors))
|
||||||
|
out = BufferOut{Time: time.Now(), Text: errors, Type: "After/Before"}
|
||||||
|
p.print("error", out, "", msg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,10 +296,12 @@ func (p *Project) ignore(str string) bool {
|
||||||
|
|
||||||
// Routines launches the toolchain run, build, install
|
// Routines launches the toolchain run, build, install
|
||||||
func (p *Project) routines(channel chan bool, wr *sync.WaitGroup) {
|
func (p *Project) routines(channel chan bool, wr *sync.WaitGroup) {
|
||||||
p.install()
|
install := p.install()
|
||||||
p.build()
|
build := p.build()
|
||||||
wr.Add(1)
|
wr.Add(1)
|
||||||
|
if install == nil && build == nil {
|
||||||
go p.run(channel, wr)
|
go p.run(channel, wr)
|
||||||
|
}
|
||||||
wr.Wait()
|
wr.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,34 +333,36 @@ func (p *Project) print(t string, o BufferOut, msg string, stream string) {
|
||||||
case "out":
|
case "out":
|
||||||
p.Buffer.StdOut = append(p.Buffer.StdOut, o)
|
p.Buffer.StdOut = append(p.Buffer.StdOut, o)
|
||||||
if p.File.Streams {
|
if p.File.Streams {
|
||||||
f := p.Create(p.base, p.parent.Resources.Output)
|
f := p.Create(p.base, p.parent.Resources.Streams)
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil {
|
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + strings.ToUpper(" "+p.Name) + " : " + o.Text + "\r\n"); err != nil {
|
||||||
p.Fatal(err, "")
|
p.Fatal(err, "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "log":
|
case "log":
|
||||||
p.Buffer.StdLog = append(p.Buffer.StdLog, o)
|
p.Buffer.StdLog = append(p.Buffer.StdLog, o)
|
||||||
if p.File.Logs {
|
if p.File.Logs {
|
||||||
f := p.Create(p.base, p.parent.Resources.Log)
|
f := p.Create(p.base, p.parent.Resources.Logs)
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil {
|
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + strings.ToUpper(" "+p.Name) + " : " + o.Text + "\r\n"); err != nil {
|
||||||
p.Fatal(err, "")
|
p.Fatal(err, "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "error":
|
case "error":
|
||||||
p.Buffer.StdErr = append(p.Buffer.StdErr, o)
|
p.Buffer.StdErr = append(p.Buffer.StdErr, o)
|
||||||
if p.File.Errors {
|
if p.File.Errors {
|
||||||
f := p.Create(p.base, p.parent.Resources.Log)
|
f := p.Create(p.base, p.parent.Resources.Errors)
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil {
|
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + strings.ToUpper(" "+p.Name) + " : " + o.Text + "\r\n"); err != nil {
|
||||||
p.Fatal(err, "")
|
p.Fatal(err, "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if msg != "" {
|
||||||
log.Print(msg)
|
log.Print(msg)
|
||||||
|
}
|
||||||
if stream != "" {
|
if stream != "" {
|
||||||
fmt.Println(stream)
|
fmt.Print(stream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue