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
33import (
44 "fmt"
55 "os"
6+ "runtime/debug"
67
78 "github.com/conventionalcommit/commitlint/cmd"
89)
910
1011// Build constants
1112// all variables are set during build
1213var (
13- Version = "devel"
14- Commit = ""
15- BuildTime = ""
14+ Version string
15+ Commit string
16+ BuildTime string
1617)
1718
19+ func init () {
20+ setVersionInfo ()
21+ }
22+
1823func main () {
1924 app := cmd .New (Version , Commit , BuildTime )
2025 err := app .Run (os .Args )
@@ -23,3 +28,29 @@ func main() {
2328 os .Exit (cmd .ErrExitCode )
2429 }
2530}
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