Cannot get latest version: module contains a go.mod file, so module path should be github.com/exercism/cli/v3

Open
#933 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
go
Domain
build-system, cli

Research direction

Start with the repository's go.mod and reproduce the failure using GO111MODULE=on and go get github.com/exercism/cli@v3.0.13. Trace internal import statements and compare the available migration options in the issue. Done means the chosen module layout allows module-aware users to fetch the intended v3 release and the project still builds.

Written by the indexing model from the issue text.

Description

Background

The github.com/exercism/cli uses Go modules and the current release version is v3. And it’s module path is "github.com/exercism/cli", instead of "github.com/exercism/cli/v3". It must comply with the specification of "Releasing Modules for v2 or higher" available in the Modules documentation. Quoting the specification:

A package that has opted in to modules must include the major version in the import path to import any v2+ modules
To preserve import compatibility, the go command requires that modules with major version v2 or later use a module path with that major version as the final element. For example, version v2.0.0 of example.com/m must instead use module path example.com/m/v2.
https://github.com/golang/go/wiki/Modules#releasing-modules-v2-or-higher

Steps to Reproduce

GO111MODULE=on, run go get targeting any version >= v3.0.12 of the exercism/cli:

$ go get github.com/exercism/cli@v3.0.13
go: finding github.com/exercism/cli v3.0.13
go: finding github.com/exercism/cli v3.0.13
go get github.com/exercism/cli@v3.0.13: github.com/exercism/cli@v3.0.13: invalid version: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v3

run go get github.com/exercism/cli, the version will stuck in v3.0.11:

$go get github.com/exercism/cli
go: downloading github.com/exercism/cli v1.9.2
go: downloading github.com/exercism/cli v3.0.11+incompatible
go: github.com/exercism/cli upgrade => v3.0.11+incompatible

SO anyone using Go modules will not be able to easily use any newer version of exercism/cli.

Solution

1. Kill the go.mod files, rolling back to GOPATH.

This would push them back to not being managed by Go modules (instead of incorrectly using Go modules).
Ensure compatibility for downstream module-aware projects and module-unaware projects projects

2. Fix module path to strictly follow SIV rules.

Patch the go.mod file to declare the module path as github.com/exercism/cli/v3 as per the specs. And adjust all internal imports.
The downstream projects might be negatively affected in their building if they are module-unaware (Go versions older than 1.9.7 and 1.10.3; Or use third-party dependency management tools, such as: Dep, glide,govendor…).

If you don't want to break the above repos. This method can provides better backwards-compatibility.
Release a v2 or higher module through the major subdirectory strategy: Create a new v3 subdirectory (github.com/exercism/cli/v3) and place a new go.mod file in that subdirectory. The module path must end with /v3. Copy or move the code into the v3 subdirectory. Update import statements within the module to also use /v3 (import "github.com/exercism/cli/v3/…"). Tag the release with v3.x.y.

3. Suggest your downstream module users use hash instead of a version tag.

If the standard rule of go modules conflicts with your development mode. Or not intended to be used as a library and does not make any guarantees about the API. So you can’t comply with the specification of "Releasing Modules for v2 or higher" available in the Modules documentation.
Regardless, since it's against one of the design choices of Go, it'll be a bit of a hack. Instead of go get github.com/exercism/cli@version-tag, module users need to use this following way to get the exercism/cli:
(1) Search for the tag you want (in browser)
(2) Get the commit hash for the tag you want
(3) Run go get github.com/exercism/cli@commit-hash
(4) Edit the go.mod file to put a comment about which version you actually used
This will make it difficult for module users to get and upgrade exercism/cli.

[*] You can see who will be affected here: [2 module users, e.g., fabiotavarespr/Planilha-MTG, exercism/cli]
https://github.com/search?q=exercism%2Fcli+filename%3Ago.mod

Summary

You can make a choice to fix DM issues by balancing your own development schedules/mode against the affects on the downstream projects.

For this issue, Solution 2 can maximize your benefits and with minimal impacts to your downstream projects the ecosystem.

References

Dominant language
Go
Stars
1.4k
Forks
363
Avg merge
6d 13h
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from exercism/cli

All issues in exercism/cli

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.