forked from LedgerHQ/satstack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmagefile.go
70 lines (55 loc) · 1.26 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
// +build mage
package main
import (
"os"
"github.com/magefile/mage/sh"
)
const (
entryPoint = "cmd/lss.go"
ldFlags = "-X '$PACKAGE/version.GitCommit=$COMMIT_HASH' " +
"-X '$PACKAGE/version.Build=$BUILD'"
)
// Allow user to override Go executable on UNIX-like systems.
var goexe = "go" // GOEXE=xxx mage build
func init() {
if exe := os.Getenv("GOEXE"); exe != "" {
goexe = exe
}
// We want to use Go 1.11 modules even if the source lives inside GOPATH.
// The default is "auto".
os.Setenv("GO111MODULE", "on")
}
// Build binary
func Build() error {
return sh.RunWith(flagEnv(), goexe, "build", "-ldflags", ldFlags,
entryPoint)
}
func Release() error {
os.Setenv("GIN_MODE", "release")
return Build()
}
// Run basic golangci-lint check.
func Lint() error {
linterArgs := []string{
"run",
"--disable-all",
"--enable=govet",
"--enable=gofmt",
}
if err := sh.Run("golangci-lint", linterArgs...); err != nil {
return err
}
return nil
}
func flagEnv() map[string]string {
hash, _ := sh.Output("git", "rev-parse", "--short", "HEAD")
build := "development"
if mode := os.Getenv("GIN_MODE"); mode == "release" {
build = "release"
}
return map[string]string{
"PACKAGE": "satstack",
"COMMIT_HASH": hash,
"BUILD": build,
}
}