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 BuildAll() bundle.Mutator {
|
|
|
|
return &all{
|
|
|
|
name: "Build",
|
|
|
|
fn: buildArtifactByName,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type build struct {
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildArtifactByName(name string) (bundle.Mutator, error) {
|
|
|
|
return &build{name}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *build) Name() string {
|
|
|
|
return fmt.Sprintf("artifacts.Build(%s)", m.name)
|
|
|
|
}
|
|
|
|
|
2023-05-24 12:45:19 +00:00
|
|
|
func (m *build) Apply(ctx context.Context, b *bundle.Bundle) error {
|
2022-11-30 13:15:22 +00:00
|
|
|
artifact, ok := b.Config.Artifacts[m.name]
|
|
|
|
if !ok {
|
2023-05-24 12:45:19 +00:00
|
|
|
return fmt.Errorf("artifact doesn't exist: %s", m.name)
|
2022-11-30 13:15:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if artifact.Notebook != nil {
|
2023-05-24 12:45:19 +00:00
|
|
|
return bundle.Apply(ctx, b, notebook.Build(m.name))
|
2022-11-30 13:15:22 +00:00
|
|
|
}
|
|
|
|
|
2023-05-24 12:45:19 +00:00
|
|
|
return nil
|
2022-11-30 13:15:22 +00:00
|
|
|
}
|