mirror of
https://github.com/beego/bee.git
synced 2024-11-22 15:10:54 +00:00
Merge pull request #368 from sergeylanzman/add-notify-on-faild-build
add notify on build fail
This commit is contained in:
commit
0e79cb596e
@ -178,6 +178,7 @@ func AutoBuild(files []string, isgenerate bool) {
|
|||||||
icmd.Env = append(os.Environ(), "GOGC=off")
|
icmd.Env = append(os.Environ(), "GOGC=off")
|
||||||
err = icmd.Run()
|
err = icmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
utils.Notify("", "Failed to generate the docs.")
|
||||||
beeLogger.Log.Errorf("Failed to generate the docs.")
|
beeLogger.Log.Errorf("Failed to generate the docs.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -202,6 +203,7 @@ func AutoBuild(files []string, isgenerate bool) {
|
|||||||
bcmd.Stderr = &stderr
|
bcmd.Stderr = &stderr
|
||||||
err = bcmd.Run()
|
err = bcmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
utils.Notify(stderr.String(), "Build Failed")
|
||||||
beeLogger.Log.Errorf("Failed to build the application: %s", stderr.String())
|
beeLogger.Log.Errorf("Failed to build the application: %s", stderr.String())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,9 @@ var defaultConf = `{
|
|||||||
"database": {
|
"database": {
|
||||||
"driver": "mysql"
|
"driver": "mysql"
|
||||||
},
|
},
|
||||||
"enable_reload": false
|
"enable_reload": false,
|
||||||
|
"enable_notification": true
|
||||||
|
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
var Conf struct {
|
var Conf struct {
|
||||||
@ -77,7 +79,8 @@ var Conf struct {
|
|||||||
Driver string
|
Driver string
|
||||||
Conn string
|
Conn string
|
||||||
}
|
}
|
||||||
EnableReload bool `json:"enable_reload" yaml:"enable_reload"`
|
EnableReload bool `json:"enable_reload" yaml:"enable_reload"`
|
||||||
|
EnableNotification bool `json:"enable_notification" yaml:"enable_notification"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
75
utils/notification.go
Normal file
75
utils/notification.go
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"runtime"
|
||||||
|
|
||||||
|
"github.com/beego/bee/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
const appName = "Beego"
|
||||||
|
|
||||||
|
func Notify(text, title string) {
|
||||||
|
if !config.Conf.EnableNotification {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "darwin":
|
||||||
|
osxNotify(text, title)
|
||||||
|
case "linux":
|
||||||
|
windowsNotify(text, title)
|
||||||
|
case "windows":
|
||||||
|
linuxNotify(text, title)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func osxNotify(text, title string) {
|
||||||
|
cmd := &exec.Cmd{}
|
||||||
|
if existTerminalNotifier() {
|
||||||
|
cmd = exec.Command("terminal-notifier", "-title", appName, "-message", text, "-subtitle", title)
|
||||||
|
} else if MacOSVersionSupport() {
|
||||||
|
notification := fmt.Sprintf("display notification \"%s\" with title \"%s\" subtitle \"%s\"", text, appName, title)
|
||||||
|
cmd = exec.Command("osascript", "-e", notification)
|
||||||
|
} else {
|
||||||
|
cmd = exec.Command("growlnotify", "-n", appName, "-m", title)
|
||||||
|
}
|
||||||
|
cmd.Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
func windowsNotify(text, title string) {
|
||||||
|
exec.Command("growlnotify", "/i:", "", "/t:", title, text).Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
func linuxNotify(text, title string) {
|
||||||
|
exec.Command("notify-send", "-i", "", title, text)
|
||||||
|
}
|
||||||
|
|
||||||
|
func existTerminalNotifier() bool {
|
||||||
|
cmd := exec.Command("which", "terminal-notifier")
|
||||||
|
err := cmd.Start()
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
err = cmd.Wait()
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func MacOSVersionSupport() bool {
|
||||||
|
cmd := exec.Command("sw_vers", "-productVersion")
|
||||||
|
check, _ := cmd.Output()
|
||||||
|
version := strings.Split(string(check), ".")
|
||||||
|
major, _ := strconv.Atoi(version[0])
|
||||||
|
minor, _ := strconv.Atoi(version[1])
|
||||||
|
if major < 10 || (major == 10 && minor < 9) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user