-
Notifications
You must be signed in to change notification settings - Fork 0
/
mage.go
86 lines (72 loc) · 2.36 KB
/
mage.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
//+build mage
// This is the "magefile" for gnorm. To install mage, run go get github.com/magefile/mage.
// To build gnorm, just mage build.
package main
import (
"fmt"
"os"
"time"
"github.com/magefile/mage/sh"
)
const (
packageName = "github.com/tixu/jiralert/cmd/jiralert"
executable = "jiralert"
)
// ldflags used to build.
var ldflags = "-X main.Version=${VERSION} -X main.BuildDate=${BUILD_DATE} -X main.Hash=${COMMIT_HASH} "
// allow user to override go executable by running as GOEXE=xxx make ... on unix-like systems
var goexe = "go"
// Runs go build for jiralert.
func Build() error {
return sh.RunWith(flagEnv(), goexe, "build", "--ldflags="+ldflags, "-o", executable+".exe", packageName)
}
// Generates binaries for all supported versions. Currently that means a
// combination of windows, linux, and OSX in 32 bit and 64 bit formats. The
// files will be dumped in the local directory with names according to their
// supported platform.
func All() error {
for _, OS := range []string{"windows", "darwin", "linux"} {
for _, ARCH := range []string{"amd64", "386"} {
fmt.Printf("running go build for GOOS=%s GOARCH=%s\n", OS, ARCH)
env := flagEnv()
env["GOOS"] = OS
env["GOARCH"] = ARCH
var buildName string
if OS == "windows" {
buildName = fmt.Sprintf("%s-%s.exe", executable, ARCH)
} else {
buildName = fmt.Sprintf("%s-%s-%s", executable, ARCH, OS)
}
if err := sh.RunWith(env, goexe, "build", "--ldflags="+ldflags, "-o", buildName, packageName); err != nil {
return err
}
}
}
return nil
return fmt.Errorf("unimplemented")
}
// Removes generated cruft. This target shouldn't ever be necessary, since the
// cleanup should happen automatically, but it's here just in case.
func Clean() error {
return fmt.Errorf("unimplemented")
}
func init() {
if exe := os.Getenv("GOEXE"); exe != "" {
goexe = exe
}
fmt.Println("activating module mode")
// We want to use Go 1.11 modules even if the source lives inside GOPATH.
// The default is "auto".
os.Setenv("GO111MODULE", "on")
}
func flagEnv() map[string]string {
hash, _ := sh.Output("git", "rev-parse", "--short", "HEAD")
//git describe --tags
tag, _ := sh.Output("git", "describe", "--tags", "--abbrev=0")
return map[string]string{
"COMMIT_TAG": tag,
"VERSION": tag,
"COMMIT_HASH": hash,
"BUILD_DATE": time.Now().Format("2006-01-02T15:04:05Z0700"),
}
}