mirror of
https://github.com/anchore/grype
synced 2024-11-10 06:34:13 +00:00
Enhance version cmd with SYFT_VERSION (#420)
* update command to take in SYFT_VERSION Signed-off-by: Christopher Angelo Phillips <christopher.phillips@anchore.com> * add dynamic input to build command for ci Signed-off-by: Christopher Angelo Phillips <christopher.phillips@anchore.com>
This commit is contained in:
parent
7c082c2162
commit
fe00b3c314
4 changed files with 9 additions and 0 deletions
|
@ -25,6 +25,7 @@ builds:
|
||||||
-s
|
-s
|
||||||
-extldflags '-static'
|
-extldflags '-static'
|
||||||
-X github.com/anchore/grype/internal/version.version={{.Version}}
|
-X github.com/anchore/grype/internal/version.version={{.Version}}
|
||||||
|
-X github.com/anchore/grype/internal/version.syftVersion={{.Env.SYFT_VERSION}}
|
||||||
-X github.com/anchore/grype/internal/version.gitCommit={{.Commit}}
|
-X github.com/anchore/grype/internal/version.gitCommit={{.Commit}}
|
||||||
-X github.com/anchore/grype/internal/version.buildDate={{.Date}}
|
-X github.com/anchore/grype/internal/version.buildDate={{.Date}}
|
||||||
-X github.com/anchore/grype/internal/version.gitTreeState={{.Env.BUILD_GIT_TREE_STATE}}
|
-X github.com/anchore/grype/internal/version.gitTreeState={{.Env.BUILD_GIT_TREE_STATE}}
|
||||||
|
@ -44,6 +45,7 @@ builds:
|
||||||
-s
|
-s
|
||||||
-extldflags '-static'
|
-extldflags '-static'
|
||||||
-X github.com/anchore/grype/internal/version.version={{.Version}}
|
-X github.com/anchore/grype/internal/version.version={{.Version}}
|
||||||
|
-X github.com/anchore/grype/internal/version.syftVersion={{.Env.SYFT_VERSION}}
|
||||||
-X github.com/anchore/grype/internal/version.gitCommit={{.Commit}}
|
-X github.com/anchore/grype/internal/version.gitCommit={{.Commit}}
|
||||||
-X github.com/anchore/grype/internal/version.buildDate={{.Date}}
|
-X github.com/anchore/grype/internal/version.buildDate={{.Date}}
|
||||||
-X github.com/anchore/grype/internal/version.gitTreeState={{.Env.BUILD_GIT_TREE_STATE}}
|
-X github.com/anchore/grype/internal/version.gitTreeState={{.Env.BUILD_GIT_TREE_STATE}}
|
||||||
|
|
3
Makefile
3
Makefile
|
@ -21,6 +21,7 @@ BOOTSTRAP_CACHE="c7afb99ad"
|
||||||
DISTDIR=./dist
|
DISTDIR=./dist
|
||||||
SNAPSHOTDIR=./snapshot
|
SNAPSHOTDIR=./snapshot
|
||||||
GITTREESTATE=$(if $(shell git status --porcelain),dirty,clean)
|
GITTREESTATE=$(if $(shell git status --porcelain),dirty,clean)
|
||||||
|
SYFTVERSION=$(shell go list -m all | grep github.com/anchore/syft | awk '{print $$2}')
|
||||||
OS := $(shell uname)
|
OS := $(shell uname)
|
||||||
|
|
||||||
ifeq ($(OS),Darwin)
|
ifeq ($(OS),Darwin)
|
||||||
|
@ -169,6 +170,7 @@ $(SNAPSHOTDIR): ## Build snapshot release binaries and packages
|
||||||
|
|
||||||
# build release snapshots
|
# build release snapshots
|
||||||
BUILD_GIT_TREE_STATE=$(GITTREESTATE) \
|
BUILD_GIT_TREE_STATE=$(GITTREESTATE) \
|
||||||
|
SYFT_VERSION=$(SYFTVERSION) \
|
||||||
$(TEMPDIR)/goreleaser release --skip-publish --skip-sign --rm-dist --snapshot --config $(TEMPDIR)/goreleaser.yaml
|
$(TEMPDIR)/goreleaser release --skip-publish --skip-sign --rm-dist --snapshot --config $(TEMPDIR)/goreleaser.yaml
|
||||||
|
|
||||||
.PHONY: acceptance-linux
|
.PHONY: acceptance-linux
|
||||||
|
@ -252,6 +254,7 @@ release: clean-dist validate-grype-test-config changelog-release ## Build and pu
|
||||||
# release (note the version transformation from v0.7.0 --> 0.7.0)
|
# release (note the version transformation from v0.7.0 --> 0.7.0)
|
||||||
bash -c "\
|
bash -c "\
|
||||||
BUILD_GIT_TREE_STATE=$(GITTREESTATE) \
|
BUILD_GIT_TREE_STATE=$(GITTREESTATE) \
|
||||||
|
SYFT_VERSION=$(SYFTVERSION) \
|
||||||
VERSION=$(VERSION:v%=%) \
|
VERSION=$(VERSION:v%=%) \
|
||||||
$(TEMPDIR)/goreleaser \
|
$(TEMPDIR)/goreleaser \
|
||||||
--rm-dist \
|
--rm-dist \
|
||||||
|
|
|
@ -31,6 +31,7 @@ func printVersion(_ *cobra.Command, _ []string) {
|
||||||
case "text":
|
case "text":
|
||||||
fmt.Println("Application: ", internal.ApplicationName)
|
fmt.Println("Application: ", internal.ApplicationName)
|
||||||
fmt.Println("Version: ", versionInfo.Version)
|
fmt.Println("Version: ", versionInfo.Version)
|
||||||
|
fmt.Println("Syft Version: ", versionInfo.SyftVersion)
|
||||||
fmt.Println("BuildDate: ", versionInfo.BuildDate)
|
fmt.Println("BuildDate: ", versionInfo.BuildDate)
|
||||||
fmt.Println("GitCommit: ", versionInfo.GitCommit)
|
fmt.Println("GitCommit: ", versionInfo.GitCommit)
|
||||||
fmt.Println("GitTreeState: ", versionInfo.GitTreeState)
|
fmt.Println("GitTreeState: ", versionInfo.GitTreeState)
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
const valueNotProvided = "[not provided]"
|
const valueNotProvided = "[not provided]"
|
||||||
|
|
||||||
var version = valueNotProvided
|
var version = valueNotProvided
|
||||||
|
var syftVersion = valueNotProvided
|
||||||
var gitCommit = valueNotProvided
|
var gitCommit = valueNotProvided
|
||||||
var gitTreeState = valueNotProvided
|
var gitTreeState = valueNotProvided
|
||||||
var buildDate = valueNotProvided
|
var buildDate = valueNotProvided
|
||||||
|
@ -15,6 +16,7 @@ var platform = fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)
|
||||||
|
|
||||||
type Version struct {
|
type Version struct {
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
|
SyftVersion string `json:"syftVersion"`
|
||||||
GitCommit string `json:"gitCommit"`
|
GitCommit string `json:"gitCommit"`
|
||||||
GitTreeState string `json:"gitTreeState"`
|
GitTreeState string `json:"gitTreeState"`
|
||||||
BuildDate string `json:"buildDate"`
|
BuildDate string `json:"buildDate"`
|
||||||
|
@ -26,6 +28,7 @@ type Version struct {
|
||||||
func FromBuild() Version {
|
func FromBuild() Version {
|
||||||
return Version{
|
return Version{
|
||||||
Version: version,
|
Version: version,
|
||||||
|
SyftVersion: syftVersion,
|
||||||
GitCommit: gitCommit,
|
GitCommit: gitCommit,
|
||||||
GitTreeState: gitTreeState,
|
GitTreeState: gitTreeState,
|
||||||
BuildDate: buildDate,
|
BuildDate: buildDate,
|
||||||
|
|
Loading…
Reference in a new issue