Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: --version flag includes release version #149

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"

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 @@
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"
}
Loading