From 03d7c75ebf1b81b12ec21f95eef1c07b265ff939 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Sat, 2 Apr 2022 15:40:09 +0200 Subject: [chore] Update Go version to 1.18 (#444) * linting with new golangci-lint version * update go to 1.18 * bump versions in drone.yml * use new runtime/debug package for version info * remove Commit build flag from goreleaser * remove mock commit + version from build script * go fmt * add dummy version env flag to test container * install git in golang container for testing * only set versionString if Version is defined --- cmd/gotosocial/main.go | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'cmd') diff --git a/cmd/gotosocial/main.go b/cmd/gotosocial/main.go index b8decf5f2..49560503f 100644 --- a/cmd/gotosocial/main.go +++ b/cmd/gotosocial/main.go @@ -19,6 +19,9 @@ package main import ( + "fmt" + "runtime/debug" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -28,30 +31,43 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/config" ) -// Version is the software version of GtS being used. +// Version is the version of GoToSocial being used. +// It's injected into the binary by the build script. var Version string -// Commit is the git commit of GtS being used. -var Commit string - //go:generate swagger generate spec func main() { - var v string - if len(Commit) < 7 { - v = Version - } else { - v = Version + " " + Commit[:7] + buildInfo, ok := debug.ReadBuildInfo() + if !ok { + panic("could not read buildinfo") + } + + goVersion := buildInfo.GoVersion + var commit string + var time string + for _, s := range buildInfo.Settings { + if s.Key == "vcs.revision" { + commit = s.Value[:7] + } + if s.Key == "vcs.time" { + time = s.Value + } + } + + var versionString string + if Version != "" { + versionString = fmt.Sprintf("%s %s %s [%s]", Version, commit, time, goVersion) } // override software version in viper store - viper.Set(config.Keys.SoftwareVersion, v) + viper.Set(config.Keys.SoftwareVersion, versionString) // instantiate the root command rootCmd := &cobra.Command{ Use: "gotosocial", Short: "GoToSocial - a fediverse social media server", Long: "GoToSocial - a fediverse social media server\n\nFor help, see: https://docs.gotosocial.org.\n\nCode: https://github.com/superseriousbusiness/gotosocial", - Version: v, + Version: versionString, SilenceErrors: true, SilenceUsage: true, } -- cgit v1.3