forked from 89luca89/lilipod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
magefile.go
86 lines (78 loc) · 2.08 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
81
82
83
84
85
86
//go:build mage
// +build mage
package main
import (
"github.com/magefile/mage/sh"
)
var Default = All
func All() {
Clean()
Pty()
Lilipod()
}
func Clean() error {
if err := sh.Rm("lilipod"); err != nil {
return err
}
if err := sh.Rm("pty"); err != nil {
return err
}
if err := sh.Rm("pty.tar.gz"); err != nil {
return err
}
return nil
}
func Lilipod() error {
if err := sh.Rm("lilipod"); err != nil {
return err
}
env := map[string]string{"CGO_ENABLED": "0"}
if err := sh.RunWith(env, "go", "build", "-mod", "vendor", "-ldflags=-s -w -X 'github.com/89luca89/lilipod/pkg/constants.Version=$${RELEASE_VERSION:-0.0.0}'", "-o", "lilipod", "main.go"); err != nil {
return err
}
return nil
}
func Coverage() error {
if err := sh.Rm("coverage/*"); err != nil {
return err
}
if err := sh.Run("mkdir", "-p", "coverage"); err != nil {
return err
}
env := map[string]string{"CGO_ENABLED": "0"}
if err := sh.RunWith(env, "go", "build", "-mod", "vendor", "-cover", "-o", "coverage/pty", "ptyagent/main.go", "ptyagent/pty.go"); err != nil {
return err
}
if err := sh.Rm("pty"); err != nil {
return err
}
if err := sh.Rm("pty.tar.gz"); err != nil {
return err
}
if err := sh.RunWith(env, "go", "build", "-mod", "vendor", "-gcflags=all=-l -B -C", "-ldflags=-s -w", "-o", "pty", "ptyagent/main.go", "ptyagent/pty.go"); err != nil {
return err
}
if err := sh.Run("tar", "czfv", "pty.tar.gz", "pty"); err != nil {
return err
}
if err := sh.RunWith(env, "go", "build", "-mod", "vendor", "-cover", "-o", "coverage/lilipod", "main.go"); err != nil {
return err
}
return nil
}
func Pty() error {
if err := sh.Rm("pty"); err != nil {
return err
}
if err := sh.Rm("pty.tar.gz"); err != nil {
return err
}
env := map[string]string{"CGO_ENABLED": "0"}
if err := sh.RunWith(env, "go", "build", "-mod", "vendor", "-gcflags=all=-l -B -C", "-ldflags=-s -w -X 'main.version=$${RELEASE_VERSION:-0.0.0}'", "-o", "pty", "ptyagent/main.go", "ptyagent/pty.go"); err != nil {
return err
}
if err := sh.Run("tar", "czfv", "pty.tar.gz", "pty"); err != nil {
return err
}
return nil
}