Gelio / go-global-update

A command to update globally installed go executables
MIT License
134 stars 4 forks source link

Some edge cases not handled #3

Closed StevenACoffman closed 2 years ago

StevenACoffman commented 2 years ago

Hi! This worked brilliantly for most things! Thank you so much! However, there were a few things that did not get handled well.

Upgrading checker to v0.0.0-20210809155116-d52e63616b7a ... ❌
    Could not upgrade package
go: downloading github.com/StevenACoffman/toolbox v0.0.0-20210809155116-d52e63616b7a
go install: github.com/StevenACoffman/toolbox/cmd/checker@latest: module github.com/StevenACoffman/toolbox@latest found (v0.0.0-20210809155116-d52e63616b7a), but does not contain package github.com/StevenACoffman/toolbox/cmd/checker

Upgrading client-go to v0.23.4 ... ❌
    Could not upgrade package
go install: k8s.io/client-go@latest (in k8s.io/client-go@v0.23.4):
    The go.mod file for the module providing named packages contains one or
    more replace directives. It must not contain directives that would cause
    it to be interpreted differently than if it were the main module.

Upgrading cobra to v1.4.0 ... ❌
    Could not upgrade package
go: downloading github.com/spf13/cobra v1.4.0
go install: github.com/spf13/cobra/cobra@latest: module github.com/spf13/cobra@latest found (v1.4.0), but does not contain package github.com/spf13/cobra/cobra

Upgrading codesync to v0.0.0-20210809155116-d52e63616b7a ... ❌
    Could not upgrade package
go install: github.com/StevenACoffman/toolbox/cmd/codesync@latest: module github.com/StevenACoffman/toolbox@latest found (v0.0.0-20210809155116-d52e63616b7a), but does not contain package github.com/StevenACoffman/toolbox/cmd/codesync

Upgrading csvlint to v0.3.0 ... ❌
    Could not upgrade package
go install: command-line-arguments@latest: malformed module path "command-line-arguments": missing dot in first path element

Upgrading dive to v0.10.0 ... ❌
    Could not upgrade package
go: downloading github.com/wagoodman/dive v0.10.0
go install: github.com/wagoodman/dive@latest (in github.com/wagoodman/dive@v0.10.0):
    The go.mod file for the module providing named packages contains one or
    more replace directives. It must not contain directives that would cause
    it to be interpreted differently than if it were the main module.

Upgrading generate-gnostic to v0.6.6 ... ❌
    Could not upgrade package
go: downloading github.com/googleapis/gnostic v0.6.6
go install: github.com/googleapis/gnostic/generate-gnostic@latest: github.com/googleapis/gnostic@v0.6.6: parsing go.mod:
    module declares its path as: github.com/google/gnostic
            but was required as: github.com/googleapis/gnostic

Upgrading genqlient to v0.4.0 ... ❌
    Could not upgrade package
go install: command-line-arguments@latest: malformed module path "command-line-arguments": missing dot in first path element

Upgrading git-changed to v0.0.0-20210809155116-d52e63616b7a ... ❌
    Could not upgrade package
go install: command-line-arguments@latest: malformed module path "command-line-arguments": missing dot in first path element

Upgrading git-cm to v1.0.0 ... ❌
    Could not upgrade package
go install: command-line-arguments@latest: malformed module path "command-line-arguments": missing dot in first path element

Upgrading gnostic to v0.6.6 ... ❌
    Could not upgrade package
go install: github.com/googleapis/gnostic@latest: github.com/googleapis/gnostic@v0.6.6: parsing go.mod:
    module declares its path as: github.com/google/gnostic
            but was required as: github.com/googleapis/gnostic

Upgrading go-on to v1.0.0 ... ❌
    Could not upgrade package
go install: command-line-arguments@latest: malformed module path "command-line-arguments": missing dot in first path element

Upgrading pkgerr to v0.0.0-20210326114838-4d703da9bc1f ... ❌
    Could not upgrade package
go install: command-line-arguments@latest: malformed module path "command-line-arguments": missing dot in first path element
Gelio commented 2 years ago

Thanks for trying out the tool and reporting bugs! I appreciate it. I will try to fix some of them in the upcoming days and post updates in this issue

StevenACoffman commented 2 years ago

Thanks! If it helps, here are links to the source code of the edge cases that were problematic:

Gelio commented 2 years ago

Thanks for sharing the exact URLs, those are definitely helpful :+1:

command-line-arguments errors

I checked the first one, genqlient, and I could not reproduce the problem.

20:34 $ GOBIN=$(pwd) go install github.com/Khan/genqlient@v0.3.0
20:35 $ GOBIN=$(pwd) go-global-update
genqlient (version: v0.3.0, can upgrade to v0.4.0)

Upgrading genqlient to v0.4.0 ... ✅

Looking at the logs you shared it seems go-global-update tries to run go install command-line-arguments@latest and fails, which is reasonable

go install: command-line-arguments@latest: malformed module path "command-line-arguments": missing dot in first path element

Could you run go-global-update to try to update genqlient and enable debug logs and paste the results? The command to run should be:

go-global-update --debug genqlient

For me, having deliberately installed genqlient@v0.3.0 to force updating it, the output of the command above is:

20:38 $ GOBIN=$(pwd) go-global-update --debug genqlient
2022-03-15T20:38:44.991+0100    DEBUG   gocli/cmd_runner.go:28  go command output       {"args": ["env", "GOBIN"], "output": "/home/voreny/projects/go-global-update/test/integration-tests/test-1639226301\n"}
2022-03-15T20:38:44.991+0100    DEBUG   updater/updater.go:41   found GOBIN path        {"GOBIN": "/home/voreny/projects/go-global-update/test/integration-tests/test-1639226301"}
2022-03-15T20:38:44.995+0100    DEBUG   gocli/cmd_runner.go:28  go command output       {"args": ["version", "-m", "/home/voreny/projects/go-global-update/test/integration-tests/test-1639226301/genqlient"], "output": "/home/voreny/projects/go-global-update/test/integration-tests/test-1639226301/genqlient: go1.17\n\tpath\tgithub.com/Khan/genqlient\n\tmod\tgithub.com/Khan/genqlient\tv0.3.0\th1:G35N630mNCW+j0rqSJUsvNkPLoX0bjrllRMnaQTbCak=\n\tdep\tgithub.com/agnivade/levenshtein\tv1.0.3\th1:M5ZnqLOoZR8ygVq0FfkXsNOKzMCk0xRiow0R5+5VkQ0=\n\tdep\tgithub.com/alexflint/go-arg\tv1.4.2\th1:lDWZAXxpAnZUq4qwb86p/3rIJJ2Li81EoMbTMujhVa0=\n\tdep\tgithub.com/alexflint/go-scalar\tv1.0.0\th1:NGupf1XV/Xb04wXskDFzS0KWOLH632W/EO4fAFi+A70=\n\tdep\tgithub.com/vektah/gqlparser/v2\tv2.1.0\th1:uiKJ+T5HMGGQM2kRKQ8Pxw8+Zq9qhhZhz/lieYvCMns=\n\tdep\tgolang.org/x/mod\tv0.4.2\th1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=\n\tdep\tgolang.org/x/sys\tv0.0.0-20210510120138-977fb7262007\th1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=\n\tdep\tgolang.org/x/tools\tv0.1.5\th1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA=\n\tdep\tgolang.org/x/xerrors\tv0.0.0-20200804184101-5ec99f83aff1\th1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=\n\tdep\tgopkg.in/yaml.v2\tv2.4.0\th1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=\n"}
2022-03-15T20:38:45.482+0100    DEBUG   gocli/cmd_runner.go:28  go command output       {"args": ["list", "-m", "-f", "{{.Version}}", "github.com/Khan/genqlient@latest"], "output": "v0.4.0\n"}
2022-03-15T20:38:45.482+0100    DEBUG   gobinaries/introspecter.go:47   introspected binary genqlient: {ModuleURL:github.com/Khan/genqlient PathURL:github.com/Khan/genqlient Name:genqlient Path:/home/voreny/projects/go-global-update/test/integration-tests/test-1639226301/genqlient Version:v0.3.0 LatestVersion:v0.4.0}
genqlient (version: v0.3.0, can upgrade to v0.4.0)

Upgrading genqlient to v0.4.0 ... 2022-03-15T20:38:46.295+0100  DEBUG   gocli/cmd_runner.go:28  go command output      {"args": ["install", "github.com/Khan/genqlient@latest"], "output": ""}
✅

This should get me enough information to try to debug the command-line-arguments problem further.

cobra

Looks like cobra changed its structure in the latest v1.4.0 release and is no longer a CLI application itself. It says the CLI package was extracted to cobra-cli. In this case, I believe users of cobra should remove cobra and instead install cobra-cli.

I suppose I could add some commonly known CLI migrations/updates, such as the one for cobra -> cobra-cli. go-global-update would remove cobra and instead install cobra-cli, logging some information about the migration in the process. That seems like it could have many edge cases, but I can consider it in the future after go-global-update is reasonably stable

gnostic

It seems there is something weird going on in go.mod for gnostic and that may have to do with the URL of the repository changing (I don't know, I assume it changed). I would also appreciate if you provided the output of

go-global-update --debug gnostic

EDIT: https://github.com/googleapis/gnostic redirects to https://github.com/google/gnostic - the organization name changed. The go.mod was also updated to use the new organization name. I don't know if we can fix this error automatically. It probably requires invoking go install github.com/google/gnostic@latest yourself to install the package using the new path. Subsequent calls to go-global-update should succeed. I reckon I can create a common update errors section in the README to describe what to do in known cases, such as this one

dive

Unfortunately, dive's go.mod uses replace directives, which go install does not seem to handle. I cannot install the latest version using go install at all:

20:53 $ GOBIN=$(pwd) go install github.com/wagoodman/dive@v0.9.2
go: downloading github.com/wagoodman/dive v0.9.2
go install: github.com/wagoodman/dive@v0.9.2 (in github.com/wagoodman/dive@v0.9.2):
        The go.mod file for the module providing named packages contains one or
        more replace directives. It must not contain directives that would cause
        it to be interpreted differently than if it were the main module.

Looks like https://github.com/golang/go/issues/44840 is/was the issue tracking that problem. I don't have a clue how to work around it

git-changed and other utilities from StevenACoffman/toolbox

I was able to install and update git-changed without issues:

19:44 $ GOBIN=$(pwd) go install github.com/StevenACoffman/toolbox/cmd/git-changed@latest
go: downloading github.com/StevenACoffman/toolbox v0.0.0-20210809155116-d52e63616b7a
go: downloading github.com/go-git/go-git/v5 v5.1.0
go: downloading golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073
go: downloading github.com/go-git/go-billy/v5 v5.0.0
go: downloading github.com/emirpasic/gods v1.12.0
go: downloading github.com/imdario/mergo v0.3.9
go: downloading github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99
go: downloading github.com/mitchellh/go-homedir v1.1.0
go: downloading github.com/go-git/gcfg v1.5.0
go: downloading github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd
go: downloading github.com/xanzy/ssh-agent v0.2.1
go: downloading golang.org/x/net v0.0.0-20200301022130-244492dfa37a
go: downloading golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527
go: downloading gopkg.in/warnings.v0 v0.1.2
19:45 $ go version -m git-changed
git-changed: go1.17
        path    github.com/StevenACoffman/toolbox/cmd/git-changed
        mod     github.com/StevenACoffman/toolbox       v0.0.0-20210809155116-d52e63616b7a      h1:TKYAe9oMtlb2UQSA3xPIPAiIaCeONC5WSOUw/41VZ+s=
        dep     github.com/emirpasic/gods       v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
        dep     github.com/go-git/gcfg  v1.5.0  h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
        dep     github.com/go-git/go-billy/v5   v5.0.0  h1:7NQHvd9FVid8VL4qVUMm8XifBK+2xCoZ2lSk0agRrHM=
        dep     github.com/go-git/go-git/v5     v5.1.0  h1:HxJn9g/E7eYvKW3Fm7Jt4ee8LXfPOm/H1cdDu8vEssk=
        dep     github.com/imdario/mergo        v0.3.9  h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
        dep     github.com/jbenet/go-context    v0.0.0-20150711004518-d14ea06fba99      h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
        dep     github.com/kevinburke/ssh_config        v0.0.0-20190725054713-01f96b0aa0cd      h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY=
        dep     github.com/mitchellh/go-homedir v1.1.0  h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
        dep     github.com/sergi/go-diff        v1.1.0  h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
        dep     github.com/xanzy/ssh-agent      v0.2.1  h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70=
        dep     golang.org/x/crypto     v0.0.0-20200302210943-78000ba7a073      h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM=
        dep     golang.org/x/net        v0.0.0-20200301022130-244492dfa37a      h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0=
        dep     golang.org/x/sys        v0.0.0-20200302150141-5c8b2ff67527      h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
        dep     gopkg.in/warnings.v0    v0.1.2  h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
19:45 $ GOBIN=$(pwd) go-global-update git-changed
git-changed (version: v0.0.0-20210809155116-d52e63616b7a, up-to-date)

I suppose your issues may stem from building those from source. I seem to have a valid path even after building from source:

19:48 $ GOBIN=$(pwd)/../../.. go install
✔ ~/projects/go-global-update/test/integration-tests/test-1639226301/toolbox/cmd/git-changed [master|✔]
19:48 $ z ../../..
✔ ~/projects/go-global-update/test/integration-tests/test-1639226301 [main|✚ 1…1]
19:48 $ l
.rwxrwxr-x 2,0M voreny 17 mar 19:37 csvlint
drwxrwxr-x    - voreny 17 mar 19:40 genqlient
.rwxrwxr-x 5,7M voreny 17 mar 19:48 git-changed
.rwxrwxr-x  14M voreny 17 mar 19:37 gnostic
drwxrwxr-x    - voreny 17 mar 19:47 toolbox
✔ ~/projects/go-global-update/test/integration-tests/test-1639226301 [main|✚ 1…1]
19:48 $ go version -m git-changed
git-changed: go1.17
        path    github.com/StevenACoffman/toolbox/cmd/git-changed
        mod     github.com/StevenACoffman/toolbox       (devel)
        dep     github.com/emirpasic/gods       v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
        dep     github.com/go-git/gcfg  v1.5.0  h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
        dep     github.com/go-git/go-billy/v5   v5.0.0  h1:7NQHvd9FVid8VL4qVUMm8XifBK+2xCoZ2lSk0agRrHM=
        dep     github.com/go-git/go-git/v5     v5.1.0  h1:HxJn9g/E7eYvKW3Fm7Jt4ee8LXfPOm/H1cdDu8vEssk=
        dep     github.com/imdario/mergo        v0.3.9  h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
        dep     github.com/jbenet/go-context    v0.0.0-20150711004518-d14ea06fba99      h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
        dep     github.com/kevinburke/ssh_config        v0.0.0-20190725054713-01f96b0aa0cd      h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY=
        dep     github.com/mitchellh/go-homedir v1.1.0  h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
        dep     github.com/sergi/go-diff        v1.1.0  h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
        dep     github.com/xanzy/ssh-agent      v0.2.1  h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70=
        dep     golang.org/x/crypto     v0.0.0-20200302210943-78000ba7a073      h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM=
        dep     golang.org/x/net        v0.0.0-20200301022130-244492dfa37a      h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0=
        dep     golang.org/x/sys        v0.0.0-20200302150141-5c8b2ff67527      h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
        dep     gopkg.in/warnings.v0    v0.1.2  h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=

So, again, I don't know why you have command-line-arguments in the path :shrug: Let's continue discussing that below

checker

It looks like there is no checker package in https://github.com/StevenACoffman/toolbox/tree/master/cmd, so the error seems to be correct. I don't know how you got the package, but you would need to build it again so the path points to a valid package pushed to a git repo

StevenACoffman commented 2 years ago

So I am now running on Go 1.17.5:

$ go version
go version go1.17.5 darwin/amd64

But it appears that I built genqlient from source using Go 1.17.1:

go-global-update --debug genqlient
2022-03-15T16:10:51.913-0400    DEBUG   gocli/cmd_runner.go:28  go command output   {"args": ["env", "GOBIN"], "output": "/Users/steve/go/bin\n"}
2022-03-15T16:10:51.915-0400    DEBUG   updater/updater.go:41   found GOBIN path    {"GOBIN": "/Users/steve/go/bin"}
2022-03-15T16:10:52.061-0400    DEBUG   gocli/cmd_runner.go:28  go command output   {"args": ["version", "-m", "/Users/steve/go/bin/genqlient"], "output": "/Users/steve/go/bin/genqlient: go1.17.1\n\tpath\tcommand-line-arguments\n\tmod\tgithub.com/Khan/genqlient\t(devel)\t\n\tdep\tgithub.com/agnivade/levenshtein\tv1.1.0\th1:n6qGwyHG61v3ABce1rPVZklEYRT8NFpCMrpZdBUbYGM=\n\tdep\tgithub.com/alexflint/go-arg\tv1.4.2\th1:lDWZAXxpAnZUq4qwb86p/3rIJJ2Li81EoMbTMujhVa0=\n\tdep\tgithub.com/alexflint/go-scalar\tv1.0.0\th1:NGupf1XV/Xb04wXskDFzS0KWOLH632W/EO4fAFi+A70=\n\tdep\tgithub.com/vektah/gqlparser/v2\tv2.2.0\th1:bAc3slekAAJW6sZTi07aGq0OrfaCjj4jxARAaC7g2EM=\n\tdep\tgolang.org/x/mod\tv0.4.2\th1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=\n\tdep\tgolang.org/x/sys\tv0.0.0-20210809222454-d867a43fc93e\th1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA=\n\tdep\tgolang.org/x/tools\tv0.1.7\th1:6j8CgantCy3yc8JGBqkDLMKWqZ0RDU2g1HVgacojGWQ=\n\tdep\tgolang.org/x/xerrors\tv0.0.0-20200804184101-5ec99f83aff1\th1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=\n\tdep\tgopkg.in/yaml.v2\tv2.4.0\th1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=\n"}
2022-03-15T16:10:52.957-0400    DEBUG   gocli/cmd_runner.go:28  go command output   {"args": ["list", "-m", "-f", "{{.Version}}", "github.com/Khan/genqlient@latest"], "output": "v0.4.0\n"}
2022-03-15T16:10:52.958-0400    DEBUG   gobinaries/introspecter.go:47   introspected binary genqlient: {ModuleURL:github.com/Khan/genqlient PathURL:command-line-arguments Name:genqlient Path:/Users/steve/go/bin/genqlient Version:(devel) LatestVersion:v0.4.0}
genqlient (version: (devel), can upgrade to v0.4.0)

Upgrading genqlient to v0.4.0 ... 2022-03-15T16:10:53.137-0400  DEBUG   gocli/cmd_runner.go:28  go command output   {"args": ["install", "command-line-arguments@latest"], "output": "go install: command-line-arguments@latest: malformed module path \"command-line-arguments\": missing dot in first path element\n", "error": "exit status 1"}
❌
    Could not upgrade package
go install: command-line-arguments@latest: malformed module path "command-line-arguments": missing dot in first path element

2022/03/15 16:10:53 could not run command: could not upgrade 1 packages
$ go version -m genqlient
genqlient: go1.17.1
    path    command-line-arguments
    mod github.com/Khan/genqlient   (devel)
    dep github.com/agnivade/levenshtein v1.1.0  h1:n6qGwyHG61v3ABce1rPVZklEYRT8NFpCMrpZdBUbYGM=
    dep github.com/alexflint/go-arg v1.4.2  h1:lDWZAXxpAnZUq4qwb86p/3rIJJ2Li81EoMbTMujhVa0=
    dep github.com/alexflint/go-scalar  v1.0.0  h1:NGupf1XV/Xb04wXskDFzS0KWOLH632W/EO4fAFi+A70=
    dep github.com/vektah/gqlparser/v2  v2.2.0  h1:bAc3slekAAJW6sZTi07aGq0OrfaCjj4jxARAaC7g2EM=
    dep golang.org/x/mod    v0.4.2  h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
    dep golang.org/x/sys    v0.0.0-20210809222454-d867a43fc93e  h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA=
    dep golang.org/x/tools  v0.1.7  h1:6j8CgantCy3yc8JGBqkDLMKWqZ0RDU2g1HVgacojGWQ=
    dep golang.org/x/xerrors    v0.0.0-20200804184101-5ec99f83aff1  h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
    dep gopkg.in/yaml.v2    v2.4.0  h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=

Which is odd, because the utilities that succeeded give different results:

$ go version -m gofumpt
gofumpt: go1.17.5
    path    mvdan.cc/gofumpt
    mod mvdan.cc/gofumpt    v0.3.0  h1:kTojdZo9AcEYbQYhGuLf/zszYthRdhDNDUi2JKTxas4=
    dep github.com/google/go-cmp    v0.5.7  h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
    dep golang.org/x/mod    v0.5.1  h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
    dep golang.org/x/sync   v0.0.0-20210220032951-036812b2e83c  h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
    dep golang.org/x/sys    v0.0.0-20220209214540-3681064d5158  h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
    dep golang.org/x/tools  v0.1.9  h1:j9KsMiaP1c3B0OTQGth0/k+miLGTgLsAFUCrF2vLcF8=
StevenACoffman commented 2 years ago

https://github.com/golang/go/blob/1eb1f621da20d7c93ac0312e59c08afbde4d9f56/src/cmd/go/internal/workcmd/sync.go#L91-L97

Which references: https://github.com/golang/go/issues/49228:

Before workspaces, when the go command was in module mode, but not in any particular module, it had a fake Target module with the path command-line-arguments and an empty modroot. This was directly translated in workspace mode to a MainModules set with a single entry with that fake module path and empty modroot.

Instead, we should make MainModules.Len() == 0 mean that we're in module mode but not inside any module.

Gelio commented 2 years ago

Thanks for providing all that information and finding https://github.com/golang/go/issues/49228.

I have trouble understanding how you got to have command-line-arguments as path for some of the binaries. Is it possible you built them from source before Go modules, hence they are not real modules and have this arbitrary command-line-arguments as their path?

When I build a package from source, I see the (devel) version, but the path is correct.

19:40 $ go version -m genqlient
genqlient: go1.17
        path    github.com/Khan/genqlient
        mod     github.com/Khan/genqlient       (devel)
        dep     github.com/agnivade/levenshtein v1.1.0  h1:n6qGwyHG61v3ABce1rPVZklEYRT8NFpCMrpZdBUbYGM=
        dep     github.com/alexflint/go-arg     v1.4.2  h1:lDWZAXxpAnZUq4qwb86p/3rIJJ2Li81EoMbTMujhVa0=
        dep     github.com/alexflint/go-scalar  v1.0.0  h1:NGupf1XV/Xb04wXskDFzS0KWOLH632W/EO4fAFi+A70=
        dep     github.com/vektah/gqlparser/v2  v2.3.1  h1:blIC0fCxGIr9pVjsc+BVI8XjYUtc2nCFRfnmP7FuFMk=
        dep     golang.org/x/mod        v0.4.2  h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
        dep     golang.org/x/sys        v0.0.0-20210809222454-d867a43fc93e      h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA=
        dep     golang.org/x/tools      v0.1.7  h1:6j8CgantCy3yc8JGBqkDLMKWqZ0RDU2g1HVgacojGWQ=
        dep     golang.org/x/xerrors    v0.0.0-20200804184101-5ec99f83aff1      h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
        dep     gopkg.in/yaml.v2        v2.4.0  h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=

Anyway, I believe I will change the code to skip the update attempt if:

  1. The version is (devel) - I would expect that engineers want to keep the version they built from source and they can manage it on their own.
  2. The path is command-line-arguments - not sure what information to display then

In either case the binary will be mentioned in the summary just so it was acknowledged and the engineer can act on it if they want to fix/upgrade the package manually.

Let me know if you have a clue how you could end up with path of command-line-arguments for some of the packages.

I would also appreciate it if you pasted the output of go-global-update --debug gnostic because that is the only package left to debug (I have described my findings from debugging other packages in https://github.com/Gelio/go-global-update/issues/3#issuecomment-1068393289 in case you haven't seen it)

StevenACoffman commented 2 years ago
$ go-global-update --debug gnostic
2022-03-17T15:46:58.370-0400    DEBUG   gocli/cmd_runner.go:28  go command output   {"args": ["env", "GOBIN"], "output": "\n"}
2022-03-17T15:46:58.502-0400    DEBUG   gocli/cmd_runner.go:28  go command output   {"args": ["env", "GOPATH"], "output": "/Users/steve/.asdf/installs/golang/1.17.5/packages\n"}
2022-03-17T15:46:58.502-0400    DEBUG   updater/updater.go:41   found GOBIN path    {"GOBIN": "/Users/steve/.asdf/installs/golang/1.17.5/packages/bin"}
2022-03-17T15:46:58.650-0400    DEBUG   gocli/cmd_runner.go:28  go command output   {"args": ["version", "-m", "/Users/steve/.asdf/installs/golang/1.17.5/packages/bin/gnostic"], "output": "stat /Users/steve/.asdf/installs/golang/1.17.5/packages/bin/gnostic: no such file or directory\n", "error": "exit status 1"}
could not introspect binary gnostic: could not get module info about /Users/steve/.asdf/installs/golang/1.17.5/packages/bin/gnostic: could not retrieve version information about binary /Users/steve/.asdf/installs/golang/1.17.5/packages/bin/gnostic: exit status 1
stat /Users/steve/.asdf/installs/golang/1.17.5/packages/bin/gnostic: no such file or directory

steve@Stevens-MacBook-Pro: ~/go/bin
$ go version -m gnostic
gnostic: go1.13.7
    path    github.com/googleapis/gnostic
    mod github.com/googleapis/gnostic   (devel)
    dep github.com/golang/protobuf  v1.4.2  h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
    dep google.golang.org/protobuf  v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
    dep gopkg.in/yaml.v2    v2.2.2  h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
StevenACoffman commented 2 years ago

So I can reliably recreate the "command-line-path" situation even with Go 1.17.5:

$ git clone git@github.com:StevenACoffman/toolbox.git
$ go build -o bin/jp cmd/jira-pull/jp.go
$ cd bin
$ go version -m jp
jp: go1.17.5
    path    command-line-arguments
    mod github.com/StevenACoffman/toolbox   (devel)
    dep github.com/emirpasic/gods   v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
    dep github.com/go-git/gcfg  v1.5.0  h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
    dep github.com/go-git/go-billy/v5   v5.0.0  h1:7NQHvd9FVid8VL4qVUMm8XifBK+2xCoZ2lSk0agRrHM=
    dep github.com/go-git/go-git/v5 v5.2.0  h1:YPBLG/3UK1we1ohRkncLjaXWLW+HKp5QNM/jTli2JgI=
    dep github.com/google/go-github v17.0.0+incompatible    h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
    dep github.com/google/go-querystring    v1.0.0  h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
    dep github.com/imdario/mergo    v0.3.9  h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
    dep github.com/jbenet/go-context    v0.0.0-20150711004518-d14ea06fba99  h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
    dep github.com/kevinburke/ssh_config    v0.0.0-20190725054713-01f96b0aa0cd  h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY=
    dep github.com/mitchellh/go-homedir v1.1.0  h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
    dep github.com/sergi/go-diff    v1.1.0  h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    dep github.com/xanzy/ssh-agent  v0.2.1  h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70=
    dep golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9  h1:sYNJzB4J8toYPQTM6pAkcmBRgw9SnQKP9oXCHfgy604=
    dep golang.org/x/net    v0.0.0-20201110031124-69a78807bb2b  h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME=
    dep golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5  h1:Lm4OryKCca1vehdsWogr9N4t7NfZxLbJoc/H0w4K4S4=
    dep golang.org/x/sys    v0.0.0-20201201145000-ef89a241ccb3  h1:kzM6+9dur93BcC2kVlYl34cHU+TYZLanmpSJHVMmL64=
    dep gopkg.in/warnings.v0    v0.1.2  h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=

I'm not sure if this is because the main package is not in the root of the module?

StevenACoffman commented 2 years ago

When I was looking into this, I found a similar tool nao1215/gup.

When they detect command-line-arguments as the importPath they just throw an error: https://github.com/nao1215/gup/blob/46bc8cd49ce5d8862a6abee857505905af728ce1/internal/goutil/goutil.go#L138-L139

Gelio commented 2 years ago

Thanks for the replies and for looking into the problem again!

The output of go-global-update --debug gnostic you shared in https://github.com/Gelio/go-global-update/issues/3#issuecomment-1071298841 suggests your GOPATH was pointing to some other directory than ~/go (/Users/steve/.asdf/installs/golang/1.17.5/packages), which is why that upgrade failed. Thanks to the log from go version -m gnostic you included, I can see that it is using the previous organization name for github.com/googleapis/gnostic, so the suggestion I made about gnostic in https://github.com/Gelio/go-global-update/issues/3#issuecomment-1068393289 (the EDIT part) is still true - you would need to do a one-time go install github.com/google/gnostic@latest to the binary to be built with the new organization name

-github.com/googleapis/gnostic
+github.com/google/gnostic

Thank you for sharing the instructions how to get build a binary with a command-line-arguments path. I have never built a binary by specifying the exact *.go file to build, I've always just used go build on the whole module. It makes sense to behave this way. I will add some tests to detect this condition and suggest what to do in that case (probably use go install, since I won't be able to support updating (devel) binaries built from source)

Also, thank you for finding https://github.com/nao1215/gup. Too bad I have not seen it before starting this project, seems like duplicate effort. I will describe that alternative tool in the README.


Looks like I have all the information to handle the edge cases you presented in this issue. None of them will be auto-upgradable, unfortunately, but go-global-update will be able to show more contextual logs in those cases. I will work on the improvements next. I appreciate you taking the time to report and research these issues, as it will make the tool more accessbile for other engineers :tada:

StevenACoffman commented 2 years ago

Thanks very much! BTW, There was also an older tool shurcooL/binstale from before modules that seems to not work so great anymore.

Gelio commented 2 years ago

I have just released v0.1.1 which should handle some of the edge cases more gracefully. I have also created #4 to add more information about other edge cases you found to provide more context about the problems.

Let me know if you think there is something else we can do to make using this tool easier

Thanks once again for reporting these problems! I appreciate it. Feel free to create other issues whenever you find something that can be improved

xxxserxxx commented 1 month ago

For anyone landing here, I was getting the following error on every binary:

could not introspect binary leg: could not get latest version of ser1.net/legume: exit status 1

I ran it with --debug and found out that it couldn't introspect modules with GO111MODULES disabled; I didn't have it set at all, and go env GO111MODULE returned auto; normally this results in on, but I was running the command outside of any project, so auto meant off. I did an extra export GO111MODULES=on and re-ran the program and after that it did its thing properly.

TL;DR: you need GO111MODULES explicitly set to on for this tool to work if you run it outside of a GOPATH or project with a go.mod in it.