ext

package
v1.23.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Executes pre hooks
	HookTypePre HookType = "pre"
	// Execute post hooks
	HookTypePost        HookType         = "post"
	HookTypeNone        HookType         = ""
	HookPlatformWindows HookPlatformType = "windows"
	HookPlatformPosix   HookPlatformType = "posix"
)

Variables

View Source
var (
	// ErrScriptTypeUnknown indicates the hook kind could not be inferred
	// from the script path and was not explicitly configured.
	ErrScriptTypeUnknown error = errors.New(
		"unable to determine hook kind. " +
			"Ensure 'kind' or 'shell' is set in your hook configuration, " +
			"or use a file with a recognized extension " +
			"(.sh, .ps1, .py, .js, .ts, .cs)",
	)
	// ErrRunRequired indicates the hook configuration is missing the mandatory 'run' field.
	ErrRunRequired error = errors.New(
		"'run' is required for every hook configuration. " +
			"Set 'run' to an inline script or a relative file path",
	)
	// ErrUnsupportedScriptType indicates the script file has an extension
	// that is not recognized and no explicit kind or shell was set.
	ErrUnsupportedScriptType error = errors.New(
		"script type is not valid. " +
			"Supported extensions: .sh, .ps1, .py, .js, .ts, .cs. " +
			"Alternatively, set 'kind' (e.g. kind: python) " +
			"or 'shell' (e.g. shell: sh)",
	)
)
View Source
var (
	ErrInvalidEvent = errors.New("invalid event name for the current type")
)

Functions

func HooksConfigSignature added in v1.23.15

func HooksConfigSignature(hooks map[string][]*HookConfig) string

HooksConfigSignature returns a stable signature for a set of hook configurations. The signature ignores runtime-only state and changes whenever the effective hook config changes.

Types

type Event

type Event string

type EventDispatcher

type EventDispatcher[T any] struct {
	// contains filtered or unexported fields
}

func NewEventDispatcher

func NewEventDispatcher[T any](validEventNames ...Event) *EventDispatcher[T]

func (*EventDispatcher[T]) AddHandler

func (ed *EventDispatcher[T]) AddHandler(ctx context.Context, name Event, handler EventHandlerFn[T]) error

AddHandler adds an event handler for the specified event name. The handler is automatically removed when ctx is cancelled.

func (*EventDispatcher[T]) Invoke

func (ed *EventDispatcher[T]) Invoke(ctx context.Context, name Event, eventArgs T, action InvokeFn) error

Invokes an action and raises an event before and after the action

func (*EventDispatcher[T]) RaiseEvent

func (ed *EventDispatcher[T]) RaiseEvent(ctx context.Context, name Event, eventArgs T) error

Raises the specified event and calls any registered event handlers

type EventHandlerFn

type EventHandlerFn[T any] func(ctx context.Context, args T) error

type HookConfig

type HookConfig struct {

	// Internal name of the hook running for a given command
	Name string `yaml:",omitempty"`
	// Kind specifies the executor type of the hook script.
	// Allowed values: "sh", "pwsh", "js", "ts", "python", "dotnet".
	// When empty, the kind is auto-detected from the file extension
	// of the run path (e.g. .py → python, .ps1 → pwsh). If Kind
	// and Shell are both empty and run references a file,
	// the extension is used. For inline scripts, Kind or Shell
	// must be set explicitly.
	Kind language.HookKind `yaml:"kind,omitempty" json:"kind,omitempty"`
	// Shell is a deprecated alias for Kind. When set in YAML
	// (shell: sh) it is mapped to Kind during validate().
	// Retained for backwards compatibility with legacy configs.
	Shell string `yaml:"shell,omitempty" json:"-"`
	// Dir specifies the working directory for hook execution,
	// used as the project context for dependency installation and builds.
	// When empty, defaults to the directory containing the script
	// referenced by the run field. Only set this when the project root
	// differs from the script's directory.
	Dir string `yaml:"dir,omitempty" json:"dir,omitempty"`
	// The inline script to execute or path to existing file
	Run string `yaml:"run,omitempty"`
	// When set to true will not halt command execution even when a script error occurs.
	ContinueOnError bool `yaml:"continueOnError,omitempty"`
	// When set to true will bind the stdin, stdout & stderr to the running console
	Interactive bool `yaml:"interactive,omitempty"`
	// When running on windows use this override config
	Windows *HookConfig `yaml:"windows,omitempty"`
	// When running on linux/macos use this override config
	Posix *HookConfig `yaml:"posix,omitempty"`
	// Environment variables in this list are added to the hook script and if the value is a akvs:// reference
	// it will be resolved to the secret value
	Secrets map[string]string `yaml:"secrets,omitempty"`
	// contains filtered or unexported fields
}

HookConfig defines the configuration for a single hook in azure.yaml. Hooks are lifecycle scripts that run before or after azd commands. Every hook is executed through a tools.HookExecutor resolved via IoC based on the hook's Kind — including Bash, PowerShell, Python, and future executor types (JS, TS, DotNet).

func (*HookConfig) IsPowerShellHook

func (hc *HookConfig) IsPowerShellHook() bool

IsPowerShellHook determines if a hook configuration uses PowerShell. It checks the resolved Kind first, then falls back to the raw Shell field and file extension for hooks that have not yet been validated.

func (*HookConfig) IsUsingDefaultShell

func (hc *HookConfig) IsUsingDefaultShell() bool

IsUsingDefaultShell returns true if the hook is using the OS default shell because no shell was explicitly configured

type HookFilterPredicateFn

type HookFilterPredicateFn func(scriptName string, hookConfig *HookConfig) bool

type HookPlatformType

type HookPlatformType string

HookPlatformType identifies the operating system platform for platform-specific hook overrides.

type HookType

type HookType string

HookType represents the execution timing of a hook relative to the associated command. Supported values are 'pre' and 'post'.

func InferHookType

func InferHookType(name string) (HookType, string)

InferHookType extracts the hook timing prefix ("pre" or "post") from a hook name and returns the remaining command name. For example, "preprovision" → (HookTypePre, "provision").

type HookValidationResult

type HookValidationResult struct {
	Warnings []HookWarning
}

HookValidationResult contains warnings found during hook validation

type HookWarning

type HookWarning struct {
	Message    string
	Suggestion string
	URL        string
}

HookWarning represents a validation warning for hooks

type HooksConfig added in v1.23.14

type HooksConfig map[string][]*HookConfig

HooksConfig is an alias for map of hook names to slices of hook configurations. It supports unmarshalling both legacy single-hook and newer multi-hook formats.

func (HooksConfig) MarshalYAML added in v1.23.14

func (ch HooksConfig) MarshalYAML() (any, error)

MarshalYAML marshals hook configuration to YAML, supporting both single-hook configuration and multiple-hooks configuration.

func (*HooksConfig) UnmarshalYAML added in v1.23.14

func (ch *HooksConfig) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML converts hook configuration from YAML, supporting both single-hook configuration and multiple-hooks configuration.

Each hook entry is independently parsed as either a single HookConfig (mapping node) or a list of HookConfigs (sequence node), allowing mixed formats within the same hooks: block.

type HooksManager

type HooksManager struct {
	// contains filtered or unexported fields
}

HooksManager enables support to invoke lifecycle hooks before & after commands. Hooks can be invoked at the project or service level.

func NewHooksManager

func NewHooksManager(
	cwd string,
	commandRunner exec.CommandRunner,
) *HooksManager

NewHooks creates a new instance of CommandHooks When `cwd` is empty defaults to current shell working directory

func (*HooksManager) GetAll

func (h *HooksManager) GetAll(hooks map[string][]*HookConfig) ([]*HookConfig, error)

Gets an array of all hook configurations Will return an error if any configuration errors are found

func (*HooksManager) GetByParams

func (h *HooksManager) GetByParams(
	hooks map[string][]*HookConfig,
	prefix HookType,
	commands ...string,
) ([]*HookConfig, error)

Gets an array of hook configurations matching the specified hook type and commands Will return an error if any configuration errors are found

func (*HooksManager) ValidateHooks

func (h *HooksManager) ValidateHooks(ctx context.Context, allHooks map[string][]*HookConfig) *HookValidationResult

ValidateHooks validates hook configurations and returns any warnings

func (*HooksManager) ValidateRuntimesErr added in v1.23.15

func (h *HooksManager) ValidateRuntimesErr(
	ctx context.Context,
	allHooks map[string][]*HookConfig,
) error

ValidateRuntimesErr is a convenience wrapper around ValidateHooks that returns an errorhandler.ErrorWithSuggestion when any required runtime is missing. Callers that need a hard early failure (e.g. before starting a long deployment) should use this instead of inspecting warnings manually.

type HooksRunner

type HooksRunner struct {
	// contains filtered or unexported fields
}

HooksRunner enables support to invoke lifecycle hooks before & after commands. Hooks can be invoked at the project or service level.

func NewHooksRunner

func NewHooksRunner(
	hooksManager *HooksManager,
	commandRunner exec.CommandRunner,
	envManager environment.Manager,
	console input.Console,
	cwd string,
	hooks map[string][]*HookConfig,
	env *environment.Environment,
	serviceLocator ioc.ServiceLocator,
) *HooksRunner

NewHooks creates a new instance of CommandHooks When `cwd` is empty defaults to current shell working directory

func (*HooksRunner) Invoke

func (h *HooksRunner) Invoke(ctx context.Context, commands []string, actionFn InvokeFn) error

Invokes an action run runs any registered pre or post script hooks for the specified command.

func (*HooksRunner) RunHooks

func (h *HooksRunner) RunHooks(
	ctx context.Context,
	hookType HookType,
	options *tools.ExecutionContext,
	commands ...string,
) error

Invokes any registered script hooks for the specified hook type and command.

type InvokeFn

type InvokeFn func() error

Generic action function that may return an error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL