File tree Expand file tree Collapse file tree 1 file changed +34
-3
lines changed Expand file tree Collapse file tree 1 file changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -3,18 +3,23 @@ package main
3
3
import (
4
4
"fmt"
5
5
"os"
6
+ "runtime/debug"
6
7
7
8
"github.com/conventionalcommit/commitlint/cmd"
8
9
)
9
10
10
11
// Build constants
11
12
// all variables are set during build
12
13
var (
13
- Version = "devel"
14
- Commit = ""
15
- BuildTime = ""
14
+ Version string
15
+ Commit string
16
+ BuildTime string
16
17
)
17
18
19
+ func init () {
20
+ setVersionInfo ()
21
+ }
22
+
18
23
func main () {
19
24
app := cmd .New (Version , Commit , BuildTime )
20
25
err := app .Run (os .Args )
@@ -23,3 +28,29 @@ func main() {
23
28
os .Exit (cmd .ErrExitCode )
24
29
}
25
30
}
31
+
32
+ func setVersionInfo () {
33
+ info , ok := debug .ReadBuildInfo ()
34
+ if ok {
35
+ Version = info .Main .Version
36
+
37
+ checkSum := "unknown"
38
+ if info .Main .Sum != "" {
39
+ checkSum = info .Main .Sum
40
+ }
41
+
42
+ Commit = "(" + "checksum: " + checkSum + ")"
43
+ }
44
+
45
+ if Version == "" {
46
+ Version = "master"
47
+ }
48
+
49
+ if Commit == "" {
50
+ Commit = "unknown"
51
+ }
52
+
53
+ if BuildTime == "" {
54
+ BuildTime = "unknown"
55
+ }
56
+ }
You can’t perform that action at this time.
0 commit comments