From ace54a333b09db5d63bc6e5dc9319741df1b4ab1 Mon Sep 17 00:00:00 2001 From: Ivan Shvedunov Date: Tue, 17 Apr 2018 14:32:47 +0300 Subject: [PATCH] Add virtletctl version --- build/cmd.sh | 51 ++-- cmd/virtlet/virtlet.go | 23 +- cmd/virtletctl/virtletctl.go | 1 + pkg/tools/TestVersionCommand__bad.out.txt | 0 pkg/tools/TestVersionCommand__client.out.txt | 8 + .../TestVersionCommand__client_json.out.json | 1 + .../TestVersionCommand__client_json.out.txt | 1 + .../TestVersionCommand__client_short.out.txt | 1 + .../TestVersionCommand__client_yaml.out.txt | 11 + .../TestVersionCommand__client_yaml.out.yaml | 11 + .../TestVersionCommand__inconsistent.out.txt | 22 ++ pkg/tools/TestVersionCommand__json.out.json | 1 + pkg/tools/TestVersionCommand__json.out.txt | 1 + pkg/tools/TestVersionCommand__short.out.txt | 3 + pkg/tools/TestVersionCommand__text.out.txt | 22 ++ pkg/tools/TestVersionCommand__text_01.out.txt | 8 + .../TestVersionCommand__text__empty.out.txt | 8 + pkg/tools/TestVersionCommand__yaml.out.txt | 34 +++ pkg/tools/TestVersionCommand__yaml.out.yaml | 34 +++ pkg/tools/gen.go | 2 +- pkg/tools/version.go | 124 ++++++++++ pkg/tools/version_test.go | 218 ++++++++++++++++++ pkg/version/TestClusterVersion__json.out.json | 1 + .../TestClusterVersion__json__empty.out.json | 1 + pkg/version/TestClusterVersion__short.out.txt | 3 + .../TestClusterVersion__short__empty.out.txt | 1 + pkg/version/TestClusterVersion__text.out.txt | 22 ++ .../TestClusterVersion__text__empty.out.txt | 8 + pkg/version/TestClusterVersion__yaml.out.yaml | 34 +++ .../TestClusterVersion__yaml__empty.out.yaml | 11 + pkg/version/TestVersion__json.out.json | 1 + pkg/version/TestVersion__short.out.txt | 1 + pkg/version/TestVersion__text.out.txt | 7 + pkg/version/TestVersion__yaml.out.yaml | 10 + pkg/version/vars.go | 10 +- pkg/version/version.go | 192 +++++++++++++++ pkg/version/version_test.go | 164 +++++++++++++ 37 files changed, 1030 insertions(+), 21 deletions(-) create mode 100755 pkg/tools/TestVersionCommand__bad.out.txt create mode 100755 pkg/tools/TestVersionCommand__client.out.txt create mode 100755 pkg/tools/TestVersionCommand__client_json.out.json create mode 100755 pkg/tools/TestVersionCommand__client_json.out.txt create mode 100755 pkg/tools/TestVersionCommand__client_short.out.txt create mode 100755 pkg/tools/TestVersionCommand__client_yaml.out.txt create mode 100755 pkg/tools/TestVersionCommand__client_yaml.out.yaml create mode 100755 pkg/tools/TestVersionCommand__inconsistent.out.txt create mode 100755 pkg/tools/TestVersionCommand__json.out.json create mode 100755 pkg/tools/TestVersionCommand__json.out.txt create mode 100755 pkg/tools/TestVersionCommand__short.out.txt create mode 100755 pkg/tools/TestVersionCommand__text.out.txt create mode 100755 pkg/tools/TestVersionCommand__text_01.out.txt create mode 100755 pkg/tools/TestVersionCommand__text__empty.out.txt create mode 100755 pkg/tools/TestVersionCommand__yaml.out.txt create mode 100755 pkg/tools/TestVersionCommand__yaml.out.yaml create mode 100644 pkg/tools/version.go create mode 100644 pkg/tools/version_test.go create mode 100755 pkg/version/TestClusterVersion__json.out.json create mode 100755 pkg/version/TestClusterVersion__json__empty.out.json create mode 100755 pkg/version/TestClusterVersion__short.out.txt create mode 100755 pkg/version/TestClusterVersion__short__empty.out.txt create mode 100755 pkg/version/TestClusterVersion__text.out.txt create mode 100755 pkg/version/TestClusterVersion__text__empty.out.txt create mode 100755 pkg/version/TestClusterVersion__yaml.out.yaml create mode 100755 pkg/version/TestClusterVersion__yaml__empty.out.yaml create mode 100755 pkg/version/TestVersion__json.out.json create mode 100755 pkg/version/TestVersion__short.out.txt create mode 100755 pkg/version/TestVersion__text.out.txt create mode 100755 pkg/version/TestVersion__yaml.out.yaml create mode 100644 pkg/version/version.go create mode 100644 pkg/version/version_test.go diff --git a/build/cmd.sh b/build/cmd.sh index f13f1068f..6ff548b2b 100755 --- a/build/cmd.sh +++ b/build/cmd.sh @@ -40,6 +40,8 @@ bindata_modtime=1522279343 bindata_out="pkg/tools/bindata.go" bindata_dir="deploy/data" bindata_pkg="tools" +ldflags=() +go_package=github.com/Mirantis/virtlet function image_tags_filter { local tag="${1}" @@ -367,18 +369,37 @@ function run_integration_internal { ( cd tests/integration && ./go.test ) } -function set_version { - # TODO: always generate & set version in addition to the tag - if [[ ! ${SET_VIRTLET_IMAGE_TAG:-} ]]; then - return +function get_ldflags { + # XXX: use kube::version::ldflag (-ldflags -X package.Var=...) + # see also versioning.mk in helm + # https://stackoverflow.com/questions/11354518/golang-application-auto-build-versioning + # see pkg/version/version.go in k8s + # for GoVersion / Compiler / Platform + local vfile="${project_dir}/pkg/version/version.go" + local git_version="$(git describe --tags --abbrev=14 'HEAD^{commit}' | sed "s/-g\([0-9a-f]\{14\}\)$/+\1/")" + local git_commit="$(git rev-parse "HEAD^{commit}")" + local git_tree_state=$([[ $(git status --porcelain) ]] && echo "dirty" || echo "clean") + if [[ ${git_tree_state} == dirty ]]; then + git_version+="-dirty" fi - cat >"${project_dir}/pkg/version/version.go" <