Skip to content

Commit

Permalink
Merge pull request #125 from benbotwin/master
Browse files Browse the repository at this point in the history
Added push notifications when a build fails or finished
  • Loading branch information
ibash authored Oct 23, 2017
2 parents 9ba6991 + 582594a commit 0124369
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import (
shellwords "github.com/mattn/go-shellwords"
"gopkg.in/urfave/cli.v1"

"github.com/0xAX/notificator"
"log"
"os"
"os/signal"
"path/filepath"
"strconv"
"strings"
"syscall"
"time"
)
Expand All @@ -26,6 +28,7 @@ var (
colorGreen = string([]byte{27, 91, 57, 55, 59, 51, 50, 59, 49, 109})
colorRed = string([]byte{27, 91, 57, 55, 59, 51, 49, 59, 49, 109})
colorReset = string([]byte{27, 91, 48, 109})
notifier = notificator.New(notificator.Options{AppName: "Gin Build"})
)

func main() {
Expand Down Expand Up @@ -218,17 +221,25 @@ func EnvAction(c *cli.Context) {
func build(builder gin.Builder, runner gin.Runner, logger *log.Logger) {
logger.Println("Building...")

notifier.Push("Build Started!", "Building "+builder.Binary()+"...", "", notificator.UR_NORMAL)
err := builder.Build()
if err != nil {
buildError = err
logger.Printf("%sBuild failed%s\n", colorRed, colorReset)
fmt.Println(builder.Errors())
buildErrors := strings.Split(builder.Errors(), "\n")
if err := notifier.Push("Build FAILED!", buildErrors[1], "", notificator.UR_CRITICAL); err != nil {
logger.Println("Notification send failed")
}
} else {
buildError = nil
logger.Printf("%sBuild finished%s\n", colorGreen, colorReset)
if immediate {
runner.Run()
}
if err := notifier.Push("Build Succeded", "Build Finished!", "", notificator.UR_CRITICAL); err != nil {
logger.Println("Notification send failed")
}
}

time.Sleep(100 * time.Millisecond)
Expand Down
2 changes: 1 addition & 1 deletion wercker.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
box: wercker/golang@1.1.1
box: wercker/golang

0 comments on commit 0124369

Please sign in to comment.