Skip to content

Commit

Permalink
fix: --version flag includes release version (#74)
Browse files Browse the repository at this point in the history
Porting fix from ipfs/rainbow#149
  • Loading branch information
lidel authored Jun 24, 2024
1 parent 3107878 commit 9e970a8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ The following emojis are used to highlight certain changes:

### Fixed

- Release tag version is now included in `--version` output.

### Security

## [v0.2.3]
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 = "someguy"
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 9e970a8

Please sign in to comment.