Skip to content

Commit 127bf5a

Browse files
authored
Merge pull request #24 from persona-id/kuzmik/fix-versioning
fix: fix the versioning info that goreleaser injects into the ldflags
2 parents 77c8841 + c1df2ec commit 127bf5a

File tree

1 file changed

+8
-34
lines changed

1 file changed

+8
-34
lines changed

cmd/proxysql-agent/main.go

+8-34
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"log/slog"
55
"os"
6-
"runtime/debug"
76
"time"
87

98
"github.com/persona-id/proxysql-agent/internal/configuration"
@@ -13,41 +12,16 @@ import (
1312

1413
var (
1514
// Version will be the version tag if the binary is built with "go install url/tool@version".
16-
// If the binary is built some other way, it will be "(devel)".
17-
Version = "unknown" //nolint:gochecknoglobals
18-
// Revision is taken from the vcs.revision tag in Go 1.18+.
19-
Revision = "unknown" //nolint:gochecknoglobals
20-
// LastCommit is taken from the vcs.time tag in Go 1.18+.
21-
LastCommit time.Time //nolint:gochecknoglobals
22-
// DirtyBuild is taken from the vcs.modified tag in Go 1.18+.
23-
DirtyBuild = true //nolint:gochecknoglobals
15+
// See https://goreleaser.com/cookbooks/using-main.version/
16+
// Current git tag.
17+
version = "unknown" //nolint:gochecknoglobals
18+
// Current git commit sha.
19+
commit = "unknown" //nolint:gochecknoglobals
20+
// Built at date.
21+
date = "unknown" //nolint:gochecknoglobals
2422
)
2523

26-
func getVersionInfo() {
27-
info, ok := debug.ReadBuildInfo()
28-
if !ok {
29-
return
30-
}
31-
32-
for _, kv := range info.Settings {
33-
if kv.Value == "" {
34-
continue
35-
}
36-
37-
switch kv.Key {
38-
case "vcs.revision":
39-
Revision = kv.Value
40-
case "vcs.time":
41-
LastCommit, _ = time.Parse(time.RFC3339, kv.Value)
42-
case "vcs.modified":
43-
DirtyBuild = kv.Value == "true"
44-
}
45-
}
46-
}
47-
4824
func main() {
49-
getVersionInfo()
50-
5125
settings, err := configuration.Configure()
5226
if err != nil {
5327
slog.Error("Error in Configure()", slog.Any("err", err))
@@ -56,7 +30,7 @@ func main() {
5630

5731
setupLogger(settings)
5832

59-
slog.Info("build info", slog.Any("version", Version), slog.Any("committed", LastCommit), slog.Any("revision", Revision), slog.Any("dirty", DirtyBuild))
33+
slog.Info("build info", slog.Any("version", version), slog.Any("committed", date), slog.Any("revision", commit))
6034

6135
// if defined, pause before booting; this allows the proxysql containers to fully come up before the agent tries
6236
// connecting; sometimes the proxysql container can take a few seconds to fully start. This is mainly only

0 commit comments

Comments
 (0)