summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-04-02 15:40:09 +0200
committerLibravatar GitHub <noreply@github.com>2022-04-02 15:40:09 +0200
commit03d7c75ebf1b81b12ec21f95eef1c07b265ff939 (patch)
tree511724f53946563a3b7ba1307d25f5bda98ac3a8 /cmd
parent[documentation] Add third-party packaging to documentation (#443) (diff)
downloadgotosocial-03d7c75ebf1b81b12ec21f95eef1c07b265ff939.tar.xz
[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
Diffstat (limited to 'cmd')
-rw-r--r--cmd/gotosocial/main.go38
1 files changed, 27 insertions, 11 deletions
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,
}