Documentation
¶
Index ¶
- func CreateInlineTempScript(hookName, ext, content string) (string, error)
- func EnsureInstalled(ctx context.Context, tools ...ExternalTool) error
- func ExecuteCommand(ctx context.Context, commandRunner exec.CommandRunner, cmd string, ...) (string, error)
- func ExtractVersion(cliOutput string) (semver.Version, error)
- func WithInstalledCheckCache(ctx context.Context) context.Context
- type ErrSemver
- type ExecutionContext
- type ExternalTool
- type HookExecutor
- type MissingToolErrors
- type VersionInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateInlineTempScript ¶ added in v1.23.15
CreateInlineTempScript creates a temp file for an inline hook script with executable permissions. The caller is responsible for cleaning up the returned file.
func EnsureInstalled ¶
func EnsureInstalled(ctx context.Context, tools ...ExternalTool) error
EnsureInstalled checks that all tools are installed, returning an error if one or more tools are not.
func ExecuteCommand ¶
func ExtractVersion ¶
ExtractVersion extracts a major.minor.patch version number from a typical CLI version flag output.
minor and patch version numbers are both optional, treated as 0 if not found.
Types ¶
type ErrSemver ¶
type ErrSemver struct {
ToolName string
VersionInfo VersionInfo
}
type ExecutionContext ¶ added in v1.23.15
type ExecutionContext struct {
// Cwd is the working directory for execution.
Cwd string
// EnvVars is the merged environment for the process, including
// resolved secrets and the azd environment.
EnvVars []string
// BoundaryDir is the project or service root directory.
// Executors may walk upward from the script to BoundaryDir
// to discover dependency files (requirements.txt, package.json).
BoundaryDir string
// Interactive controls whether stdin is attached.
Interactive *bool
// StdOut overrides the default stdout for the process.
StdOut io.Writer
// InlineScript contains the raw script content for inline hooks.
// When set, the executor creates a temp file in Prepare() with
// the appropriate extension and content wrapper (e.g., shebang
// for bash). When empty, scriptPath is used directly as a file
// path.
InlineScript string
// HookName is the descriptive name of the hook (e.g.,
// "preprovision"). Used by executors for temp file naming to
// aid debuggability.
HookName string
}
ExecutionContext provides the per-invocation execution environment for a hook. The HooksRunner constructs this from the validated HookConfig, resolving secrets, merging directories, and building the environment.
type ExternalTool ¶
type ExternalTool interface {
CheckInstalled(ctx context.Context) error
InstallUrl() string
Name() string
}
func Unique ¶
func Unique(tools []ExternalTool) []ExternalTool
Unique filters a slice of tools such that a tool with a given name only appears once.
type HookExecutor ¶ added in v1.23.15
type HookExecutor interface {
// Prepare performs pre-execution setup such as runtime validation,
// virtual environment creation, dependency installation, or temp
// file creation for inline scripts.
Prepare(ctx context.Context, scriptPath string, execCtx ExecutionContext) error
// Execute runs the hook at the given path.
Execute(ctx context.Context, scriptPath string, execCtx ExecutionContext) (exec.RunResult, error)
// Cleanup removes any temporary resources created during Prepare.
// Called by the hooks runner after Execute completes, regardless
// of success or failure. Implementations must be safe to call
// even when Prepare was not called or created no resources.
Cleanup(ctx context.Context) error
}
HookExecutor is the unified interface for all hook execution. Every executor follows a three-phase lifecycle:
- Prepare — validate prerequisites, resolve tools, create temp files
- Execute — run the hook
- Cleanup — remove temporary resources created during Prepare
type MissingToolErrors ¶
MissingToolErrors wraps a set of errors discovered when probing for tools and implements the Error interface to pretty print the underlying errors. We use this instead of the existing `multierr` package we use elsewhere, because we want to control the error string (the default one produced by multierr is not as nice as what we do here).
func (*MissingToolErrors) Error ¶
func (m *MissingToolErrors) Error() string
type VersionInfo ¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package language provides project file discovery and dependency management for multi-language hook scripts.
|
Package language provides project file discovery and dependency management for multi-language hook scripts. |