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

Control sorting of image versions #3

Open
jhamman opened this issue Mar 16, 2020 · 4 comments
Open

Control sorting of image versions #3

jhamman opened this issue Mar 16, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@jhamman
Copy link

jhamman commented Mar 16, 2020

I am using this action to get the latest image version from the repo2docker repository: https://hub.docker.com/r/jupyter/repo2docker/tags

The repo2docker team produces a new image (tag) for every git commit and tag. Currently the latest commit image is jupyter/repo2docker:0.11.0-20.g070e4a9 and the latest git-tag image is jupyter/repo2docker:0.11.0.

From what I can tell, Semver sort is always going to return the latter (i.e. 0.11.0) and not the latest commit tag:

semver.Sort(tags)

Is this something we can control? (I want the latest commit tag)

@jacobtomlinson
Copy link
Owner

jacobtomlinson commented Mar 16, 2020

Hmm interesting point. In theory I would expect 0.11.0-20.g070e4a9 to sort as newer than0.11.0 as it is 20 commits ahead. But perhaps there is some logic that ignores commit tags like this.

We use this library to do the sorting. Maybe an issue there would be helpful to clarify the designed logic of the sort.

@jacobtomlinson jacobtomlinson added the bug Something isn't working label Mar 16, 2020
@jhamman
Copy link
Author

jhamman commented Mar 16, 2020

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"}
	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))
}

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]

So at least we have a way to isolate this behavior.

@jhamman
Copy link
Author

jhamman commented Mar 16, 2020

opened an issue upstream: Masterminds/semver#149

@minrk
Copy link

minrk commented Sep 9, 2020

prerelease tags are supposed to be sorted before the stable release they refer to (i.e. 0.1.0-beta < 0.1.0). So when using these as post-build suffixes, we should be using + as the separator for post-build metadata or incrementing the version, i.e. 0.2.0-n123 for "pre-0.2"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants