@@ -13,6 +13,8 @@ import (
13
13
"path/filepath"
14
14
"time"
15
15
16
+ "golang.org/x/mod/semver"
17
+
16
18
ociclient "github.com/fluxcd/pkg/oci"
17
19
"github.com/go-git/go-git/v5/utils/ioutil"
18
20
"github.com/google/go-containerregistry/pkg/compression"
@@ -25,6 +27,7 @@ import (
25
27
26
28
"github.com/errordeveloper/tape/attest/manifest"
27
29
attestTypes "github.com/errordeveloper/tape/attest/types"
30
+ "github.com/errordeveloper/tape/attest/vcs/git"
28
31
manifestTypes "github.com/errordeveloper/tape/manifest/types"
29
32
)
30
33
@@ -224,10 +227,6 @@ func (c *Client) PushArtefact(ctx context.Context, destinationRef, sourceDir str
224
227
}
225
228
defer os .RemoveAll (tmpDir )
226
229
227
- _ , err = SemVerFromAttestations (ctx , sourceAttestations ... )
228
- if err != nil {
229
- return "" , err
230
- }
231
230
tmpFile := filepath .Join (tmpDir , "artefact.tgz" )
232
231
233
232
outputFile , err := os .OpenFile (tmpFile , os .O_RDWR | os .O_CREATE | os .O_EXCL , regularFileMode )
@@ -255,7 +254,11 @@ func (c *Client) PushArtefact(ctx context.Context, destinationRef, sourceDir str
255
254
}
256
255
hash := hex .EncodeToString (c .hash .Sum (nil ))
257
256
tag := repo .Tag (manifestTypes .ConfigImageTagPrefix + hash )
258
- tagAlias := tag .Context ().Tag (manifestTypes .ConfigImageTagPrefix + hash [:7 ])
257
+
258
+ tagAliases := append (
259
+ SemVerTagsFromAttestations (ctx , tag , sourceAttestations ... ),
260
+ tag .Context ().Tag (manifestTypes .ConfigImageTagPrefix + hash [:7 ]),
261
+ )
259
262
260
263
if timestamp == nil {
261
264
timestamp = new (time.Time )
@@ -346,25 +349,51 @@ func (c *Client) PushArtefact(ctx context.Context, destinationRef, sourceDir str
346
349
return "" , fmt .Errorf ("pushing index failed: %w" , err )
347
350
}
348
351
349
- if err := remote .Tag (tagAlias , index , c .remoteWithContext (ctx )... ); err != nil {
350
- return "" , fmt .Errorf ("adding alias tagging failed: %w" , err )
352
+ for i := range tagAliases {
353
+ if err := remote .Tag (tagAliases [i ], index , c .remoteWithContext (ctx )... ); err != nil {
354
+ return "" , fmt .Errorf ("adding alias tagging failed: %w" , err )
355
+ }
351
356
}
352
357
353
- return tagAlias .String () + "@" + digest .String (), err
358
+ return tagAliases [ 0 ] .String () + "@" + digest .String (), err
354
359
}
355
360
356
- func SemVerFromAttestations (ctx context.Context , sourceAttestations ... attestTypes.Statement ) ( string , error ) {
361
+ func SemVerTagsFromAttestations (ctx context.Context , tag name. Tag , sourceAttestations ... attestTypes.Statement ) []name. Tag {
357
362
statements := attestTypes .FilterByPredicateType (manifest .ManifestDirPredicateType , sourceAttestations )
358
- if len (statements ) == 0 {
359
- return "" , fmt . Errorf ( "VCS provinance attestion (%q) not found" , manifest . ManifestDirPredicateType )
363
+ if len (statements ) != 1 {
364
+ return []name. Tag {}
360
365
}
361
- if len (statements ) > 1 {
362
- return "" , fmt .Errorf ("too many attestations of type %q found, expected 1" , manifest .ManifestDirPredicateType )
366
+
367
+ entries := manifest .MakeDirContentsStatementFrom (statements [0 ]).GetUnderlyingPredicate ().VCSEntries
368
+ if len (entries .EntryGroups ) != 1 && len (entries .Providers ) != 1 ||
369
+ entries .Providers [0 ] != git .ProviderName {
370
+ return []name.Tag {}
371
+ }
372
+ if len (entries .EntryGroups [0 ]) == 0 {
373
+ return []name.Tag {}
374
+ }
375
+ groupSummary , ok := entries .EntryGroups [0 ][0 ].Full ().(* git.GitSummary )
376
+ if ! ok {
377
+ return []name.Tag {}
378
+ }
379
+ if len (groupSummary .Reference .Tags ) == 0 {
380
+ return []name.Tag {}
363
381
}
364
382
365
- _ = manifest . MakeDirContentsStatementFrom ( statements [ 0 ] )
383
+ tags := make ([]name. Tag , 0 , len ( groupSummary . Reference . Tags ) )
366
384
367
- return "" , nil
385
+ // TODO: detect tags with groupSummary.Path+"/" as prefix and priorities them
386
+ for i := range groupSummary .Reference .Tags {
387
+ t := groupSummary .Reference .Tags [i ].Name
388
+ fmt .Println (t )
389
+ if semver .IsValid (t ) {
390
+ tags = append (tags , tag .Context ().Tag (t ))
391
+ }
392
+ }
393
+ if len (tags ) == 0 {
394
+ return []name.Tag {}
395
+ }
396
+ return tags
368
397
}
369
398
370
399
func makeDescriptorWithPlatform () Descriptor {
0 commit comments