Fix version info -v/--version (#138)

Co-authored-by: James Mills <prologic@shortcircuit.net.au>
Reviewed-on: #138
Reviewed-by: xuu <xuu@noreply@mills.io>
pull/140/head
James Mills 6 months ago
parent e8110e2a86
commit 668cae61b7
  1. 4
      Makefile
  2. 15
      version.go
  3. 15
      version_test.go

@ -2,8 +2,8 @@
.PHONY: help deps dev build install image release test clean clean-all
export CGO_ENABLED=0
VERSION=$(shell git describe --abbrev=0 --tags 2>/dev/null || echo "$VERSION")
COMMIT=$(shell git rev-parse --short HEAD || echo "$COMMIT")
VERSION=$(shell git describe --abbrev=0 --tags 2>/dev/null || echo "0.0.0")
COMMIT=$(shell git rev-parse --short HEAD || echo "HEAD")
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
GOCMD=go
GOVER=$(shell go version | grep -o -E 'go1\.17\.[0-9]+')

@ -2,11 +2,12 @@ package saltyim
import (
"fmt"
"runtime/debug"
)
var (
// Version release version
Version = "0.0.1"
Version = "0.0.0"
// Commit will be overwritten automatically by the build system
Commit = "HEAD"
@ -14,5 +15,15 @@ var (
// FullVersion display the full version and build
func FullVersion() string {
return fmt.Sprintf("%s@%s", Version, Commit)
if Version != "0.0.0" && Commit != "HEAD" {
return fmt.Sprintf("%s@%s", Version, Commit)
}
info, ok := debug.ReadBuildInfo()
if !ok {
return "unknown"
}
return fmt.Sprintf(
"%s built with %s (checksum: %s)",
info.Main.Version, info.GoVersion, info.Main.Sum,
)
}

@ -1,15 +0,0 @@
package saltyim
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestFullVersion(t *testing.T) {
assert := assert.New(t)
expected := fmt.Sprintf("%s@%s", Version, Commit)
assert.Equal(expected, FullVersion())
}
Loading…
Cancel
Save