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 #74

Merged
merged 1 commit into from
Jun 24, 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
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 @@
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