mirror of
https://github.com/anchore/grype
synced 2024-11-14 00:07:08 +00:00
5aa85338d6
* refactor release to keep snapshot assets in parity with release assets Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * refactor install.sh and put under test Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * tidy go.sum Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add mac acceptance test to github actions workflow Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * rm use of goreleaser in cli tests Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * go mod tidy with go 1.17 Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
50 lines
1.7 KiB
Go
50 lines
1.7 KiB
Go
package version
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
"strings"
|
|
)
|
|
|
|
const valueNotProvided = "[not provided]"
|
|
|
|
// all variables here are provided as build-time arguments, with clear default values
|
|
var version = valueNotProvided
|
|
var syftVersion = valueNotProvided
|
|
var gitCommit = valueNotProvided
|
|
var gitDescription = valueNotProvided
|
|
var buildDate = valueNotProvided
|
|
var platform = fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)
|
|
|
|
// Version defines the application version details (generally from build information)
|
|
type Version struct {
|
|
Version string `json:"version"` // application semantic version
|
|
SyftVersion string `json:"syftVersion"` // the version of syft being used by grype
|
|
GitCommit string `json:"gitCommit"` // git SHA at build-time
|
|
GitDescription string `json:"gitDescription"` // output of 'git describe --dirty --always --tags'
|
|
BuildDate string `json:"buildDate"` // date of the build
|
|
GoVersion string `json:"goVersion"` // go runtime version at build-time
|
|
Compiler string `json:"compiler"` // compiler used at build-time
|
|
Platform string `json:"platform"` // GOOS and GOARCH at build-time
|
|
}
|
|
|
|
func (v Version) isProductionBuild() bool {
|
|
if strings.Contains(v.Version, "SNAPSHOT") || strings.Contains(v.Version, valueNotProvided) {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
// FromBuild provides all version details
|
|
func FromBuild() Version {
|
|
return Version{
|
|
Version: version,
|
|
SyftVersion: syftVersion,
|
|
GitCommit: gitCommit,
|
|
GitDescription: gitDescription,
|
|
BuildDate: buildDate,
|
|
GoVersion: runtime.Version(),
|
|
Compiler: runtime.Compiler,
|
|
Platform: platform,
|
|
}
|
|
}
|