2022-11-30 13:15:22 +00:00
|
|
|
package artifacts
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-05-16 16:35:39 +00:00
|
|
|
"github.com/databricks/cli/bundle"
|
2024-08-14 09:03:44 +00:00
|
|
|
"github.com/databricks/cli/bundle/libraries"
|
2024-03-25 14:18:47 +00:00
|
|
|
"github.com/databricks/cli/libs/diag"
|
2024-07-16 08:57:04 +00:00
|
|
|
"github.com/databricks/cli/libs/filer"
|
|
|
|
"github.com/databricks/cli/libs/log"
|
2022-11-30 13:15:22 +00:00
|
|
|
)
|
|
|
|
|
2023-07-25 11:35:08 +00:00
|
|
|
func CleanUp() bundle.Mutator {
|
|
|
|
return &cleanUp{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type cleanUp struct{}
|
|
|
|
|
|
|
|
func (m *cleanUp) Name() string {
|
|
|
|
return "artifacts.CleanUp"
|
|
|
|
}
|
|
|
|
|
2024-03-25 14:18:47 +00:00
|
|
|
func (m *cleanUp) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
2024-12-02 21:18:07 +00:00
|
|
|
client, uploadPath, diags := libraries.GetFilerForLibraries(ctx, b)
|
|
|
|
if diags.HasError() {
|
|
|
|
return diags
|
2024-07-16 08:57:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We intentionally ignore the error because it is not critical to the deployment
|
2024-12-02 21:18:07 +00:00
|
|
|
err := client.Delete(ctx, ".", filer.DeleteRecursively)
|
2024-07-16 08:57:04 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf(ctx, "failed to delete %s: %v", uploadPath, err)
|
|
|
|
}
|
2023-07-25 11:35:08 +00:00
|
|
|
|
2024-07-16 08:57:04 +00:00
|
|
|
err = client.Mkdir(ctx, ".")
|
2023-07-25 11:35:08 +00:00
|
|
|
if err != nil {
|
2024-03-25 14:18:47 +00:00
|
|
|
return diag.Errorf("unable to create directory for %s: %v", uploadPath, err)
|
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
|
|
|
}
|