2022-11-30 13:15:22 +00:00
|
|
|
package artifacts
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
2023-05-16 16:35:39 +00:00
|
|
|
"github.com/databricks/cli/bundle"
|
|
|
|
"github.com/databricks/cli/bundle/artifacts/notebook"
|
2022-11-30 13:15:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func UploadAll() bundle.Mutator {
|
|
|
|
return &all{
|
|
|
|
name: "Upload",
|
|
|
|
fn: uploadArtifactByName,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type upload struct {
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
func uploadArtifactByName(name string) (bundle.Mutator, error) {
|
|
|
|
return &upload{name}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *upload) Name() string {
|
|
|
|
return fmt.Sprintf("artifacts.Upload(%s)", m.name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *upload) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) {
|
|
|
|
artifact, ok := b.Config.Artifacts[m.name]
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("artifact doesn't exist: %s", m.name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if artifact.Notebook != nil {
|
|
|
|
return []bundle.Mutator{notebook.Upload(m.name)}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|