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

Conversation

sbp-bvanb
Copy link

@sbp-bvanb sbp-bvanb commented Nov 25, 2024

Return version if regal is installed using go install.


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

@anderseknert
Copy link
Member

@sbp-bvanb yeah, having looked into this tonight, I don't think I've seen a single project where this works without having some external script setting the version somewhere in a file, and then have that read for this data.

From what I now gather, the "module version" we thought would work here is merely the version that could possibly be extracted from the module path, like "v2" in "github.com/styrainc/regal/v2" if that was a thing. Sorry if I led you astray here.

Like I said before, I think we can rule out any system that requires us to update some file manually each time we push a release. That's prone to being forgotten about, or be done wrong. So the alternative that remains would be to have a github action or similar do this for us. Or perhaps if Goreleaser can do something like that. I'll leave your issue open for ideas, but I think we can close this PR for now as neither your or my own attempts to get it working this way got where we wanted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants