Skip to content

Commit

Permalink
Sort unknown versions higher in bump sort
Browse files Browse the repository at this point in the history
When using "bump" sort, place images for which version could not be
identified in between the group of outdated and updated images. This
improves the UX as their state is unknown, but similar to other images
of the same state.
  • Loading branch information
AlexGustafsson committed Dec 22, 2024
1 parent 1ab6393 commit 8f277aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 8 additions & 3 deletions internal/semver/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,17 @@ func LatestOpinionatedVersionString(current string, versions []string) (string,
// used to diff two versions of the same image. The resulting diff is sortable
// among with calculated values. Might fall apart if there are many parts, but
// most of the time, there are only three or four version parts.
// Note that it is valid to pass a nil [Version], which will be treated as a
// unknown version.
func PackInt64(version *Version) uint64 {
var packed uint64
if version == nil {
return 1
}

bitsPerPart := 64 / len(version.Release)
var packed uint64
bitsPerPart := 63 / len(version.Release)
for i, part := range version.Release {
packed |= uint64(part) << uint64((len(version.Release)-i-1)*bitsPerPart)
packed |= uint64(part) << uint64((len(version.Release)-i-1)*bitsPerPart+1)
}

return packed
Expand Down
6 changes: 4 additions & 2 deletions internal/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,17 @@ func (w *Worker) ProcessRawImage(ctx context.Context, reference oci.Reference) e
// Fallthrough - insert what we have
}

versionDiffSortable := semver.PackInt64(nil)

// If no new version was defined and the current version is using the "latest"
// convention, the latest available reference is the current reference
if reference.Version() == "latest" && data.LatestReference == nil {
if reference.Version() == "latest" {
r := reference
data.LatestReference = &r
versionDiffSortable = 0
}

// Add some basic tags
var versionDiffSortable uint64
if data.LatestReference != nil {
if data.ImageReference.String() == data.LatestReference.String() {
data.Tags = append(data.Tags, "up-to-date")
Expand Down

0 comments on commit 8f277aa

Please sign in to comment.