cmd: Use newly-available version information #4931
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #4926
New Version() function returns simple and full version strings.
Go module information is still preferred. Then vcs info.
It's kind of weird, in that different ways of building Caddy give different outputs:
go run
doesn't embed vcs in it, presumably because it runs from outside the git repo?go build
at least embeds commit info, so that's nice. That will still add a lot of helpful version info where we are currently lacking it in bug reports, etc.xcaddy build
of course builds Caddy as a dependency rather than as the main module, so we get the Go module version information, which is the most detailed as it gives us information about module replacements, etc.So the
caddy version
command will print the full version string with a little more info.The short form of the version string also returned by
Version()
looks like this if it uses VCS info:63c7720e-20220802
-- it's a shortened SHA with the commit date, for convenience. This would be used for things like User-Agent strings, metrics, etc:Caddy/63c7720e-20220802
Overall, this is definitely an improvement. We're still waiting on golang/go#29228 and golang/go#50603 for a more ideal solution that always makes version info available for the Main module. But this'll do for now.
(Oh, totally forgot in the commit message, but we also just use
BuildInfo.String()
forcaddy build-info
now, instead of crafting our own output format. TheString()
output is quite nice!)