Skip to content

Commit

Permalink
fix: --version flag includes release version
Browse files Browse the repository at this point in the history
Porting fix from ipfs/rainbow#149
  • Loading branch information
lidel committed Jun 21, 2024
1 parent 445c611 commit dbe26c4
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"

Check warning on line 30 in version.go

View check run for this annotation

Codecov / codecov/patch

version.go#L30

Added line #L30 was not covered by tests
}
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)

Check warning on line 47 in version.go

View check run for this annotation

Codecov / codecov/patch

version.go#L47

Added line #L47 was not covered by tests
}
return "dev-build"
return release + " dev-build"
}

0 comments on commit dbe26c4

Please sign in to comment.