From c25d0bef6734d32cb5138864c7bf46934952ff1f Mon Sep 17 00:00:00 2001 From: Marcel van der Boom Date: Tue, 20 Nov 2018 14:21:13 +0100 Subject: [PATCH 1/2] Get versioninfo from the git repository Sets value of softwareVer during build --- Makefile | 9 ++++++--- app.go | 8 +++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 09a216f..308c6e8 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,10 @@ +GITREV=`git describe --tags` +LDFLAGS=-ldflags="-X 'github.com/writeas/writefreely.softwareVer=$(GITREV)'" + GOCMD=go -GOINSTALL=$(GOCMD) install -GOBUILD=$(GOCMD) build -GOTEST=$(GOCMD) test +GOINSTALL=$(GOCMD) install $(LDFLAGS) +GOBUILD=$(GOCMD) build $(LDFLAGS) +GOTEST=$(GOCMD) test $(LDFLAGS) GOGET=$(GOCMD) get BINARY_NAME=writefreely diff --git a/app.go b/app.go index 0514f38..35ce444 100644 --- a/app.go +++ b/app.go @@ -33,10 +33,12 @@ const ( serverSoftware = "WriteFreely" softwareURL = "https://writefreely.org" - - softwareVer = "0.3" ) +// Software version can be set from git env using -ldflags +var softwareVer = "v0.3" + + var ( debugging bool @@ -133,7 +135,7 @@ func pageForReq(app *app, r *http.Request) page.StaticPage { p := page.StaticPage{ AppCfg: app.cfg.App, Path: r.URL.Path, - Version: "v" + softwareVer, + Version: softwareVer, } // Add user information, if given From b030921691cf971cd2f057b50e3c5f240f4d6f1b Mon Sep 17 00:00:00 2001 From: Marcel van der Boom Date: Tue, 20 Nov 2018 18:14:02 +0100 Subject: [PATCH 2/2] Don't automatically include "v" from git - "v" should not be part of the version (softwareVer variable is used in other places) - formatting --- Makefile | 4 ++-- app.go | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 308c6e8..ee6414f 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -GITREV=`git describe --tags` +GITREV=`git describe --tags | cut -c 2-` LDFLAGS=-ldflags="-X 'github.com/writeas/writefreely.softwareVer=$(GITREV)'" GOCMD=go @@ -32,6 +32,6 @@ ui : force_look clean : cd less/; $(MAKE) clean $(MFLAGS) - + force_look : true diff --git a/app.go b/app.go index 35ce444..ada7392 100644 --- a/app.go +++ b/app.go @@ -36,8 +36,7 @@ const ( ) // Software version can be set from git env using -ldflags -var softwareVer = "v0.3" - +var softwareVer = "0.3" var ( debugging bool @@ -135,7 +134,7 @@ func pageForReq(app *app, r *http.Request) page.StaticPage { p := page.StaticPage{ AppCfg: app.cfg.App, Path: r.URL.Path, - Version: softwareVer, + Version: "v" + softwareVer, } // Add user information, if given