diff --git a/.goreleaser.yml b/.goreleaser.yml index d8de2151..391379c4 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -30,10 +30,6 @@ builds: goarch: arm64 flags: - -trimpath - # #1031: don't include the git hash in an official build - # default is: "-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser" - ldflags: - - "-s -w -X main.build={{.Version}}" archives: - diff --git a/Makefile b/Makefile index 7422c315..2a5043d7 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: all install build release capdefs test smoke -GIT_COMMIT := $(shell git rev-parse --short=16 HEAD 2> /dev/null) +GIT_COMMIT := $(shell git rev-parse HEAD 2> /dev/null) capdef_file = ./irc/caps/defs.go diff --git a/irc/constants.go b/irc/constants.go index 311aaf1a..975e9953 100644 --- a/irc/constants.go +++ b/irc/constants.go @@ -5,20 +5,7 @@ package irc -import "fmt" - const ( - // SemVer is the semantic version of Oragono. - SemVer = "2.1.0-unreleased" -) - -var ( - // Commit is the current git commit. - Commit = "" - - // Ver is the full version of Oragono, used in responses to clients. - Ver = fmt.Sprintf("oragono-%s", SemVer) - // maxLastArgLength is used to simply cap off the final argument when creating general messages where we need to select a limit. // for instance, in MONITOR lists, RPL_ISUPPORT lists, etc. maxLastArgLength = 400 diff --git a/irc/version.go b/irc/version.go new file mode 100644 index 00000000..217e47fd --- /dev/null +++ b/irc/version.go @@ -0,0 +1,28 @@ +// Copyright (c) 2020 Shivaram Lingamneni +// Released under the MIT license + +package irc + +import "fmt" + +const ( + // SemVer is the semantic version of Oragono. + SemVer = "2.1.0-unreleased" +) + +var ( + // Ver is the full version of Oragono, used in responses to clients. + Ver = fmt.Sprintf("oragono-%s", SemVer) + // Commit is the full git hash, if available + Commit string +) + +// initialize version strings (these are set in package main via linker flags) +func SetVersionString(version, commit string) { + Commit = commit + if version != "" { + Ver = fmt.Sprintf("oragono-%s", version) + } else if len(Commit) == 40 { + Ver = fmt.Sprintf("oragono-%s-%s", SemVer, Commit[:16]) + } +} diff --git a/oragono.go b/oragono.go index 955924c4..e7ef49b3 100644 --- a/oragono.go +++ b/oragono.go @@ -21,7 +21,9 @@ import ( "golang.org/x/crypto/ssh/terminal" ) -var commit = "" +// set via linker flags, either by make or by goreleaser: +var commit = "" // git hash +var version = "" // tagged version // get a password from stdin from the user func getPassword() string { @@ -89,7 +91,7 @@ func doMkcerts(configFile string, quiet bool) { } func main() { - version := irc.SemVer + irc.SetVersionString(version, commit) usage := `oragono. Usage: oragono initdb [--conf ] [--quiet] @@ -105,7 +107,7 @@ Options: -h --help Show this screen. --version Show version.` - arguments, _ := docopt.ParseArgs(usage, nil, version) + arguments, _ := docopt.ParseArgs(usage, nil, irc.Ver) // don't require a config file for genpasswd if arguments["genpasswd"].(bool) { @@ -167,22 +169,11 @@ Options: } } else if arguments["run"].(bool) { if !arguments["--quiet"].(bool) { - logman.Info("server", fmt.Sprintf("Oragono v%s starting", irc.SemVer)) - if commit == "" { - logman.Debug("server", fmt.Sprintf("Could not get current commit")) - } else { - logman.Info("server", fmt.Sprintf("Running commit %s", commit)) - } - } - - // set current git commit - irc.Commit = commit - if commit != "" { - irc.Ver = fmt.Sprintf("%s-%s", irc.Ver, commit) + logman.Info("server", fmt.Sprintf("%s starting", irc.Ver)) } // warning if running a non-final version - if strings.Contains(irc.SemVer, "unreleased") { + if strings.Contains(irc.Ver, "unreleased") { logman.Warning("server", "You are currently running an unreleased beta version of Oragono that may be unstable and could corrupt your database.\nIf you are running a production network, please download the latest build from https://oragono.io/downloads.html and run that instead.") }