/
magefile.go
72 lines (58 loc) · 1.52 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
// +build mage
package main
import (
"fmt"
"os"
"os/exec"
"github.com/magefile/mage/mg" // mg contains helpful utility functions, like Deps
)
// Default target to run when none is specified
// If not set, running mage will list available targets
// var Default = Build
// Clean files and folders used for test data or binaries
func Clean() error {
fmt.Println("Cleaning files and folders...")
clean := exec.Command("rm", "-rf", "dist")
err := clean.Run()
if err != nil {
return err
}
clean = exec.Command("rm", "-f", "bin/icon")
err = clean.Run()
if err != nil {
return err
}
return nil
}
// A build step that requires additional params, or platform specific steps for example
func Build() error {
mg.Deps(Clean)
mg.Deps(InstallDeps)
fmt.Println("Building...")
cmd := exec.Command("go", "build", "-o", "./bin/icon")
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...")
gopath := os.Getenv("GOPATH")
return os.Rename("./bin/icon", gopath+"/bin/identicon")
}
// Manage your deps, or running package managers.
func InstallDeps() error {
fmt.Println("Installing Deps...")
cmd := exec.Command("dep", "ensure")
return cmd.Run()
}
// Run test that creates an identicon named Identicon
func Test() error {
mg.Deps(Build)
fmt.Println("Running test...")
err := os.Mkdir("dist", os.FileMode(0777))
if err != nil {
return err
}
cmd := exec.Command("./bin/icon", "-o", "dist", "Identicon")
return cmd.Run()
}