MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / Run

Method Run

app/cli/pkg/action/artifact_upload.go:47–76  ·  view source on GitHub ↗
(filePath string)

Source from the content-addressed store, hash-verified

45}
46
47func (a *ArtifactUpload) Run(filePath string) (*CASArtifact, error) {
48 client := casclient.New(a.artifactsCASConn, casclient.WithLogger(a.Logger))
49
50 // open file and calculate size
51 f, err := os.Open(filePath)
52 if err != nil {
53 return nil, fmt.Errorf("can't open file to upload: %w", err)
54 }
55 defer f.Close()
56
57 info, err := f.Stat()
58 if err != nil {
59 return nil, fmt.Errorf("retrieving file information: %w", err)
60 }
61
62 // render progress bar
63 go renderOperationStatus(context.Background(), client.ProgressStatus, info.Size())
64 defer close(client.ProgressStatus)
65
66 res, err := client.UploadFile(context.Background(), filePath)
67 if err != nil {
68 return nil, err
69 }
70
71 // Give some time for the progress renderer to finish
72 // TODO: Implement with proper subroutine messaging
73 time.Sleep(progress.DefaultUpdateFrequency)
74
75 return &CASArtifact{Digest: res.Digest, fileName: res.Filename}, nil
76}

Callers

nothing calls this directly

Calls 5

NewFunction · 0.92
WithLoggerFunction · 0.92
renderOperationStatusFunction · 0.85
UploadFileMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected