diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 9da27c5b..551c8f1e 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -25,6 +25,7 @@ builds: -s -extldflags '-static' -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.buildDate={{.Date}} -X github.com/anchore/grype/internal/version.gitTreeState={{.Env.BUILD_GIT_TREE_STATE}} @@ -44,6 +45,7 @@ builds: -s -extldflags '-static' -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.buildDate={{.Date}} -X github.com/anchore/grype/internal/version.gitTreeState={{.Env.BUILD_GIT_TREE_STATE}} diff --git a/Makefile b/Makefile index bf7b4be6..9a3479a8 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,7 @@ BOOTSTRAP_CACHE="c7afb99ad" DISTDIR=./dist SNAPSHOTDIR=./snapshot 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) ifeq ($(OS),Darwin) @@ -169,6 +170,7 @@ $(SNAPSHOTDIR): ## Build snapshot release binaries and packages # build release snapshots BUILD_GIT_TREE_STATE=$(GITTREESTATE) \ + SYFT_VERSION=$(SYFTVERSION) \ $(TEMPDIR)/goreleaser release --skip-publish --skip-sign --rm-dist --snapshot --config $(TEMPDIR)/goreleaser.yaml .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) bash -c "\ BUILD_GIT_TREE_STATE=$(GITTREESTATE) \ + SYFT_VERSION=$(SYFTVERSION) \ VERSION=$(VERSION:v%=%) \ $(TEMPDIR)/goreleaser \ --rm-dist \ diff --git a/cmd/version.go b/cmd/version.go index a82278bf..ca42b623 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -31,6 +31,7 @@ func printVersion(_ *cobra.Command, _ []string) { case "text": fmt.Println("Application: ", internal.ApplicationName) fmt.Println("Version: ", versionInfo.Version) + fmt.Println("Syft Version: ", versionInfo.SyftVersion) fmt.Println("BuildDate: ", versionInfo.BuildDate) fmt.Println("GitCommit: ", versionInfo.GitCommit) fmt.Println("GitTreeState: ", versionInfo.GitTreeState) diff --git a/internal/version/build.go b/internal/version/build.go index 21b11eb1..2de61c9b 100644 --- a/internal/version/build.go +++ b/internal/version/build.go @@ -8,6 +8,7 @@ import ( const valueNotProvided = "[not provided]" var version = valueNotProvided +var syftVersion = valueNotProvided var gitCommit = valueNotProvided var gitTreeState = valueNotProvided var buildDate = valueNotProvided @@ -15,6 +16,7 @@ var platform = fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH) type Version struct { Version string `json:"version"` + SyftVersion string `json:"syftVersion"` GitCommit string `json:"gitCommit"` GitTreeState string `json:"gitTreeState"` BuildDate string `json:"buildDate"` @@ -26,6 +28,7 @@ type Version struct { func FromBuild() Version { return Version{ Version: version, + SyftVersion: syftVersion, GitCommit: gitCommit, GitTreeState: gitTreeState, BuildDate: buildDate,