vt version doesn't print the version number
melomac opened this issue · comments
I wanted to check my current vt CLI version (Homebrew) and was surprised to see vt version
didn't print any version number.
So I checked out the repo to find out this is a current problem:
$ make
$ make install
$ ~/go/bin/vt version
vt-cli
And I verified on an old setup, this isn't a regression as of commit 031203cad77b
.
This looks like VERSION
isn't set by defaults. On setting VERSION manually, this does work:
vt-cli (master)> make clean
rm -rf ./build
vt-cli (master)> env VERSION=test make
go build -ldflags "-X github.com/VirusTotal/vt-cli/cmd.Version=test" -o ./build/vt ./vt/main.go
vt-cli (master)> ./build/vt version
vt-cli test
Builds attached to this page prints the version number correctly.
Would you please consider a way to setup VERSION
on manual build? ex: closest tag dash closest commit
May be something like this:
diff --git a/Makefile b/Makefile
index 9e76939..a8c9c3a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,15 @@
# This how we want to name the binary output
BINARY=./build/vt
+COMMIT := $(shell git rev-parse --short HEAD)
+TAG := $(shell git describe --tags $(COMMIT))
+ifneq ($(shell git status --porcelain),)
+ COMMIT := dirty
+endif
+ifeq ($(VERSION),)
+ VERSION := $(TAG)-$(COMMIT)
+endif
+
# Setup the -ldflags option for go build here, interpolate the variable values
LDFLAGS=-ldflags "-X github.com/VirusTotal/vt-cli/cmd.Version=${VERSION}"
I tried downloading one of the binaries from our release downloads page (https://github.com/VirusTotal/vt-cli/releases/tag/0.10.4) and it worked:
$ ./vt version
vt-cli 0.10.4
The version is set in our release pipeline:
vt-cli/.github/workflows/release.yaml
Lines 23 to 30 in 6b82e3a
Probably it's the homebrew formula which needs to be fixed? https://github.com/Homebrew/homebrew-core/blob/master/Formula/virustotal-cli.rb