mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 09:16:29 +00:00
properly save linuxkit version
Signed-off-by: Avi Deitcher <avi@deitcher.net>
This commit is contained in:
parent
8d76ae282f
commit
8bb9174b28
@ -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)
|
||||
# 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
|
||||
export GO_FLAGS=-mod=vendor
|
||||
|
||||
|
@ -10,11 +10,22 @@ import (
|
||||
)
|
||||
|
||||
func versionCmd() *cobra.Command {
|
||||
var short, commit bool
|
||||
cmd := &cobra.Command{
|
||||
Use: "version",
|
||||
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 {
|
||||
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)
|
||||
if version.GitCommit != "" {
|
||||
fmt.Printf("commit: %s\n", version.GitCommit)
|
||||
@ -22,6 +33,8 @@ func versionCmd() *cobra.Command {
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user