Ignore -uki suffixed artifacts in versioneer (#262)

* Ignore `-uki` suffixed artifacts in versioneer

Part of: https://github.com/kairos-io/kairos/issues/2710

Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>

* Extract ignore suffixes to a list

Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>

* Fix comment

---------

Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
This commit is contained in:
Dimitris Karakasilis 2024-07-26 13:21:19 +03:00 committed by GitHub
parent ff56b89405
commit 7f4ace5174
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 2 deletions

View File

@ -10,6 +10,8 @@ import (
"golang.org/x/mod/semver"
)
var ignoredImageSuffixes = []string{"-uki", "-img"}
type TagList struct {
Tags []string
Artifact *Artifact
@ -59,8 +61,9 @@ func (tl TagList) Images() TagList {
newTags := []string{}
for _, t := range tl.Tags {
// We have to filter "-img" tags outside the regexp because golang regexp doesn't support negative lookaheads.
if regexpObject.MatchString(t) && !strings.HasSuffix(t, "-img") {
// Golang regexp doesn't support negative lookaheads so we filter some images
// outside regexp.
if regexpObject.MatchString(t) && !ignoreSuffixedTag(t) {
newTags = append(newTags, t)
}
}
@ -354,3 +357,12 @@ func extractVersions(tagToCheck string, artifact Artifact) []string {
func newTagListWithTags(tl TagList, tags []string) TagList {
return TagList{Artifact: tl.Artifact, RegistryAndOrg: tl.RegistryAndOrg, Tags: tags}
}
func ignoreSuffixedTag(tag string) bool {
for _, i := range ignoredImageSuffixes {
if strings.HasSuffix(tag, i) {
return true
}
}
return false
}

View File

@ -40,6 +40,20 @@ var _ = Describe("TagList", func() {
expectOnlyImages(images.Tags)
})
// Fixed bug
It("filters out -uki suffixed images", func() {
// Add a -uki suffixed (otherwise matching) artifact
badTag := "tumbleweed-standard-amd64-generic-v2.4.2-k3sv1.27.6-k3s1-uki"
tagList.Tags = append(tagList.Tags, badTag)
images := tagList.Images()
Expect(images.Tags).ToNot(ContainElement(badTag))
// Sanity check, that we didn't filter everything out
Expect(len(images.Tags)).To(BeNumerically(">", 4))
expectOnlyImages(images.Tags)
})
})
Describe("FullImages", func() {
@ -356,6 +370,7 @@ func expectOnlyImages(images []string) {
Expect(images).ToNot(ContainElement(ContainSubstring(".sbom")))
Expect(images).ToNot(ContainElement(ContainSubstring(".sig")))
Expect(images).ToNot(ContainElement(ContainSubstring("-img")))
Expect(images).ToNot(ContainElement(ContainSubstring("-uki")))
Expect(images).To(HaveEach(MatchRegexp((".*-(core|standard)-(amd64|arm64)-.*-v.*"))))
}