Skip to content

Integrate ScriptExecutor into HooksRunner #7441

Description

@wbreza

Integrate ScriptExecutor into HooksRunner

Part of #7435 — Multi-Language Hook Support

User Story

As a template consumer, I want Python hooks defined in azure.yaml to execute automatically during azd up/azd deploy alongside existing shell hooks so the deployment lifecycle works end-to-end.

Solution Approach

Modify pkg/ext/hooks_runner.go:

  1. Add import for pkg/tools/language.

  2. Add GetScriptExecutor(hookConfig *HookConfig) (language.ScriptExecutor, error) method:

    • Resolve executor via language.GetExecutor(hookConfig.ScriptLanguage(), h.commandRunner, h.console, h.cwd).
  3. Update execHook() — branch on hookConfig.IsLanguageHook():

    if hookConfig.IsLanguageHook() {
        executor, err := h.GetScriptExecutor(hookConfig)
        // ...
        if err := executor.Prepare(ctx, hookConfig.path); err != nil { ... }
        res, err := executor.Execute(ctx, hookConfig.path, *options)
        // ... shared post-execution logic ...
    } else {
        // existing shell hook path — unchanged
    }
  4. Extract shared post-execution logic (ContinueOnError, output previewer, cleanup) into helper to avoid duplication.

  5. Thread environment variables via ExecOptions.Env or executor constructor.

Modify pkg/ext/hooks_runner_test.go:

  1. Python hook full pipeline (mock CommandRunner expects: version check → venv → pip → execute)
  2. Shell hook unchanged (.sh does NOT trigger language path)
  3. ContinueOnError with failing Python hook
  4. Interactive mode flag passthrough

Follow existing test pattern: mocks.NewMockContext, mockenv.MockEnvManager, mockContext.CommandRunner.When(...).RespondFn(...).

Files: pkg/ext/hooks_runner.go (MODIFY), pkg/ext/hooks_runner_test.go (MODIFY)

Acceptance Criteria

  • Python .py hooks execute through ScriptExecutor path automatically
  • Shell .sh/.ps1 hooks execute through existing Script path (no regression)
  • Inline shell hooks completely unaffected
  • Error messages clearly indicate which hook and language failed
  • ContinueOnError and Interactive flags work for language hooks
  • Environment variables passed to language hooks

References

Metadata

Metadata

Assignees

Labels

area/core-cliCLI commands, cmd/, internal/cmd/area/hooksLifecycle hooksfeatureFeature request

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions