2024-02-05 15:29:45 +00:00
|
|
|
package libraries
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/databricks/cli/bundle"
|
2024-03-25 14:18:47 +00:00
|
|
|
"github.com/databricks/cli/libs/diag"
|
2024-02-05 15:29:45 +00:00
|
|
|
"github.com/databricks/databricks-sdk-go/service/jobs"
|
|
|
|
)
|
|
|
|
|
|
|
|
type match struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func MatchWithArtifacts() bundle.Mutator {
|
|
|
|
return &match{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *match) Name() string {
|
|
|
|
return "libraries.MatchWithArtifacts"
|
|
|
|
}
|
|
|
|
|
2024-03-25 14:18:47 +00:00
|
|
|
func (a *match) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
2024-02-05 15:29:45 +00:00
|
|
|
tasks := findAllTasks(b)
|
|
|
|
for _, task := range tasks {
|
|
|
|
if isMissingRequiredLibraries(task) {
|
2024-03-25 14:18:47 +00:00
|
|
|
return diag.Errorf("task '%s' is missing required libraries. Please include your package code in task libraries block", task.TaskKey)
|
2024-02-05 15:29:45 +00:00
|
|
|
}
|
|
|
|
for j := range task.Libraries {
|
|
|
|
lib := &task.Libraries[j]
|
|
|
|
_, err := findArtifactFiles(ctx, lib, b)
|
|
|
|
if err != nil {
|
2024-03-25 14:18:47 +00:00
|
|
|
return diag.FromErr(err)
|
2024-02-05 15:29:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func isMissingRequiredLibraries(task *jobs.Task) bool {
|
|
|
|
if task.Libraries != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return task.PythonWheelTask != nil || task.SparkJarTask != nil
|
|
|
|
}
|