mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Set gitMajor and gitMinor from hack/build-go.sh
Set the values of major and minor version based on the output of the `git describe` command, which uses annotated tags as source of versioning information. Minor will get a "+" appended whenever the annotated tag does not match the tree exactly (including when the tree is dirty.) So that only official releases will have a "bare" minor version, all others will have a "+" to indicate the binaries contain changes from the released version in minor. (This is similar to how versions of development builds of the Linux kernel work.) Tested: - With no annotated tags: $ hack/build-go.sh $ _output/go/bin/kubecfg -version=raw version.Info{Major:"0", Minor:"1+", GitVersion:"v0.1+", GitCommit:"7d29873bdee87efacaace30ab3602297cacf1b4f", GitTreeState:"clean"} - Tagging current version on a clean git tree: $ git tag -a -m 'Test tag v2.3' v2.3 $ hack/build-go.sh $ _output/go/bin/kubecfg -version=raw version.Info{Major:"2", Minor:"3", GitVersion:"v2.3", GitCommit:"7d29873bdee87efacaace30ab3602297cacf1b4f", GitTreeState:"clean"} - Tagging current version on a dirty git tree: $ git tag -a -m 'Test tag v2.3' v2.3 $ touch test.txt # this is enough to mark the tree as dirty $ hack/build-go.sh $ _output/go/bin/kubecfg -version=raw version.Info{Major:"2", Minor:"3+", GitVersion:"v2.3-dirty", GitCommit:"7d29873bdee87efacaace30ab3602297cacf1b4f", GitTreeState:"dirty"} - Tagging a previous version on a clean tree: $ git tag -a -m 'Test tag v2.3' v2.3 HEAD~5 $ hack/build-go.sh $ _output/go/bin/kubecfg -version=raw version.Info{Major:"2", Minor:"3+", GitVersion:"v2.3-6-g7d29873bdee87e", GitCommit:"7d29873bdee87efacaace30ab3602297cacf1b4f", GitTreeState:"clean"} Signed-off-by: Filipe Brandenburger <filbranden@google.com>
This commit is contained in:
parent
8cd7387cc0
commit
b94749ec70
@ -54,6 +54,21 @@ kube::version_ldflags() {
|
||||
git_version+="-dirty"
|
||||
fi
|
||||
ldflags+=(-X "${KUBE_GO_PACKAGE}/pkg/version.gitVersion" "${git_version}")
|
||||
|
||||
# Try to match the "git describe" output to a regex to try to extract
|
||||
# the "major" and "minor" versions and whether this is the exact tagged
|
||||
# version or whether the tree is between two tagged versions.
|
||||
if [[ "${git_version}" =~ ^v([0-9]+)\.([0-9]+)([.-].*)?$ ]]; then
|
||||
git_major=${BASH_REMATCH[1]}
|
||||
git_minor=${BASH_REMATCH[2]}
|
||||
if [[ -n "${BASH_REMATCH[3]}" ]]; then
|
||||
git_minor+="+"
|
||||
fi
|
||||
ldflags+=(
|
||||
-X "${KUBE_GO_PACKAGE}/pkg/version.gitMajor" "${git_major}"
|
||||
-X "${KUBE_GO_PACKAGE}/pkg/version.gitMinor" "${git_minor}"
|
||||
)
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user