Skip to content

Commit

Permalink
fix: --version flag includes release version (#149)
Browse files Browse the repository at this point in the history
The tagged release version should match the contents of version.json, 
so embed the version.json file and add the release version from it
 to the output from --version.

Fixes #145
  • Loading branch information
gammazero authored Jun 20, 2024
1 parent 7d805fd commit eccc6d5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The following emojis are used to highlight certain changes:
### Fixed

- Added more buckets to the duration histogram metric to allow for tracking operations that take longer than 1 minute.
- Release version included in --version output.

### Security

Expand Down
17 changes: 14 additions & 3 deletions version.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
package main

import (
_ "embed"
"encoding/json"
"fmt"
"runtime/debug"
"time"
)

//go:embed version.json
var versionJSON []byte

var name = "rainbow"
var version = buildVersion()
var userAgent = name + "/" + version

func buildVersion() string {
// Read version from embedded JSON file.
var verMap map[string]string
json.Unmarshal(versionJSON, &verMap)
release := verMap["version"]

var revision string
var day string
var dirty bool

info, ok := debug.ReadBuildInfo()
if !ok {
return "dev-build"
return release + " dev-build"
}
for _, kv := range info.Settings {
switch kv.Key {
Expand All @@ -33,7 +44,7 @@ func buildVersion() string {
revision += "-dirty"
}
if revision != "" {
return day + "-" + revision
return fmt.Sprintf("%s %s-%s", release, day, revision)
}
return "dev-build"
return release + " dev-build"
}

0 comments on commit eccc6d5

Please sign in to comment.