forked from ngerakines/protoc-gen-whatever
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmagefile.go
65 lines (56 loc) · 1.58 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
// +build mage
package main
import (
"errors"
"fmt"
"os"
"os/exec"
"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", "protoc-gen-whatever", "cmd/protoc-gen-whatever/main.go")
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("./protoc-gen-whatever", "/usr/bin/protoc-gen-whatever")
}
// 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() error {
fmt.Println("Cleaning...")
os.RemoveAll("protoc-gen-whatever")
return sh.Rm("dist")
}
func Release() (err error) {
if os.Getenv("TAG") == "" {
return errors.New("MSG and TAG environment variables are required")
}
if err := sh.RunV("git", "tag", "-a", "$TAG"); err != nil {
return err
}
if err := sh.RunV("git", "push", "origin", "$TAG"); err != nil {
return err
}
defer func() {
if err != nil {
sh.RunV("git", "tag", "--delete", "$TAG")
sh.RunV("git", "push", "--delete", "origin", "$TAG")
}
}()
return sh.RunV("goreleaser")
}