summaryrefslogtreecommitdiff
path: root/Magefile.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-10-27 23:36:49 +0200
committerPaul Buetow <paul@buetow.org>2025-10-27 23:36:49 +0200
commit81d1550df55318beff8e9f762952a33daaa7c0cf (patch)
tree897e3c044c8e3bf5c9d71d98345fde9a645e8c7a /Magefile.go
parent6352e8c33c1c22af382093d406d477d1530950db (diff)
feat: Add randomSpread and RunInterval to checks
This commit introduces two new optional parameters to the check configuration: - `randomSpread`: This parameter allows specifying a random sleep time up to N seconds before a check is executed. This is useful to avoid all checks running at the same time. - `RunInterval`: This parameter defines the minimum interval in seconds between two executions of a check. This is useful if gogios is run more frequently than a specific check should be. The `README.md` has been updated to document these new features. fix: Fix deadlock when skipping checks This commit also fixes a deadlock that occurred when a check was skipped due to the `RunInterval` setting. The `inputWg.Done()` was not being called, causing the main goroutine to wait forever. build: Replace Taskfile with Magefile The `Taskfile.yml` has been replaced with a `Magefile.go` to manage the build process. This provides more flexibility and is more idiomatic for Go projects.
Diffstat (limited to 'Magefile.go')
-rw-r--r--Magefile.go105
1 files changed, 105 insertions, 0 deletions
diff --git a/Magefile.go b/Magefile.go
new file mode 100644
index 0000000..dc7d90b
--- /dev/null
+++ b/Magefile.go
@@ -0,0 +1,105 @@
+//go:build mage
+// +build mage
+
+package main
+
+import (
+ "fmt"
+ "os"
+ "os/exec"
+
+ "github.com/magefile/mage/mg"
+)
+
+// Build builds the gogios binary.
+func Build() error {
+ fmt.Println("Building...")
+ cmd := exec.Command("go", "build", "-o", "gogios", "cmd/gogios/main.go")
+ cmd.Stdout = os.Stdout
+ cmd.Stderr = os.Stderr
+ return cmd.Run()
+}
+
+// Dev builds the gogios binary with race detection.
+func Dev() error {
+ mg.Deps(Vet, Lint)
+ fmt.Println("Building with race detector...")
+ cmd := exec.Command("go", "build", "-race", "-o", "gogios", "cmd/gogios/main.go")
+ cmd.Stdout = os.Stdout
+ cmd.Stderr = os.Stderr
+ return cmd.Run()
+}
+
+// Vet runs go vet on all go files.
+func Vet() error {
+ fmt.Println("Vetting...")
+ cmd := exec.Command("go", "vet", "./...")
+ cmd.Stdout = os.Stdout
+ cmd.Stderr = os.Stderr
+ return cmd.Run()
+}
+
+// Lint runs golangci-lint.
+func Lint() error {
+ fmt.Println("Linting...")
+ cmd := exec.Command("golangci-lint", "run")
+ cmd.Stdout = os.Stdout
+ cmd.Stderr = os.Stderr
+ return cmd.Run()
+}
+
+// LintInstall installs golangci-lint.
+func LintInstall() error {
+ fmt.Println("Installing golangci-lint...")
+ cmd := exec.Command("go", "install", "github.com/golangci/golangci-lint/cmd/golangci-lint@latest")
+ cmd.Stdout = os.Stdout
+ cmd.Stderr = os.Stderr
+ return cmd.Run()
+}
+
+// Test runs all unit tests.
+func Test() error {
+ fmt.Println("Cleaning test cache...")
+ cleanCmd := exec.Command("go", "clean", "-testcache")
+ cleanCmd.Stdout = os.Stdout
+ cleanCmd.Stderr = os.Stderr
+ if err := cleanCmd.Run(); err != nil {
+ return err
+ }
+
+ fmt.Println("Running tests...")
+ testCmd := exec.Command("go", "test", "./...")
+ testCmd.Stdout = os.Stdout
+ testCmd.Stderr = os.Stderr
+ return testCmd.Run()
+}
+
+// Openbsd builds and deploys the gogios binary for OpenBSD.
+func Openbsd() error {
+ mg.Deps(BuildOpenbsd, DeployOpenbsd)
+ return nil
+}
+
+// BuildOpenbsd builds the gogios binary for OpenBSD.
+func BuildOpenbsd() error {
+ fmt.Println("Building for OpenBSD...")
+ if err := os.Setenv("GOOS", "openbsd"); err != nil {
+ return err
+ }
+ if err := os.Setenv("GOARCH", "amd64"); err != nil {
+ return err
+ }
+ cmd := exec.Command("go", "build", "-o", "gogios", "cmd/gogios/main.go")
+ cmd.Stdout = os.Stdout
+ cmd.Stderr = os.Stderr
+ return cmd.Run()
+}
+
+// DeployOpenbsd copies the gogios binary for OpenBSD.
+func DeployOpenbsd() error {
+ fmt.Println("Copying binary...")
+ cpCmd := exec.Command("cp", "gogios", "/home/paul/git/conf/frontends/usr/local/bin/gogios")
+ cpCmd.Stdout = os.Stdout
+ cpCmd.Stderr = os.Stderr
+ return cpCmd.Run()
+}