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: [#1275] Return version if regal installed using go install #1276

Closed
Closed
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
4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
"OPA_CHECK_CAPABILITIES": "${workspacePath}/build/capabilities.json",
"OPA_EVAL_CAPABILITIES": "${workspacePath}/build/capabilities.json"
},
"opa.roots": [
"${workspaceFolder}/bundle"
],
"opa.roots": ["${workspaceFolder}/bundle"],
"opa.strictMode": true
}
10 changes: 9 additions & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (vi Info) String() string {

func New() Info {
return Info{
Version: unknownString(Version),
Version: unknownVersionString(Version),
GoVersion: goVersion,
Platform: platform,
Commit: unknownString(Commit),
Expand All @@ -67,3 +67,11 @@ func unknownString(s string) string {

return s
}

func unknownVersionString(s string) string {
if s == "" {
return "v.29.3"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would need to be updated continuously with each new release, and I don't think that's feasible.

Looking at one of the links you provided, and as @srenatus previously mentioned, this method looks more appealing https://github.com/vektra/mockery/blob/master/pkg/logging/logging.go#L36-L45

Would you want to give that a shot?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried, but I wonder whether it will work: golang/go#50603 (comment)

Locally I have tried:

func buildVersion() string {
	version, ok := debug.ReadBuildInfo()
	fmt.Println("----------", version.Main.Version)
	if ok && version.Main.Version != "(devel)" && version.Main.Version != "" {
		return version.Main.Version
	}
	return "unknown"
}
func New() Info {
	return Info{
		Version:   buildVersion(),
		GoVersion: goVersion,
		Platform:  platform,
		Commit:    unknownString(Commit),
		Timestamp: unknownString(Timestamp),
		Hostname:  unknownString(Hostname),
	}
}

and

go build -ldflags "-s -w -X github.com/styrainc/regal/pkg/version.Version=1.2.3"

./regal version

---------- (devel)
Version:    unknown
Go Version: go1.23.3
Platform:   darwin/arm64
Commit:     unknown
Timestamp:  unknown
Hostname:   unknown

}

return s
}
Loading