Do not append "-dirty" to the version number when the git repo is dirty

- Semver version numbers do not end with "-dirty"
- Continue to include the clean/dirty status of the repo in the
  `gitTreeState` field
This commit is contained in:
Ryan Richard 2020-10-01 17:23:37 -07:00
parent b69eb5e850
commit 0bfa351eb4

View File

@ -38,9 +38,10 @@ kube::version::get_version_vars() {
fi fi
fi fi
# If KUBE_GIT_VERSION is supplied and is not a valid Semantic Version, then refuse to build. # If KUBE_GIT_VERSION is supplied
if [[ -n "${KUBE_GIT_VERSION:-""}" ]]; then if [[ -n "${KUBE_GIT_VERSION:-""}" ]]; then
# If KUBE_GIT_VERSION is not a valid Semantic Version, then refuse to build.
if ! [[ "${KUBE_GIT_VERSION}" =~ ^v([0-9]+)\.([0-9]+)(\.[0-9]+)?(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then if ! [[ "${KUBE_GIT_VERSION}" =~ ^v([0-9]+)\.([0-9]+)(\.[0-9]+)?(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
echo "KUBE_GIT_VERSION should be a valid Semantic Version starting with a \"v\". Current value: ${KUBE_GIT_VERSION}" echo "KUBE_GIT_VERSION should be a valid Semantic Version starting with a \"v\". Current value: ${KUBE_GIT_VERSION}"
echo "Please see more details here: https://semver.org" echo "Please see more details here: https://semver.org"
@ -52,13 +53,6 @@ kube::version::get_version_vars() {
KUBE_GIT_MINOR=${BASH_REMATCH[2]} KUBE_GIT_MINOR=${BASH_REMATCH[2]}
fi fi
if [[ "${KUBE_GIT_TREE_STATE}" == "dirty" ]]; then
# git describe --dirty only considers changes to existing files, but
# that is problematic since new untracked .go files affect the build,
# so use our idea of "dirty" from git status instead.
KUBE_GIT_VERSION+="-dirty"
fi
else else
# KUBE_GIT_VERSION was not supplied # KUBE_GIT_VERSION was not supplied
KUBE_GIT_VERSION='?.?.?' KUBE_GIT_VERSION='?.?.?'