Skip to content

Commit

Permalink
change display versions (#1601)
Browse files Browse the repository at this point in the history
  • Loading branch information
kobayashi authored Mar 1, 2022
1 parent b1097b5 commit 587a4a8
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions hack/build-flags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function build_flags() {
rev="$(git rev-parse --short HEAD)"
local pkg="knative.dev/client/pkg/kn/commands/version"
local version="${TAG:-}"
local major_minor="$(echo "${version}" | cut -f1-2 -d. -n)"
# Use vYYYYMMDD-local-<hash> for the version string, if not passed.
if [[ -z "${version}" ]]; then
# Get the commit, excluding any tags but keeping the "dirty" flag
Expand All @@ -27,13 +28,21 @@ function build_flags() {
[[ -n "${commit}" ]] || abort "error getting the current commit"
version="v$(date +%Y%m%d)-local-${commit}"
fi
# Extract Eventing and Serving versions from go.mod
local version_serving version_eventing
version_serving=$(grep "knative.dev/serving " "${base}/go.mod" \
# For Eventing and Serving versionings,
# major and minor versions are the same as client version
# patch version is from each technical version
technical_version_serving=$(grep "knative.dev/serving " "${base}/go.mod" \
| sed -s 's/.* \(v.[\.0-9]*\).*/\1/')
version_eventing=$(grep "knative.dev/eventing " "${base}/go.mod" \
technical_version_eventing=$(grep "knative.dev/eventing " "${base}/go.mod" \
| sed -s 's/.* \(v.[\.0-9]*\).*/\1/')

local version_serving version_eventing
if [[ -n "${major_minor}" ]]; then
version_serving=${major_minor}.$(echo ${technical_version_serving} |cut -f3 -d.)
version_eventing=${major_minor}.$(echo ${technical_version_eventing} |cut -f3 -d.)
else
version_serving="${technical_version_serving}"
version_eventing="${technical_version_eventing}"
fi
echo "-X '${pkg}.BuildDate=${now}' \
-X ${pkg}.Version=${version} \
-X ${pkg}.GitRevision=${rev} \
Expand Down

0 comments on commit 587a4a8

Please sign in to comment.