-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathmagefile.go
63 lines (51 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
// +build mage
package main
import (
"fmt"
"runtime"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
// Build will build the basic magefile
func Build() error {
ldf, err := flags()
if err != nil {
return err
}
fmt.Println("go build -ldflags '" + ldf + "'")
err = sh.RunV("go", "build", "-ldflags", ldf)
if err != nil {
fmt.Println(`You may need to install libpcap.
OS X: brew install libpcap
Linux: apt-get install libpcap-dev
`)
}
return err
}
// Release will build and then tar a release
func Release() error {
mg.Deps(Build)
err := sh.RunV("tar", "-czvf", "find3-cli-scanner-"+runtime.GOOS+"-"+runtime.GOARCH+".tar.gz", "find3-cli-scanner", "README.md")
if err == nil {
fmt.Println("built", "find3-cli-scanner-"+runtime.GOOS+"-"+runtime.GOARCH+".tar.gz")
}
return err
}
var Default = Build
func flags() (string, error) {
tag := tag()
if tag == "" {
tag = "dev"
}
return fmt.Sprintf(`-s -w -X main.version=%s`, tag), nil
}
// tag returns the git tag for the current branch or "" if none.
func tag() string {
s, _ := sh.Output("git", "describe", "--tags")
return s
}
// hash returns the git hash for the current repo or "" if none.
func hash() string {
hash, _ := sh.Output("git", "rev-parse", "--short", "HEAD")
return hash
}