-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmageHelpers.go
50 lines (45 loc) · 969 Bytes
/
mageHelpers.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
//go:build mage
// +build mage
package main
import (
"fmt"
"github.com/magefile/mage/sh"
)
func flags() (string, error) {
// Make version increase automatically
return fmt.Sprintf(`-X "main.version=%s" -X "main.commit=%s" -X "main.date=%s" -X "main.builtBy=%s"`, version, commit, date, builtBy), nil
}
// Implement automatic semver management
func getVersion() string {
cmd, ok := sh.Output("git", "describe", "--tags")
if ok != nil {
return "-tag"
}
return cmd
}
func getCommit() string {
cmd, ok := sh.Output("git", "describe", "--always", "--long", "--dirty")
if ok != nil {
return ""
}
return cmd
}
func getDate() string {
cmd, ok := sh.Output("date")
if ok != nil {
return ""
}
return cmd
}
func getBuiltBy() string {
cmd, ok := sh.Output("git", "--no-pager", "show", "-s", "--format='%ae'")
if ok != nil {
return ok.Error()
}
// change str from 'xxx' to xxx
if cmd != "" {
sl := len(cmd)
cmd = cmd[1 : sl-1]
}
return cmd
}