jpillora / media-sort

Automatically organise your movies and tv series
MIT License
118 stars 21 forks source link

Fix go get by removing broken v2 tags #28

Open KateGo520 opened 4 years ago

KateGo520 commented 4 years ago

Background

The github.com/jpillora/media-sort uses Go modules and the current release version is v2. And it’s module path is "github.com/jpillora/media-sort", instead of "github.com/jpillora/media-sort/v2". 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 >= v2.3.0 of the jpillora/media-sort:

$ go get github.com/jpillora/media-sort@v2.3.0
go: finding github.com/jpillora/media-sort v2.3.0
go: finding github.com/jpillora/media-sort v2.3.0
go get github.com/jpillora/media-sort@v2.3.0: github.com/jpillora/media-sort@v2.3.0: invalid version: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v2

SO anyone using Go modules will not be able to easily use any newer version of jpillora/media-sort.

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/jpillora/media-sort/v2 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 v2 subdirectory (github.com/jpillora/media-sort/v2) and place a new go.mod file in that subdirectory. The module path must end with /v2. Copy or move the code into the v2 subdirectory. Update import statements within the module to also use /v2 (import "github.com/jpillora/media-sort/v2/…"). Tag the release with v2.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/jpillora/media-sort@version-tag, module users need to use this following way to get the jpillora/media-sort: (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/jpillora/media-sort@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 jpillora/media-sort.

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

KateGo520 commented 4 years ago

@jpillora @rotsix Could you help me review this issue? Thx :p

jpillora commented 4 years ago

Thanks for the detailed writeup! I'd already moved to v2 before I switched to modules, though definitely missed this glaring issue - however I thinking of going for option 6 :P Delete all the v2 tags (since they're broken anyway) and re-tag as a v1. Thoughts?

KateGo520 commented 4 years ago

@jpillora I'm worried that those repos that have used v2 tag will be break.

jpillora commented 4 years ago

Can external repos use the v2 tag? I thought they recieve an invalid version error? Sorry I haven't tested any of this yet

On Sat, 25 Jul 2020 at 11:01, KateGo520 notifications@github.com wrote:

@jpillora https://github.com/jpillora I'm worried that those repos that have used v2 tag will be destroyed.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jpillora/media-sort/issues/28#issuecomment-663787259, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAE2X4Z3BZH6KHHERP2ZH53R5IVHJANCNFSM4PGKFMHQ .

jpillora commented 4 years ago

main.go

package main

import mediasort "github.com/jpillora/media-sort/sort"

func main() {
    c := mediasort.Config{}
    c.DryRun = true
}

go.mod

module github.com/jpillora/foobar

go 1.14

then

$ go get -v .

go.mod again

module github.com/jpillora/foobar

go 1.14

require github.com/jpillora/media-sort v0.0.0-20200710203312-f7ab1e0e0471

and if you try to get a v2 tag directly

$ go get -v github.com/jpillora/media-sort@v2.6.2
go get github.com/jpillora/media-sort@v2.6.2: github.com/jpillora/media-sort@v2.6.2: invalid version: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v2

so I think it would be okay to remove the v2 tags

KateGo520 commented 4 years ago

@jpillora OK,thank you for your reply.

jpillora commented 4 years ago

Sorry hopefully will get around to this soon