Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting of pre-release versions #149

Open
jhamman opened this issue Mar 16, 2020 · 1 comment
Open

Sorting of pre-release versions #149

jhamman opened this issue Mar 16, 2020 · 1 comment
Labels

Comments

@jhamman
Copy link

jhamman commented Mar 16, 2020

How are pre-release versions intended to be sorted in this library?

Take this simple test:

package main

import (
	"fmt"
	"github.com/coreos/go-semver/semver"
)

func main() {

	raw := []string{"0.11.0-20.g070e4a9", "0.12.0", "0.11.0"}
	fmt.Println(fmt.Sprintf(`Unsorted Tags::%s`, raw))
	var tags []*semver.Version
	for _, r := range raw {	
		tags = append(tags, semver.New(r))
	}
	semver.Sort(tags)
	fmt.Println(fmt.Sprintf(`Sorted Tags (oldest -> newest)::%s`, tags))
}

which yields:

$ go run test.go
Unsorted Tags::[0.11.0-20.g070e4a9 0.12.0 0.11.0]
Sorted Tags (oldest -> newest)::[0.11.0-20.g070e4a9 0.11.0 0.12.0]

I would have expected the following ordering: [0.11.0 0.11.0-20.g070e4a9 0.12.0]. Is this the expected behavior?

@mattfarina
Copy link
Member

@jhamman pre-releases are those that are before a release. The spec provides an example of precedence which has an ordering in it at https://semver.org/#spec-item-11. The order you see in the sorted tags is the order that is correct per the spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants