From bae7dc81e91cdfbe09144ba0b7b75c14710b8401 Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Wed, 11 Mar 2026 17:46:57 +0100 Subject: [PATCH 1/2] Return early from script mutator if no script is defined Move the empty command check to the top of `Apply` so that `NewCommandExecutor` (which requires a shell) is not called when no script hook is configured. This avoids a hard dependency on a shell being available during bundle initialization. Closes #4710 Co-Authored-By: Claude Opus 4.6 --- bundle/scripts/scripts.go | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/bundle/scripts/scripts.go b/bundle/scripts/scripts.go index 9b90a4e20d..58309234c5 100644 --- a/bundle/scripts/scripts.go +++ b/bundle/scripts/scripts.go @@ -32,19 +32,21 @@ func (m *script) Name() string { } func (m *script) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics { + command := getCommmand(b, m.scriptHook) + if command == "" { + log.Debugf(ctx, "No script defined for %s, skipping", m.scriptHook) + return nil + } + executor, err := exec.NewCommandExecutor(b.BundleRootPath) if err != nil { return diag.FromErr(err) } - cmd, out, err := executeHook(ctx, executor, b, m.scriptHook) + cmd, out, err := executeHook(ctx, executor, command) if err != nil { return diag.FromErr(fmt.Errorf("failed to execute script: %w", err)) } - if cmd == nil { - log.Debugf(ctx, "No script defined for %s, skipping", m.scriptHook) - return nil - } cmdio.LogString(ctx, fmt.Sprintf("Executing '%s' script", m.scriptHook)) @@ -63,12 +65,7 @@ func (m *script) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics { return nil } -func executeHook(ctx context.Context, executor *exec.Executor, b *bundle.Bundle, hook config.ScriptHook) (exec.Command, io.Reader, error) { - command := getCommmand(b, hook) - if command == "" { - return nil, nil, nil - } - +func executeHook(ctx context.Context, executor *exec.Executor, command config.Command) (exec.Command, io.Reader, error) { // Don't run any arbitrary code when restricted execution is enabled. if _, ok := env.RestrictedExecution(ctx); ok { return nil, nil, errors.New("running scripts is not allowed when DATABRICKS_BUNDLE_RESTRICTED_CODE_EXECUTION is set") From 51264f314399e04992351fb7fd31186a7085a95d Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Thu, 12 Mar 2026 08:20:21 +0100 Subject: [PATCH 2/2] Fix typo: getCommmand -> getCommand Co-Authored-By: Claude Opus 4.6 --- bundle/scripts/scripts.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bundle/scripts/scripts.go b/bundle/scripts/scripts.go index 58309234c5..cca380129a 100644 --- a/bundle/scripts/scripts.go +++ b/bundle/scripts/scripts.go @@ -32,7 +32,7 @@ func (m *script) Name() string { } func (m *script) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics { - command := getCommmand(b, m.scriptHook) + command := getCommand(b, m.scriptHook) if command == "" { log.Debugf(ctx, "No script defined for %s, skipping", m.scriptHook) return nil @@ -79,7 +79,7 @@ func executeHook(ctx context.Context, executor *exec.Executor, command config.Co return cmd, io.MultiReader(cmd.Stdout(), cmd.Stderr()), nil } -func getCommmand(b *bundle.Bundle, hook config.ScriptHook) config.Command { +func getCommand(b *bundle.Bundle, hook config.ScriptHook) config.Command { if b.Config.Experimental == nil || b.Config.Experimental.Scripts == nil { return "" }