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

Show git commit if version information is missing #1517

Merged
merged 2 commits into from
Dec 26, 2023

Conversation

Limero
Copy link
Contributor

@Limero Limero commented Dec 2, 2023

This uses runtime/debug to show the Go version and Git commit embedded in the binary if version information is missing. The previous behavior is to just print nothing if the version is missing which is not very helpful.

I also considered adding the Go version information to the regular version information, but decided against it in case someone parses the output from the current version command.

Example output of custom built binary:

Go version: go1.21.4
Commit: 4f8ba9726d0bb6af4904740b52ba7b18320709ee 2023-12-02T04:17:13Z modified

Copy link
Collaborator

@joelim-work joelim-work left a comment

Choose a reason for hiding this comment

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

Thanks very much for this patch, I think this will be helpful for bug reports.

One minor thing is that I'm not sure how useful vcs.time is, although I guess it can't hurt to include it anyway. Otherwise I don't have much opinion on the format of the version output, and overall the PR looks fine to me.

@Limero
Copy link
Contributor Author

Limero commented Dec 3, 2023

Thanks very much for this patch, I think this will be helpful for bug reports.

One minor thing is that I'm not sure how useful vcs.time is, although I guess it can't hurt to include it anyway. Otherwise I don't have much opinion on the format of the version output, and overall the PR looks fine to me.

Thanks for reviewing! I actually find the vcs.time quite useful, being able to see how old your current build is right away without having to manually look up the commit

@joelim-work
Copy link
Collaborator

Thanks for reviewing! I actually find the vcs.time quite useful, being able to see how old your current build is right away without having to manually look up the commit

Cool no worries, I will give my approval then. Thanks once again.

@ilyagr
Copy link
Collaborator

ilyagr commented Dec 3, 2023

Thanks for the PR!

Two minor suggestions:

  • Put the Go line after the Commit line
  • (Optional) Instead of Commit:, I would write Built at commit . Or, alternatively, you could have 3 lines: 1) Just the commit id, "Commit date:" line, and "Go version:" line.

I was also thinking about an alternative plan: --version could just print the commit id, and there could be a separate --verbose-version option to print everything (including the official version, if present). However, I decided we don't really have to think about that too hard now. We can merge this and then see whether there's a demand for something more complicated.

main.go Outdated Show resolved Hide resolved
@Limero
Copy link
Contributor Author

Limero commented Dec 11, 2023

@ilyagr Thanks! I've updated the format to now look like the followng:

Built at commit: 397f4a089030e7df9ceca5973523ae5a4453c415 (dirty) 2023-12-02T04:21:57Z
Go version: go1.21.4

Copy link
Collaborator

@ilyagr ilyagr left a comment

Choose a reason for hiding this comment

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

Thank you! LGTM.

@gokcehan gokcehan merged commit a51462d into gokcehan:master Dec 26, 2023
4 checks passed
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.

4 participants