Skip to content

Commit

Permalink
Make sure some version information is set when no version was injecte…
Browse files Browse the repository at this point in the history
…d into the binary

Signed-off-by: Cosmin Cojocar <cosmin.cojocar@gmx.ch>
  • Loading branch information
ccojocar authored and Cosmin Cojocar committed Jun 25, 2020
1 parent 1d2c951 commit ad1cb7e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/gosec/main.go
Expand Up @@ -240,6 +240,9 @@ func filterIssues(issues []*gosec.Issue, severity gosec.Score, confidence gosec.
}

func main() {
// Makes sure some version information is set
prepareVersionInfo()

// Setup usage description
flag.Usage = usage

Expand Down
15 changes: 15 additions & 0 deletions cmd/gosec/version.go
@@ -1,5 +1,9 @@
package main

import (
"runtime/debug"
)

// Version is the build version
var Version string

Expand All @@ -8,3 +12,14 @@ var GitTag string

// BuildDate is the date when the build was created
var BuildDate string

// prepareVersionInfo sets some runtime version when the version value
// was not injected by the build into the binary (e.g. go get).
// This returns currently "(devel)" but not an effective version until
// https://github.com/golang/go/issues/29814 gets resolved.
func prepareVersionInfo() {
if Version == "" {
bi, _ := debug.ReadBuildInfo()
Version = bi.Main.Version
}
}

0 comments on commit ad1cb7e

Please sign in to comment.