mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 17:26:28 +00:00
Merge pull request #4055 from deitch/include-semver-in-version
properly save linuxkit version
This commit is contained in:
commit
bfac135e4e
@ -1,5 +1,24 @@
|
|||||||
VERSION?="v0.0-dev"
|
# determine the version we save in the build binary
|
||||||
|
# we always include the git commit.
|
||||||
|
# the version is the current semver if it this commit matches the tag,
|
||||||
|
# else it is the following: <tag>-<commits since tag>-<short commit hash>
|
||||||
|
# if the git tree is dirty, append "-dirty"
|
||||||
|
# most recent commit
|
||||||
GIT_COMMIT=$(shell git rev-list -1 HEAD)
|
GIT_COMMIT=$(shell git rev-list -1 HEAD)
|
||||||
|
# whether or not it is dirty, i.e. has uncommitted changes
|
||||||
|
GIT_DIRTY=$(shell git update-index -q --refresh && git diff-index --quiet HEAD -- . || echo "-dirty")
|
||||||
|
# most recent tag, might or might not point to GIT_COMMIT
|
||||||
|
GIT_TAG=$(shell git describe --tags --match="v*")
|
||||||
|
# include the possible "-dirty" suffix
|
||||||
|
VERSION=$(GIT_TAG)$(GIT_DIRTY)
|
||||||
|
|
||||||
|
report:
|
||||||
|
@echo "VERSION: $(VERSION)"
|
||||||
|
@echo "GIT_COMMIT: $(GIT_COMMIT)"
|
||||||
|
@echo "GIT_DIRTY: $(GIT_DIRTY)"
|
||||||
|
@echo "GIT_TAG: $(GIT_TAG)"
|
||||||
|
@echo "VERSION: $(VERSION)"
|
||||||
|
|
||||||
GO_COMPILE?=linuxkit/go-compile:c97703655e8510b7257ffc57f25e40337b0f0813
|
GO_COMPILE?=linuxkit/go-compile:c97703655e8510b7257ffc57f25e40337b0f0813
|
||||||
export GO_FLAGS=-mod=vendor
|
export GO_FLAGS=-mod=vendor
|
||||||
|
|
||||||
|
@ -10,11 +10,22 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func versionCmd() *cobra.Command {
|
func versionCmd() *cobra.Command {
|
||||||
|
var short, commit bool
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Short: "report the version of linuxkit",
|
Short: "report the version of linuxkit",
|
||||||
Long: `Report the version of linuxkit.`,
|
Long: `Report the version of linuxkit.
|
||||||
|
Run with option --short to print just the version number.
|
||||||
|
Run with option --commit to print just the git commit.`,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
if short {
|
||||||
|
fmt.Println(version.Version)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if commit {
|
||||||
|
fmt.Println(version.GitCommit)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
fmt.Printf("%s version %s\n", filepath.Base(os.Args[0]), version.Version)
|
fmt.Printf("%s version %s\n", filepath.Base(os.Args[0]), version.Version)
|
||||||
if version.GitCommit != "" {
|
if version.GitCommit != "" {
|
||||||
fmt.Printf("commit: %s\n", version.GitCommit)
|
fmt.Printf("commit: %s\n", version.GitCommit)
|
||||||
@ -22,6 +33,8 @@ func versionCmd() *cobra.Command {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
cmd.Flags().BoolVar(&short, "short", false, "print just the version number")
|
||||||
|
cmd.Flags().BoolVar(&commit, "commit", false, "print just the commit")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user