-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: cmd/go: add go version -json #55136
Comments
You're somewhat there already via
or with tip:
|
@mvdan Thanks for pointing out the Perhaps for tip/non-official releases there could be another option for what git rev it was built from or something like that. For example, to take your two examples, it would be good to have these values output independently.
and
|
For actual releases, it seems to me like you can extract the semver-like numbers with a fairly simple regular expression. I've done that in a couple of places and it doesn't seem particularly difficult. For "devel" versions, note that they don't need to follow a specific format. A build can end up with any version string placed in the
Note that if this is your use case, you likely don't want to obey It sounds to me like you only want to use |
I can use a regex, that's what all the search results for "How to get Go version" do. Some of them are broken in various ways, need maintenance, or assume access to certain tooling or a particular regex implementation. The point of the proposal is to do away with this. It's information that the Go binary already has, why not make it available in a structured way rather than making everyone re-implement the wheel in various broken ways? |
I'm not sure I understand when this would happen at all, certainly not "often".
The -compat argument predates the work on forward compatibility (respecting the go version in the go.mod file) and basically should not be used anymore. Are there other contexts where this information is needed? |
This proposal has been added to the active column of the proposals project |
With the compatibility work that has landed since this issue was filed in 2022, it seems like this may not be necessary anymore. |
Based on the discussion above, this proposal seems like a likely decline. |
No change in consensus, so declined. |
Background
Issue #21207 describes an effectively similar problem, but was closed without actually resulting in a structured version output.
Problem
When using CI Tools and pipelines, it is often required to know the major/minor version of Go.
Not least of which for passing into go commands such as
go mod tidy
which has a-compat
argument, which requires just the major.minor version number.Current Work-Arounds
As best as I can tell, everyone seems to be using some kind of regex against the output of
go version
.Proposal
An argument for
go version
which will output a structured format of some kind, or perhaps just the version elements requested.The text was updated successfully, but these errors were encountered: