1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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.
// Runs sequentially to ensure build completes before deploy.
func Openbsd() error {
if err := BuildOpenbsd(); err != nil {
return err
}
return DeployOpenbsd()
}
// BuildOpenbsd builds the gogios binary for OpenBSD.
func BuildOpenbsd() error {
fmt.Println("Building for OpenBSD...")
env := os.Environ()
env = append(env, "GOOS=openbsd", "GOARCH=amd64")
cmd := exec.Command("go", "build", "-o", "gogios", "cmd/gogios/main.go")
cmd.Env = env
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()
}
|