Skip to content
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
6 changes: 4 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ builds:

archives:
- id: default
format: tar.gz
formats:
- tar.gz
name_template: >-
{{ .ProjectName }}_
{{- .Version }}_
Expand All @@ -42,7 +43,8 @@ archives:
{{- if .Arm }}v{{ .Arm }}{{ end }}
format_overrides:
- goos: windows
format: zip
formats:
- zip
files:
- LICENSE
- README.md
Expand Down
29 changes: 29 additions & 0 deletions internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package version
import (
"fmt"
"runtime"
"runtime/debug"
)

// These variables are set at build time using ldflags.
Expand All @@ -19,6 +20,34 @@ var (
Date = "unknown"
)

func init() {
// If version wasn't set via ldflags, try to get it from build info.
// This works when installed via "go install module@version".
if Version == "dev" {
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "" && info.Main.Version != "(devel)" {
Version = info.Main.Version
}
}

// Try to get commit and date from build settings if not set via ldflags.
if Commit == "none" || Date == "unknown" {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
switch setting.Key {
case "vcs.revision":
if Commit == "none" && len(setting.Value) >= 7 {
Commit = setting.Value[:7]
}
case "vcs.time":
if Date == "unknown" {
Date = setting.Value
}
}
}
}
}
}

// Info returns formatted version information.
func Info() string {
return fmt.Sprintf("daco version %s (commit: %s, built: %s, go: %s)",
Expand Down
Loading