summaryrefslogtreecommitdiffhomepage
path: root/internal/version/version.go
blob: 69fd5282b2cb5f0b61809dd05b2ae00c3b7b9d2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package version

import "runtime/debug"

// Build-time parameters set via -ldflags
var Version = "unknown"

// A user may install pug using `go install github.com/sst/opencode@latest`.
// without -ldflags, in which case the version above is unset. As a workaround
// we use the embedded build version that *is* set when using `go install` (and
// is only set for `go install` and not for `go build`).
func init() {
	info, ok := debug.ReadBuildInfo()
	if !ok {
		// < go v1.18
		return
	}
	mainVersion := info.Main.Version
	if mainVersion == "" || mainVersion == "(devel)" {
		// bin not built using `go install`
		return
	}
	// bin built using `go install`
	Version = mainVersion
}