Browse Source

tweak version strings again

tags/v2.1.0-rc1
Shivaram Lingamneni 4 years ago
parent
commit
464d0be949
5 changed files with 36 additions and 34 deletions
  1. 0
    4
      .goreleaser.yml
  2. 1
    1
      Makefile
  3. 0
    13
      irc/constants.go
  4. 28
    0
      irc/version.go
  5. 7
    16
      oragono.go

+ 0
- 4
.goreleaser.yml View File

@@ -30,10 +30,6 @@ builds:
30 30
         goarch: arm64
31 31
     flags:
32 32
       - -trimpath
33
-    # #1031: don't include the git hash in an official build
34
-    # default is: "-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser"
35
-    ldflags:
36
-      - "-s -w -X main.build={{.Version}}"
37 33
 
38 34
 archives:
39 35
   -

+ 1
- 1
Makefile View File

@@ -1,6 +1,6 @@
1 1
 .PHONY: all install build release capdefs test smoke
2 2
 
3
-GIT_COMMIT := $(shell git rev-parse --short=16 HEAD 2> /dev/null)
3
+GIT_COMMIT := $(shell git rev-parse HEAD 2> /dev/null)
4 4
 
5 5
 capdef_file = ./irc/caps/defs.go
6 6
 

+ 0
- 13
irc/constants.go View File

@@ -5,20 +5,7 @@
5 5
 
6 6
 package irc
7 7
 
8
-import "fmt"
9
-
10 8
 const (
11
-	// SemVer is the semantic version of Oragono.
12
-	SemVer = "2.1.0-unreleased"
13
-)
14
-
15
-var (
16
-	// Commit is the current git commit.
17
-	Commit = ""
18
-
19
-	// Ver is the full version of Oragono, used in responses to clients.
20
-	Ver = fmt.Sprintf("oragono-%s", SemVer)
21
-
22 9
 	// maxLastArgLength is used to simply cap off the final argument when creating general messages where we need to select a limit.
23 10
 	// for instance, in MONITOR lists, RPL_ISUPPORT lists, etc.
24 11
 	maxLastArgLength = 400

+ 28
- 0
irc/version.go View File

@@ -0,0 +1,28 @@
1
+// Copyright (c) 2020 Shivaram Lingamneni
2
+// Released under the MIT license
3
+
4
+package irc
5
+
6
+import "fmt"
7
+
8
+const (
9
+	// SemVer is the semantic version of Oragono.
10
+	SemVer = "2.1.0-unreleased"
11
+)
12
+
13
+var (
14
+	// Ver is the full version of Oragono, used in responses to clients.
15
+	Ver = fmt.Sprintf("oragono-%s", SemVer)
16
+	// Commit is the full git hash, if available
17
+	Commit string
18
+)
19
+
20
+// initialize version strings (these are set in package main via linker flags)
21
+func SetVersionString(version, commit string) {
22
+	Commit = commit
23
+	if version != "" {
24
+		Ver = fmt.Sprintf("oragono-%s", version)
25
+	} else if len(Commit) == 40 {
26
+		Ver = fmt.Sprintf("oragono-%s-%s", SemVer, Commit[:16])
27
+	}
28
+}

+ 7
- 16
oragono.go View File

@@ -21,7 +21,9 @@ import (
21 21
 	"golang.org/x/crypto/ssh/terminal"
22 22
 )
23 23
 
24
-var commit = ""
24
+// set via linker flags, either by make or by goreleaser:
25
+var commit = ""  // git hash
26
+var version = "" // tagged version
25 27
 
26 28
 // get a password from stdin from the user
27 29
 func getPassword() string {
@@ -89,7 +91,7 @@ func doMkcerts(configFile string, quiet bool) {
89 91
 }
90 92
 
91 93
 func main() {
92
-	version := irc.SemVer
94
+	irc.SetVersionString(version, commit)
93 95
 	usage := `oragono.
94 96
 Usage:
95 97
 	oragono initdb [--conf <filename>] [--quiet]
@@ -105,7 +107,7 @@ Options:
105 107
 	-h --help          Show this screen.
106 108
 	--version          Show version.`
107 109
 
108
-	arguments, _ := docopt.ParseArgs(usage, nil, version)
110
+	arguments, _ := docopt.ParseArgs(usage, nil, irc.Ver)
109 111
 
110 112
 	// don't require a config file for genpasswd
111 113
 	if arguments["genpasswd"].(bool) {
@@ -167,22 +169,11 @@ Options:
167 169
 		}
168 170
 	} else if arguments["run"].(bool) {
169 171
 		if !arguments["--quiet"].(bool) {
170
-			logman.Info("server", fmt.Sprintf("Oragono v%s starting", irc.SemVer))
171
-			if commit == "" {
172
-				logman.Debug("server", fmt.Sprintf("Could not get current commit"))
173
-			} else {
174
-				logman.Info("server", fmt.Sprintf("Running commit %s", commit))
175
-			}
176
-		}
177
-
178
-		// set current git commit
179
-		irc.Commit = commit
180
-		if commit != "" {
181
-			irc.Ver = fmt.Sprintf("%s-%s", irc.Ver, commit)
172
+			logman.Info("server", fmt.Sprintf("%s starting", irc.Ver))
182 173
 		}
183 174
 
184 175
 		// warning if running a non-final version
185
-		if strings.Contains(irc.SemVer, "unreleased") {
176
+		if strings.Contains(irc.Ver, "unreleased") {
186 177
 			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.")
187 178
 		}
188 179
 

Loading…
Cancel
Save