Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Jul 5, 2024
1 parent e85f6c2 commit bb98fd2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
10 changes: 9 additions & 1 deletion attest/vcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,17 @@ func TestVCS(t *testing.T) {
CheckoutTag: "v0.0.2",
LoadPath: "podinfo",
ExpectManifests: []string{"kustomization.yaml", "deployment.yaml", "hpa.yaml", "service.yaml"},
ExpectImageTags: []string{"v0.0.2"},
ExpectImageTags: []string{"v6.7.0"},
ExpectRawTags: []string{"0.0.2", "v0.0.2", "podinfo/v6.7.0"},
},
{
URL: "https://github.com/errordeveloper/tape-git-testing",
CheckoutHash: "9eeeed9f4ff44812ca23dba1bd0af9f509686d21", // => v0.0.1
LoadPath: "podinfo",
ExpectManifests: []string{"kustomization.yaml", "deployment.yaml", "hpa.yaml", "service.yaml"},
ExpectImageTags: []string{"v6.6.3"},
ExpectRawTags: []string{"0.0.1", "v0.0.1", "podinfo/v6.6.3"},
},
}

repos := &repos{}
Expand Down
53 changes: 38 additions & 15 deletions oci/artefact.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,28 +395,51 @@ func SemVerTagsFromAttestations(ctx context.Context, tag name.Tag, sourceAttesta
return []name.Tag{}
}
ref := groupSummary.Git.Reference
if len(ref.Tags) == 0 {
numTags := len(ref.Tags)
if numTags == 0 {
return []name.Tag{}
}
// TODO: detect tags with groupSummary.Path+"/" as prefix and priorities them
tags := make([]name.Tag, 0, len(ref.Tags))
set := make(map[string]struct{}, len(ref.Tags))
tags := newTagtagSet(numTags)
scopedTags := newTagtagSet(numTags)
for i := range ref.Tags {
t := ref.Tags[i].Name
if !strings.HasPrefix(t, "v") {
t = "v" + t
}
if _, ok := set[t]; !ok {
if semver.IsValid(t) {
tags = append(tags, tag.Context().Tag(t))
set[t] = struct{}{}
}
// this is accounts only for a simple case where tape is pointed at a dir
// and a tags have prefix that matches it exactly, it won't work for cases
// where tape is pointed at a subdir a parent of which has a scoped tag
if strings.HasPrefix(t, groupSummary.Path+"/") {
scopedTags.add(strings.TrimPrefix(t, groupSummary.Path+"/"), tag)
continue
}
tags.add(t, tag)
}
if len(tags) == 0 {
return []name.Tag{}
if len(scopedTags.list) > 0 {
return scopedTags.list
}
return tags.list
}

type tagSet struct {
set map[string]struct{}
list []name.Tag
}

func newTagtagSet(c int) *tagSet {
return &tagSet{
set: make(map[string]struct{}, c),
list: make([]name.Tag, 0, c),
}
}

func (s *tagSet) add(t string, image name.Tag) {
if !strings.HasPrefix(t, "v") {
t = "v" + t
}
if _, ok := s.set[t]; !ok {
if semver.IsValid(t) {
s.list = append(s.list, image.Context().Tag(t))
s.set[t] = struct{}{}
}
}
return tags
}

func makeDescriptorWithPlatform() Descriptor {
Expand Down

0 comments on commit bb98fd2

Please sign in to comment.