From 5e8da52af50e1cd659a3c7998a672ee5e491bab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sun, 27 Aug 2023 19:27:28 +0200 Subject: [PATCH] Add post-run-command notify implementation for windows Requires notify-send.exe: http://vaskovsky.net/notify-send --- contrib/notify/notify_windows.go | 60 ++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 contrib/notify/notify_windows.go diff --git a/contrib/notify/notify_windows.go b/contrib/notify/notify_windows.go new file mode 100644 index 00000000..bf508c38 --- /dev/null +++ b/contrib/notify/notify_windows.go @@ -0,0 +1,60 @@ +package main + +import ( + "fmt" + "log" + "os" + "os/exec" + "strconv" +) + +func main() { + total := envInt("TOTAL") + skipped := envInt("SKIPPED") + failed := envInt("FAILED") + errors := envInt("ERRORS") + + icon := "info" // Info 🛈 + title := "Passed" + switch { + case errors > 0: + icon = "error" // Error ⮾ + title = "Errored" + case failed > 0: + icon = "important" // Warning ⚠ + title = "Failed" + case skipped > 0: + title = "Passed with skipped" + } + + subtitle := fmt.Sprintf("%d Tests Run", total) + if errors > 0 { + subtitle += fmt.Sprintf(", %d Errored", errors) + } + if failed > 0 { + subtitle += fmt.Sprintf(", %d Failed", failed) + } + if skipped > 0 { + subtitle += fmt.Sprintf(", %d Skipped", skipped) + } + + args := []string{ + "-i", icon, + title, + subtitle, + } + log.Printf("notify-send %#v", args) + err := exec.Command("notify-send.exe", args...).Run() + if err != nil { + log.Fatalf("Failed to exec: %v", err) + } +} + +func envInt(name string) int { + val := os.Getenv("TESTS_" + name) + n, err := strconv.Atoi(val) + if err != nil { + return 0 + } + return n +}