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

proposal: Use version info from runtime/debug:BuildInfo when installed by go install #4358

Closed
MakDon opened this issue May 22, 2024 · 2 comments

Comments

@MakDon
Copy link
Contributor

MakDon commented May 22, 2024

As #3967 says, if we install gRPC-gateway using go install, then protoc-gen-grpc-gateway --version would outputs Version dev, commit unknown, built at unknown because the build info is not linked during build time.

But i found that golang provides runtime/debug:BuildInfo ,which may helps.

We could use the BuildInfo from it if vsc info is not linked by goreleaser:

	if commit == "unknown" {
		buildInfo, ok := debug.ReadBuildInfo()
		if ok {
			for _, setting := range buildInfo.Settings {
				if setting.Key == "vcs.revision" {
					commit = setting.Value
				}
				if setting.Key == "vcs.time" {
					date = setting.Value
				}
			}
			fmt.Printf("commit %v, built at %v\n", commit, date)
			os.Exit(0)
		}
	}
			

And then check if it works:

➜  grpc-gateway git:(master) ✗ cd ..
➜  dev mkdir tmp
➜  dev 
➜  dev cd tmp 
➜  tmp git clone git@github.com:MakDon/grpc-gateway.git
Cloning into 'grpc-gateway'...
remote: Enumerating objects: 22297, done.
remote: Counting objects: 100% (3444/3444), done.
remote: Compressing objects: 100% (443/443), done.
remote: Total 22297 (delta 3295), reused 3036 (delta 2997), pack-reused 18853
Receiving objects: 100% (22297/22297), 9.03 MiB | 3.20 MiB/s, done.
Resolving deltas: 100% (16799/16799), done.
➜  tmp cd grpc-gateway/protoc-gen-grpc-gateway 
➜  protoc-gen-grpc-gateway git:(master) ls
BUILD.bazel internal    main.go
➜  protoc-gen-grpc-gateway git:(master) go build
➜  protoc-gen-grpc-gateway git:(master) ✗ ./protoc-gen-grpc-gateway --version
commit 09bd9fef8e214eeb8487844d6f25f7f6c1101c22, built at 2024-05-22T17:36:03Z
➜  protoc-gen-grpc-gateway git:(master) ✗
@MakDon
Copy link
Contributor Author

MakDon commented May 23, 2024

Found it still not working when installed by go install.

➜  git:(master) go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@cc70731
go: downloading github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.1-0.20240523165541-cc70731f9bd2
➜  git:(master) protoc-gen-grpc-gateway --version                                                   
commit unknown, built at unknown

Would keep trying to solve this issue.

@MakDon
Copy link
Contributor Author

MakDon commented May 31, 2024

Close for issue has been solved.

➜ go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@main
go: downloading github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.1-0.20240531172029-a94bb9df9cdf
➜ protoc-gen-grpc-gateway --version
Version v2.20.1-0.20240531172029-a94bb9df9cdf, commit unknown, built at unknown

@MakDon MakDon closed this as completed May 31, 2024
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

No branches or pull requests

1 participant