golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.59k stars 17.48k forks source link

x/website/tour: installing @latest gets older version #47236

Open dmitshur opened 3 years ago

dmitshur commented 3 years ago

A reasonable way to install the latest version of the tour binary from its latest location is by using go install:

go install golang.org/x/website/tour@latest

However, doing so currently gets a slightly older version of the tour, before the x/website/tour nested module was merged into the x/website module in CL 323897.


``` $ go install golang.org/x/website/tour@latest go: downloading golang.org/x/website v0.0.0-20210715154925-11adafea15f8 go: downloading golang.org/x/website/tour v0.0.0-20210616181959-e0d934b43647 $ go version -m $(which tour) | head -n 3 /Users/dmitshur/go/bin/tour: go1.16.6 path golang.org/x/website/tour mod golang.org/x/website/tour v0.0.0-20210616181959-e0d934b43647 h1:IFK+1/z6bm51XIJD3ksijCgwsZXJJxliWFiIYVEG6F8= ``` Note that module path is `golang.org/x/website/tour` and version is a month-old `v0.0.0-20210616181959-e0d934b43647`, rather than the latest commit on `master` branch: ``` $ go install golang.org/x/website/tour@HEAD $ go version -m $(which tour) | head -n 3 /Users/dmitshur/go/bin/tour: go1.16.6 path golang.org/x/website/tour mod golang.org/x/website v0.0.0-20210715154925-11adafea15f8 h1:xRFLa1Fo4NnOCH0yKaPu6H36MmmA/GJEZyTEO+HOWlI= ```

A workaround is to specify @HEAD or the exact version of tour one wants.

dmitshur commented 3 years ago

Hmm, this doesn't seem to happen in GOPROXY=direct mode, so maybe the module mirror is playing a role. I'll check again later.

dmitshur commented 3 years ago

I understand why this is happening and can confirm both the go command and module mirror are working as expected. Specifically, https://golang.org/ref/mod#resolve-pkg-mod specifies that:

If one or more modules contain the requested package, the module with the longest path is used.

When the module mirror is used, the latest versions of both x/website and x/website/tour modules are found, both contain the tour package, and the x/website/tour with the its longer module path gets selected (despite being older).

I suspect we'll need to fix this by publishing a newer version of the x/website/tour module that retracts its past versions and/or deletes the tour package.

bcmills commented 3 years ago

39007 is closely related.