jdx / mise

dev tools, env vars, task runner
https://mise.jdx.dev
MIT License
9.89k stars 284 forks source link

Go package forge doesn't handle subpackages properly #1495

Closed endigma closed 9 months ago

endigma commented 9 months ago
> mise x go:github.com/go-task/task/v3/cmd/task@latest -- task
mise failed to resolve tool version: missing field `Versions` at line 10 column 1
task: No tasks with description available. Try --list-all to list all tasks
task: Task "default" does not exist

This is because go list -m -versions -json github.com/go-task/task/v3/cmd/task returns

{
        "Path": "github.com/go-task/task/v3/cmd/task",
        "Origin": {
                "VCS": "git",
                "URL": "https://github.com/go-task/task",
                "Subdir": "v3/cmd/task",
                "TagPrefix": "v3/cmd/task/",
                "TagSum": "t1:47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU="
        }
}

I originally added the forge, so I'll probably fix this myself, but I don't have time for it right this moment so someone else can get it if they want to.

Solution will probably involve somehow resolving which type of JSON comes back and somehow retrying with the module directory.

endigma commented 9 months ago

This may also fail where a repository has no tags or has the go package in a non-root directory, as the "Origin" info here doesn't tell us where the go.mod is.

endigma commented 9 months ago

In the case in OP, the correct command to get the list of versions is go list -m -versions -json github.com/go-task/task/v3, I don't see how to derive this from the return except for just trying parent directories until a result comes back?

GeertJohan commented 9 months ago

I get the same error when trying to instal connectrpc.com/connect/cmd/protoc-gen-connect-go through mise's go backend. I've scanned through the go cli subcommands but there doesn't seem to be a command that translates a package into the module, which go install does silently.

Should we perhaps open a feature request over at golang/go to add support for this resolving in go list?

endigma commented 9 months ago

That may actually be the best option, I don't see a way to automatically resolve the module versions from the package path without recursively checking the whole path. Maybe an extra flag for go install that lists versions would be most likely to be accepted.

endigma commented 9 months ago

This could probably get a "hotfix" by climbing the path until a valid module is found, this seems to work from my testing, but a better solution is probably possible.

endigma commented 9 months ago

There's now an issue in https://github.com/golang/go, but the hotfix is likely much more likely to work on a quick timeline.

jdx commented 9 months ago

lol that thread could not be more stereotypical for go. I hope you get some traction. It seems crazy to me that go install takes versions as input but there is no way to get the possible options.