From dafa5a40890cc49fdbc5d4eaca35aabb0c53468e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=96stanb=C3=A4ck?= Date: Sat, 25 Feb 2017 13:16:49 +0100 Subject: [PATCH 1/5] Fix for #828 Add build tags to ldflags and print in version output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonas Östanbäck --- Makefile | 2 +- main.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e34fd9dc0b41..72be35228ef9 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ BINDATA := modules/{options,public,templates}/bindata.go STYLESHEETS := $(wildcard public/less/index.less public/less/_*.less) JAVASCRIPTS := -LDFLAGS := -X "main.Version=$(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')" +LDFLAGS := -X "main.Version=$(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')" -X "main.Tags=$(TAGS)" TARGETS ?= linux/*,darwin/*,windows/* PACKAGES ?= $(shell go list ./... | grep -v /vendor/) diff --git a/main.go b/main.go index b7e8244b4b29..d47f04c9bcb6 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ package main // import "code.gitea.io/gitea" import ( "os" + "strings" "code.gitea.io/gitea/cmd" "code.gitea.io/gitea/modules/log" @@ -18,6 +19,9 @@ import ( // Version holds the current Gitea version var Version = "1.1.0+dev" +// Tags holds the build tags used +var Tags = "" + func init() { setting.AppVer = Version } @@ -26,7 +30,7 @@ func main() { app := cli.NewApp() app.Name = "Gitea" app.Usage = "A painless self-hosted Git service" - app.Version = Version + app.Version = Version + formatBuiltWith(Tags) app.Commands = []cli.Command{ cmd.CmdWeb, cmd.CmdServ, @@ -42,3 +46,10 @@ func main() { } } + +func formatBuiltWith(Tags string) string { + if len(Tags) > 0 { + return " built with: " + strings.Join(strings.Split(Tags, " "), ", ") + } + return "" +} From c6737aca4aa4292f1e64999d92b126d5eeaa58ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=96stanb=C3=A4ck?= Date: Sat, 25 Feb 2017 16:20:44 +0100 Subject: [PATCH 2/5] Reworked formatBuiltWith function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonas Östanbäck --- main.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index d47f04c9bcb6..79bcc00d9020 100644 --- a/main.go +++ b/main.go @@ -48,8 +48,9 @@ func main() { } func formatBuiltWith(Tags string) string { - if len(Tags) > 0 { - return " built with: " + strings.Join(strings.Split(Tags, " "), ", ") - } - return "" + if len(Tags) == 0 { + return "" + } + + return " built with: " + strings.Replace(Tags, " ", ", ", -1) } From 2f81c12f244ff5cf64b1fd0b3de7bf5ae292ba0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=96stanb=C3=A4ck?= Date: Mon, 27 Feb 2017 09:54:47 +0100 Subject: [PATCH 3/5] Add tags to version information in admin panel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonas Östanbäck --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 79bcc00d9020..40d1aba94e1d 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,7 @@ var Version = "1.1.0+dev" var Tags = "" func init() { - setting.AppVer = Version + setting.AppVer = Version + formatBuiltWith(Tags) } func main() { From a0cb2c0d70f5a48213e8ab91613a30fd8dbf604d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=96stanb=C3=A4ck?= Date: Mon, 27 Feb 2017 13:09:38 +0100 Subject: [PATCH 4/5] Added new variable for use on admin page. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonas Östanbäck --- main.go | 3 ++- modules/setting/setting.go | 3 ++- modules/templates/helper.go | 3 +++ templates/admin/config.tmpl | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 40d1aba94e1d..b11676f637d9 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,8 @@ var Version = "1.1.0+dev" var Tags = "" func init() { - setting.AppVer = Version + formatBuiltWith(Tags) + setting.AppVer = Version + setting.AppBuiltWith = formatBuiltWith(Tags) } func main() { diff --git a/modules/setting/setting.go b/modules/setting/setting.go index dd06691dc3c4..bdece17ad4d1 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -59,6 +59,7 @@ const ( var ( // AppVer settings AppVer string + AppBuiltWith string AppName string AppURL string AppSubURL string @@ -939,7 +940,7 @@ var logLevels = map[string]string{ } func newLogService() { - log.Info("Gitea v%s", AppVer) + log.Info("Gitea v%s%s", AppVer, AppBuiltWith) LogModes = strings.Split(Cfg.Section("log").Key("MODE").MustString("console"), ",") LogConfigs = make([]string, len(LogModes)) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index b03128a0b1ec..9dee7a84f1ec 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -48,6 +48,9 @@ func NewFuncMap() []template.FuncMap { "AppVer": func() string { return setting.AppVer }, + "AppBuiltWith": func() string { + return setting.AppBuiltWith + }, "AppDomain": func() string { return setting.Domain }, diff --git a/templates/admin/config.tmpl b/templates/admin/config.tmpl index 12a25e8e5d71..ca12bbe05758 100644 --- a/templates/admin/config.tmpl +++ b/templates/admin/config.tmpl @@ -13,7 +13,7 @@
{{.i18n.Tr "admin.config.app_name"}}
{{AppName}}
{{.i18n.Tr "admin.config.app_ver"}}
-
{{AppVer}}
+
{{AppVer}}{{AppBuiltWith}}
{{.i18n.Tr "admin.config.app_url"}}
{{.AppUrl}}
{{.i18n.Tr "admin.config.domain"}}
From 9a928c30fabdfaaa2cd14317b42b544e5cb409c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=96stanb=C3=A4ck?= Date: Mon, 27 Feb 2017 15:01:30 +0100 Subject: [PATCH 5/5] Fixed incorrect indentation --- main.go | 6 +++--- modules/templates/helper.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index b11676f637d9..6925b524936e 100644 --- a/main.go +++ b/main.go @@ -50,8 +50,8 @@ func main() { func formatBuiltWith(Tags string) string { if len(Tags) == 0 { - return "" - } + return "" + } - return " built with: " + strings.Replace(Tags, " ", ", ", -1) + return " built with: " + strings.Replace(Tags, " ", ", ", -1) } diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 9dee7a84f1ec..1f510bda6ad8 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -48,9 +48,9 @@ func NewFuncMap() []template.FuncMap { "AppVer": func() string { return setting.AppVer }, - "AppBuiltWith": func() string { - return setting.AppBuiltWith - }, + "AppBuiltWith": func() string { + return setting.AppBuiltWith + }, "AppDomain": func() string { return setting.Domain },