Skip to content

Commit

Permalink
feat: set version info on init
Browse files Browse the repository at this point in the history
  • Loading branch information
muthukrishnan24 committed Aug 28, 2021
1 parent 07e2316 commit d95a20e
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ package main
import (
"fmt"
"os"
"runtime/debug"

"github.com/conventionalcommit/commitlint/cmd"
)

// Build constants
// all variables are set during build
var (
Version = "devel"
Commit = ""
BuildTime = ""
Version string
Commit string
BuildTime string
)

func init() {
setVersionInfo()
}

func main() {
app := cmd.New(Version, Commit, BuildTime)
err := app.Run(os.Args)
Expand All @@ -23,3 +28,29 @@ func main() {
os.Exit(cmd.ErrExitCode)
}
}

func setVersionInfo() {
info, ok := debug.ReadBuildInfo()
if ok {
Version = info.Main.Version

checkSum := "unknown"
if info.Main.Sum != "" {
checkSum = info.Main.Sum
}

Commit = "(" + "checksum: " + checkSum + ")"
}

if Version == "" {
Version = "master"
}

if Commit == "" {
Commit = "unknown"
}

if BuildTime == "" {
BuildTime = "unknown"
}
}

0 comments on commit d95a20e

Please sign in to comment.