-
Notifications
You must be signed in to change notification settings - Fork 15
/
magefile.go
80 lines (65 loc) · 1.29 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 (
"os"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
var (
Default = Build
targets = []string{"skinnyd", "skinnyctl"}
protos = []string{"lock", "consensus", "control"}
)
// Install build dependencies.
func BuildDeps() error {
err := sh.RunV("protoc", "--version")
if err != nil {
return err
}
err = sh.RunV("go", "get", "-u", "github.com/golang/protobuf/protoc-gen-go")
if err != nil {
return err
}
err = sh.RunV("go", "get", "-u", "google.golang.org/grpc")
if err != nil {
return err
}
return nil
}
// Install dependencies.
func Deps() error {
err := sh.RunV("go", "mod", "vendor")
if err != nil {
return err
}
return nil
}
// Generate code.
func Generate() error {
for _, name := range protos {
err := sh.RunV("protoc", "--go_out=plugins=grpc:.", "./proto/"+name+"/"+name+".proto")
if err != nil {
return err
}
}
return nil
}
// Run tests.
func Test() error {
mg.Deps(Generate)
return sh.RunV("go", "test", "-v", "./...")
}
// Build binary executables.
func Build() error {
for _, name := range targets {
err := sh.RunV("go", "build", "-v", "-o", "./bin/"+name, "./cmd/"+name)
if err != nil {
return err
}
}
return nil
}
// Remove binary executables.
func Clean() error {
return os.RemoveAll("bin")
}