Skip to content

Commit 7750f49

Browse files
committed
add calver dep
1 parent cfc22fa commit 7750f49

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

registry-scanner/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/Masterminds/semver/v3 v3.3.1
77
github.com/argoproj/pkg v0.13.7-0.20230627120311-a4dd357b057e
88
github.com/distribution/distribution/v3 v3.0.0-20230722181636-7b502560cad4
9+
github.com/k1LoW/calver v0.7.3
910
github.com/opencontainers/go-digest v1.0.0
1011
github.com/opencontainers/image-spec v1.1.0
1112
github.com/patrickmn/go-cache v2.1.0+incompatible
@@ -55,6 +56,7 @@ require (
5556
github.com/prometheus/client_model v0.5.0 // indirect
5657
github.com/prometheus/common v0.48.0 // indirect
5758
github.com/prometheus/procfs v0.12.0 // indirect
59+
github.com/snabb/isoweek v1.0.3 // indirect
5860
github.com/spf13/pflag v1.0.5 // indirect
5961
github.com/stretchr/objx v0.5.2 // indirect
6062
github.com/x448/float16 v0.8.4 // indirect

registry-scanner/go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u
156156
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
157157
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
158158
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
159+
github.com/k1LoW/calver v0.7.3 h1:i05crMZqiIgkswcv0esE7DBi+QBpIr1BP/3PgV5HAmg=
160+
github.com/k1LoW/calver v0.7.3/go.mod h1:Djp3yuoeRnIxwWjLOwY14lgcha5YnWYggABhNhSxHl4=
159161
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
160162
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
161163
github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI=
@@ -284,6 +286,8 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx
284286
github.com/sirupsen/logrus v1.9.2/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
285287
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
286288
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
289+
github.com/snabb/isoweek v1.0.3 h1:BwEULUhj7UToLLa7FivDTLzA4y1epTYkLhnn31huBRs=
290+
github.com/snabb/isoweek v1.0.3/go.mod h1:J5hJfY1CG56xmKCC/4XfoaWZcOiB+qntmyKEDATSnlw=
287291
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
288292
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
289293
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=

registry-scanner/pkg/tag/tag.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/log"
1010

1111
"github.com/Masterminds/semver/v3"
12+
"github.com/k1LoW/calver"
1213
)
1314

1415
// ImageTag is a representation of an image tag with metadata
@@ -172,6 +173,29 @@ func (il ImageTagList) SortBySemVer() SortableImageTagList {
172173
return sil
173174
}
174175

176+
func (il ImageTagList) SortByCalVer() SortableImageTagList {
177+
il.lock.RLock()
178+
defer il.lock.RUnlock()
179+
sil := make(SortableImageTagList, 0, len(il.items))
180+
calvers := make([]calver.Calver, 0, len(il.items))
181+
for _, v := range il.items {
182+
cv, err := calver.Parse(v.TagName)
183+
if err != nil {
184+
// Fallback to alphabetical order if parsing fails
185+
sil = append(sil, v)
186+
} else {
187+
calvers = append(calvers, cv)
188+
}
189+
}
190+
sort.Slice(calvers, func(i, j int) bool {
191+
return calvers[i].String() < calvers[j].String()
192+
})
193+
for _, cv := range calvers {
194+
sil = append(sil, il.items[cv.String()])
195+
}
196+
return sil
197+
}
198+
175199
// Should only be used in a method that holds a lock on the ImageTagList
176200
func (il ImageTagList) unlockedContains(tag *ImageTag) bool {
177201
if _, ok := il.items[tag.TagName]; ok {

0 commit comments

Comments
 (0)