2022-11-30 13:15:22 +00:00
|
|
|
package artifacts
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
2023-08-15 13:50:40 +00:00
|
|
|
"slices"
|
|
|
|
|
2023-05-16 16:35:39 +00:00
|
|
|
"github.com/databricks/cli/bundle"
|
2022-11-30 13:15:22 +00:00
|
|
|
"golang.org/x/exp/maps"
|
|
|
|
)
|
|
|
|
|
|
|
|
// all is an internal proxy for producing a list of mutators for all artifacts.
|
|
|
|
// It is used to produce the [BuildAll] and [UploadAll] mutators.
|
|
|
|
type all struct {
|
|
|
|
name string
|
|
|
|
fn func(name string) (bundle.Mutator, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *all) Name() string {
|
|
|
|
return fmt.Sprintf("artifacts.%sAll", m.name)
|
|
|
|
}
|
|
|
|
|
2023-05-24 12:45:19 +00:00
|
|
|
func (m *all) Apply(ctx context.Context, b *bundle.Bundle) error {
|
2022-11-30 13:15:22 +00:00
|
|
|
var out []bundle.Mutator
|
|
|
|
|
|
|
|
// Iterate with stable ordering.
|
|
|
|
keys := maps.Keys(b.Config.Artifacts)
|
|
|
|
slices.Sort(keys)
|
|
|
|
|
|
|
|
for _, name := range keys {
|
|
|
|
m, err := m.fn(name)
|
|
|
|
if err != nil {
|
2023-05-24 12:45:19 +00:00
|
|
|
return err
|
2022-11-30 13:15:22 +00:00
|
|
|
}
|
|
|
|
if m != nil {
|
|
|
|
out = append(out, m)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-24 12:45:19 +00:00
|
|
|
return bundle.Apply(ctx, b, bundle.Seq(out...))
|
2022-11-30 13:15:22 +00:00
|
|
|
}
|