anchor version regex

Also create a GIT_MINOR variable for a touch of readability....
pull/6/head
Eric Paris 2015-03-27 18:54:36 -04:00
parent 3919a38ad6
commit 2b941f4954
1 changed files with 5 additions and 10 deletions

View File

@ -24,7 +24,7 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
NEW_VERSION=${1-}
VERSION_REGEX="v([0-9]+).([0-9]+)(.([0-9]+))?"
VERSION_REGEX="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"
[[ ${NEW_VERSION} =~ $VERSION_REGEX ]] || {
echo "!!! You must specify the version in the form of '$VERSION_REGEX'" >&2
exit 1
@ -32,13 +32,7 @@ VERSION_REGEX="v([0-9]+).([0-9]+)(.([0-9]+))?"
VERSION_MAJOR="${BASH_REMATCH[1]}"
VERSION_MINOR="${BASH_REMATCH[2]}"
VERSION_PATCH="${BASH_REMATCH[4]}"
# force .0 if no patch version specified
if [[ -z ${VERSION_PATCH:-} ]]; then
VERSION_PATCH="0"
NEW_VERSION="${NEW_VERSION}.0"
fi
VERSION_PATCH="${BASH_REMATCH[3]}"
if ! git diff-index --quiet --cached HEAD; then
echo "!!! You must not have any changes in your index when running this command"
@ -70,9 +64,10 @@ fi
VERSION_FILE="${KUBE_ROOT}/pkg/version/base.go"
GIT_MINOR="${VERSION_MINOR}.${VERSION_PATCH}"
echo "+++ Updating to ${NEW_VERSION}"
"$SED" -r -i -e "s/gitMajor\s+string = \"[^\"]*\"/gitMajor string = \"${VERSION_MAJOR}\"/" "${VERSION_FILE}"
"$SED" -r -i -e "s/gitMinor\s+string = \"[^\"]*\"/gitMinor string = \"${VERSION_MINOR}.${VERSION_PATCH}\"/" "${VERSION_FILE}"
"$SED" -r -i -e "s/gitMinor\s+string = \"[^\"]*\"/gitMinor string = \"${GIT_MINOR}\"/" "${VERSION_FILE}"
"$SED" -r -i -e "s/gitVersion\s+string = \"[^\"]*\"/gitVersion string = \"$NEW_VERSION\"/" "${VERSION_FILE}"
gofmt -s -w "${VERSION_FILE}"
@ -85,7 +80,7 @@ git tag -a -m "Kubernetes version $NEW_VERSION" "${NEW_VERSION}"
echo "+++ Updating to ${NEW_VERSION}-dev"
"$SED" -r -i -e "s/gitMajor\s+string = \"[^\"]*\"/gitMajor string = \"${VERSION_MAJOR}\"/" "${VERSION_FILE}"
"$SED" -r -i -e "s/gitMinor\s+string = \"[^\"]*\"/gitMinor string = \"${VERSION_MINOR}.${VERSION_PATCH}\+\"/" "${VERSION_FILE}"
"$SED" -r -i -e "s/gitMinor\s+string = \"[^\"]*\"/gitMinor string = \"${GIT_MINOR}\+\"/" "${VERSION_FILE}"
"$SED" -r -i -e "s/gitVersion\s+string = \"[^\"]*\"/gitVersion string = \"$NEW_VERSION-dev\"/" "${VERSION_FILE}"
gofmt -s -w "${VERSION_FILE}"