This repository has been archived by the owner on Aug 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmagefile.go
78 lines (67 loc) · 1.66 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
// +build mage
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"github.com/magefile/mage/mg" // mg contains helpful utility functions, like Deps
"github.com/magefile/mage/sh"
)
// Default target to run when none is specified
// If not set, running mage will list available targets
// var Default = Build
// A build step that requires additional params, or platform specific steps for example
func Build() error {
mg.Deps(InstallDeps)
fmt.Println("Building...")
cmd := exec.Command("go", "build", "-o", "MyApp", ".")
return cmd.Run()
}
// A custom install step if you need your bin someplace other than go/bin
func Install() error {
mg.Deps(Build)
fmt.Println("Installing...")
return os.Rename("./MyApp", "/usr/bin/MyApp")
}
// Manage your deps, or running package managers.
func InstallDeps() error {
fmt.Println("Installing Deps...")
cmd := exec.Command("go", "get", "github.com/stretchr/piglatin")
return cmd.Run()
}
// Clean up after yourself
func Clean() {
fmt.Println("Cleaning...")
os.RemoveAll("MyApp")
}
//Tooling help
func Tools() error {
update, err := envBool("UPDATE")
if err != nil {
return err
}
if err := os.MkdirAll("_tools", 0700); err != nil {
return err
}
wd, err := os.Getwd()
if err != nil {
return err
}
env := map[string]string{"GOBIN": filepath.Join(wd, "_tools")}
args := []string{"get"}
if update {
args = []string{"get", "-u"}
}
for _, t := range tools {
err := sh.RunWith(env, "go", append(args, t)...)
if err != nil {
return err
}
}
return nil
}
// tool runs a command using a cached binary.
func tool(cmd string, args ...string) error {
return sh.Run(filepath.Join("_tools", cmd), args...)
}