mirror of
https://github.com/kairos-io/kairos-sdk.git
synced 2025-04-27 19:15:23 +00:00
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:
parent
ff56b89405
commit
7f4ace5174
@ -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
|
||||
}
|
||||
|
@ -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.*"))))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user