-
Notifications
You must be signed in to change notification settings - Fork 0
/
magefile.go
80 lines (67 loc) · 1.58 KB
/
magefile.go
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
//+build mage
package main
import (
"fmt"
"os"
"os/exec"
"github.com/julian7/goshipdone"
"github.com/julian7/sensulib/sensuasset"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
type Buildconf mg.Namespace
func step(name string) {
fmt.Printf("-----> %s\n", name)
}
// All builds for all possible targets
func All() error {
step("all")
sensuasset.Register()
if err := goshipdone.Run(os.Getenv("GOSHIPDONE_CONF")); err != nil {
return err
}
return nil
}
// Release builds and releases package
func Release() {
mg.SerialDeps(flagrel, All)
}
func flagrel() {
os.Setenv("SKIP_PUBLISH", "false")
}
func Official() {
os.Setenv("GOSHIPDONE_CONF", ".goshipdone.yml")
}
// Alltests runs all code checks
func Alltests() {
mg.SerialDeps(Lint, Test, Cover)
}
// Test runs all tests
func Test() error {
step("test")
return sh.RunV(mg.GoCmd(), "test", "./...")
}
// Lint tries to run golangci-lint, or golint. If neither of them are available,
// it runs go fmt and go vet instead.
func Lint() error {
step("lint")
if _, err := exec.LookPath("golangci-lint"); err == nil {
return sh.RunV("golangci-lint", "run", "-v", "./...")
}
if _, err := exec.LookPath("golint"); err == nil {
return sh.RunV("golint", "./...")
}
if err := sh.RunV(mg.GoCmd(), "fmt", "./..."); err != nil {
return err
}
return sh.RunV(mg.GoCmd(), "vet", "./...")
}
// Cover runs coverity profile
func Cover() error {
step("cover")
err := sh.RunV(mg.GoCmd(), "test", "-coverprofile", "sum.cov", "./...")
if err != nil {
return err
}
return sh.RunV(mg.GoCmd(), "tool", "cover", "-func", "sum.cov")
}