Skip to content

Commit bae7dc8

Browse files
pieternclaude
andcommitted
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 <noreply@anthropic.com>
1 parent da35a12 commit bae7dc8

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

bundle/scripts/scripts.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,21 @@ func (m *script) Name() string {
3232
}
3333

3434
func (m *script) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
35+
command := getCommmand(b, m.scriptHook)
36+
if command == "" {
37+
log.Debugf(ctx, "No script defined for %s, skipping", m.scriptHook)
38+
return nil
39+
}
40+
3541
executor, err := exec.NewCommandExecutor(b.BundleRootPath)
3642
if err != nil {
3743
return diag.FromErr(err)
3844
}
3945

40-
cmd, out, err := executeHook(ctx, executor, b, m.scriptHook)
46+
cmd, out, err := executeHook(ctx, executor, command)
4147
if err != nil {
4248
return diag.FromErr(fmt.Errorf("failed to execute script: %w", err))
4349
}
44-
if cmd == nil {
45-
log.Debugf(ctx, "No script defined for %s, skipping", m.scriptHook)
46-
return nil
47-
}
4850

4951
cmdio.LogString(ctx, fmt.Sprintf("Executing '%s' script", m.scriptHook))
5052

@@ -63,12 +65,7 @@ func (m *script) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
6365
return nil
6466
}
6567

66-
func executeHook(ctx context.Context, executor *exec.Executor, b *bundle.Bundle, hook config.ScriptHook) (exec.Command, io.Reader, error) {
67-
command := getCommmand(b, hook)
68-
if command == "" {
69-
return nil, nil, nil
70-
}
71-
68+
func executeHook(ctx context.Context, executor *exec.Executor, command config.Command) (exec.Command, io.Reader, error) {
7269
// Don't run any arbitrary code when restricted execution is enabled.
7370
if _, ok := env.RestrictedExecution(ctx); ok {
7471
return nil, nil, errors.New("running scripts is not allowed when DATABRICKS_BUNDLE_RESTRICTED_CODE_EXECUTION is set")

0 commit comments

Comments
 (0)