Skip to content

Commit bb98fd2

Browse files
WIP
1 parent e85f6c2 commit bb98fd2

File tree

2 files changed

+47
-16
lines changed

2 files changed

+47
-16
lines changed

attest/vcs_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,17 @@ func TestVCS(t *testing.T) {
7676
CheckoutTag: "v0.0.2",
7777
LoadPath: "podinfo",
7878
ExpectManifests: []string{"kustomization.yaml", "deployment.yaml", "hpa.yaml", "service.yaml"},
79-
ExpectImageTags: []string{"v0.0.2"},
79+
ExpectImageTags: []string{"v6.7.0"},
8080
ExpectRawTags: []string{"0.0.2", "v0.0.2", "podinfo/v6.7.0"},
8181
},
82+
{
83+
URL: "https://github.com/errordeveloper/tape-git-testing",
84+
CheckoutHash: "9eeeed9f4ff44812ca23dba1bd0af9f509686d21", // => v0.0.1
85+
LoadPath: "podinfo",
86+
ExpectManifests: []string{"kustomization.yaml", "deployment.yaml", "hpa.yaml", "service.yaml"},
87+
ExpectImageTags: []string{"v6.6.3"},
88+
ExpectRawTags: []string{"0.0.1", "v0.0.1", "podinfo/v6.6.3"},
89+
},
8290
}
8391

8492
repos := &repos{}

oci/artefact.go

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -395,28 +395,51 @@ func SemVerTagsFromAttestations(ctx context.Context, tag name.Tag, sourceAttesta
395395
return []name.Tag{}
396396
}
397397
ref := groupSummary.Git.Reference
398-
if len(ref.Tags) == 0 {
398+
numTags := len(ref.Tags)
399+
if numTags == 0 {
399400
return []name.Tag{}
400401
}
401-
// TODO: detect tags with groupSummary.Path+"/" as prefix and priorities them
402-
tags := make([]name.Tag, 0, len(ref.Tags))
403-
set := make(map[string]struct{}, len(ref.Tags))
402+
tags := newTagtagSet(numTags)
403+
scopedTags := newTagtagSet(numTags)
404404
for i := range ref.Tags {
405405
t := ref.Tags[i].Name
406-
if !strings.HasPrefix(t, "v") {
407-
t = "v" + t
408-
}
409-
if _, ok := set[t]; !ok {
410-
if semver.IsValid(t) {
411-
tags = append(tags, tag.Context().Tag(t))
412-
set[t] = struct{}{}
413-
}
406+
// this is accounts only for a simple case where tape is pointed at a dir
407+
// and a tags have prefix that matches it exactly, it won't work for cases
408+
// where tape is pointed at a subdir a parent of which has a scoped tag
409+
if strings.HasPrefix(t, groupSummary.Path+"/") {
410+
scopedTags.add(strings.TrimPrefix(t, groupSummary.Path+"/"), tag)
411+
continue
414412
}
413+
tags.add(t, tag)
415414
}
416-
if len(tags) == 0 {
417-
return []name.Tag{}
415+
if len(scopedTags.list) > 0 {
416+
return scopedTags.list
417+
}
418+
return tags.list
419+
}
420+
421+
type tagSet struct {
422+
set map[string]struct{}
423+
list []name.Tag
424+
}
425+
426+
func newTagtagSet(c int) *tagSet {
427+
return &tagSet{
428+
set: make(map[string]struct{}, c),
429+
list: make([]name.Tag, 0, c),
430+
}
431+
}
432+
433+
func (s *tagSet) add(t string, image name.Tag) {
434+
if !strings.HasPrefix(t, "v") {
435+
t = "v" + t
436+
}
437+
if _, ok := s.set[t]; !ok {
438+
if semver.IsValid(t) {
439+
s.list = append(s.list, image.Context().Tag(t))
440+
s.set[t] = struct{}{}
441+
}
418442
}
419-
return tags
420443
}
421444

422445
func makeDescriptorWithPlatform() Descriptor {

0 commit comments

Comments
 (0)