diff --git a/Makefile b/Makefile index 8cdcecd..ee35d77 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/main.go b/main.go index d6e6d04..6d2b53b 100644 --- a/main.go +++ b/main.go @@ -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{ diff --git a/shell.go b/shell.go index 7108de8..4d49af6 100644 --- a/shell.go +++ b/shell.go @@ -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 }, }, {