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

asdf-golang is not selecting the expected version using legacy_version_file #65

Closed
jabrown85 opened this issue Nov 10, 2021 · 5 comments

Comments

@jabrown85
Copy link

Describe the bug
asdf-golang is not selecting the expected version using only a go.mod

To Reproduce

➜  cat go.mod
module github.com/asdf-golang/issue

go 1.14
➜  asdf current golang
golang          1.17            /Users/jesse.brown/dev/jabrown85/go-test/go.mod
➜  asdf list golang
  1.14
  1.16
  1.17
➜  cat ~/.asdfrc
legacy_version_file = yes%

I know legacy_version_file is being respected given the output from go-test asdf current golang, but it seems to be picking the latest matching major version.

Expected behavior
I would expect go-test asdf current golang and subsequently go version to produce 1.14

Desktop (please complete the following information):

  • OS: macOS 11.6
@kennyp
Copy link
Member

kennyp commented Nov 16, 2021

Hey Jesse, the current behavior is actually what is intended based on how go.mod is described in the go docs.

For an exact version I would use a .tool-versions file.

@kennyp kennyp closed this as completed Nov 16, 2021
@myhro
Copy link

myhro commented Dec 30, 2021

Hi Kenny,

I'm trying to find a way to overcome this behavior - which I totally get the reasoning, but it's not working for my specific use case.

I'm using Go 1.18beta1 for a single project where I'm exploring its new features. The problem is that when there isn't a local .tool-versions on all the other repositories, it reads go 1.17 from go.mod and ends up selecting the 1.18beta1 one. This is not ideal, as golangci-lint is currently not working with the latter.

I've tried to use the minor/non-exact version format within .tool-versions, to avoid updating all repositories whenever a patch version is released, but that's not possible:

$ echo 'golang 1.17' > .tool-versions
$ go version
No preset version installed for command go
Please install a version by running one of the following:

asdf install golang 1.17

or add one of the following versions in your config file at /Users/myhro/Documents/github.com/myhro/feeds/.tool-versions
golang 1.17.5
golang 1.18beta1

The only workaround I found until now is to resort to the legacy version file, which supports the minor/non-exact version format:

$ rm .tool-versions
$ echo 'legacy_version_file = yes' > ~/.asdfrc
$ go version
go version go1.18beta1 darwin/amd64
$ echo '1.17' > .go-version
$ go version
go version go1.17.5 darwin/amd64

Which is also a bit cumbersome, given it's a legacy option.

Would it be possible to offer a configuration option to disable the default behavior of reading the version from go.mod? I've checked the PR #32 which introduced it, but looks like right now that's not optional.

Not going after non-stable versions would also work, but I'm not sure if that's compatible with the go directive meaning within go.mod. I haven't found any mentions to that in the official docs.

@kennyp
Copy link
Member

kennyp commented Jan 16, 2022

Hey @myhro,

In your .tool-versions file if you use 1.17.5 based on the output you should be good.

There is an option to turn off the legacy version support in asdf. https://asdf-vm.com/manage/configuration.html#legacy-version-file

But then you would still need to set golfing 1.17.5 in your .tool-versions file.

@myhro
Copy link

myhro commented Jan 17, 2022

Hi Kenny,

In your .tool-versions file if you use 1.17.5 based on the output you should be good.
(...)
But then you would still need to set golfing 1.17.5 in your .tool-versions file.

This exactly what I want to avoid. I would like to stick to whatever 1.17.x I have available, without specifying the minor release or the go.mod-based fallback sticking to the 1.18.x beta versions.

Currently, I can only do that by opting for the legacy version support.

@kennyp
Copy link
Member

kennyp commented Jan 17, 2022 via email

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

Successfully merging a pull request may close this issue.

3 participants