Use dynamic version

This commit is contained in:
Manfred Touron 2017-11-14 00:38:23 +01:00
parent 8d6a76a93b
commit 0b137e1939
3 changed files with 24 additions and 5 deletions

View file

@ -1,6 +1,12 @@
PACKAGE ?= github.com/moul/sshportal
GIT_SHA ?= $(shell git rev-parse HEAD)
GIT_TAG ?= $(shell git describe --tags --always)
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
LDFLAGS ?= "-X $(PACKAGE)/main.GIT_SHA=$(GIT_SHA) -X $(PACKAGE)/main.GIT_TAG=$(GIT_TAG) -X $(PACKAGE)/main.GIT_BRANCH=$(GIT_BRANCH)"
.PHONY: install
install:
go install .
go install -ldflags $(LDFLAGS) .
.PHONY: dev
dev:

13
main.go
View file

@ -16,7 +16,16 @@ import (
gossh "golang.org/x/crypto/ssh"
)
var version = "0.0.1"
var (
// VERSION should be updated by hand at each release
VERSION = "1.0.0"
// GIT_TAG will be overwritten automatically by the build system
GIT_TAG = ""
// GIT_SHA will be overwritten automatically by the build system
GIT_SHA = ""
// GIT_BRANCH will be overwritten automatically by the build system
GIT_BRANCH = ""
)
type sshportalContextKey string
@ -30,7 +39,7 @@ func main() {
app := cli.NewApp()
app.Name = path.Base(os.Args[0])
app.Author = "Manfred Touron"
app.Version = version
app.Version = VERSION + "(" + GIT_SHA + ")"
app.Email = "https://github.com/moul/sshportal"
app.Flags = []cli.Flag{
cli.StringFlag{

View file

@ -580,7 +580,11 @@ GLOBAL OPTIONS:
myself := s.Context().Value(userContextKey).(User)
fmt.Fprintf(s, "User email: %v\n", myself.ID)
fmt.Fprintf(s, "User email: %s\n", myself.Email)
// FIXME: add version
fmt.Fprintf(s, "Version: %s\n", VERSION)
fmt.Fprintf(s, "GIT SHA: %s\n", GIT_SHA)
fmt.Fprintf(s, "GIT Branch: %s\n", GIT_BRANCH)
fmt.Fprintf(s, "GIT Tag: %s\n", GIT_TAG)
// FIXME: add info about current server (network, cpu, ram, OS)
// FIXME: add info about current user
// FIXME: add active connections
@ -1023,7 +1027,7 @@ GLOBAL OPTIONS:
Name: "version",
Usage: "Shows the SSHPortal version information",
Action: func(c *cli.Context) error {
fmt.Fprintf(s, "%s\n", version)
fmt.Fprintf(s, "%s\n", VERSION)
return nil
},
}, {