engine

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package engine orchestrates the execution of a keepup Flow. Groups are scheduled either as ordered waves (step mode) or topologically from the implicit data DAG (dag mode); both share the same Runner, OutputStore, Expander, and Logger interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

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

Engine binds a parsed Config to a set of pluggable collaborators.

func New

func New(cfg *config.Config, opts ...Option) *Engine

New constructs an Engine. The config pointer is held by reference; do not mutate it for the lifetime of the Engine.

func (*Engine) Outputs

func (e *Engine) Outputs() OutputStore

Outputs returns the captured outputs (populated after RunFlow completes).

func (*Engine) RunFlow added in v1.6.0

func (e *Engine) RunFlow(ctx context.Context, flowName string) error

RunFlow executes the named Flow, honoring ctx cancellation.

type Expander

type Expander interface {
	Expand(template string, outputs map[string]string) string
}

Expander substitutes "{{ output.<name> }}" placeholders in templated strings.

type MemoryOutputStore

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

MemoryOutputStore is the default in-memory implementation.

func NewMemoryOutputStore

func NewMemoryOutputStore() *MemoryOutputStore

NewMemoryOutputStore returns an empty store.

func (*MemoryOutputStore) Get

func (s *MemoryOutputStore) Get(name string) (string, bool)

func (*MemoryOutputStore) Set

func (s *MemoryOutputStore) Set(name, value string)

func (*MemoryOutputStore) Snapshot

func (s *MemoryOutputStore) Snapshot() map[string]string

Snapshot returns a copy of the current state for safe iteration.

type Option

type Option func(*Engine)

Option configures an Engine.

func WithCache added in v1.7.0

func WithCache(s cache.Store) Option

WithCache overrides the default file-backed cache store.

func WithDryRun

func WithDryRun(dry bool) Option

WithDryRun forces dry-run mode regardless of the config flag.

func WithExpander

func WithExpander(x Expander) Option

WithExpander overrides the default TemplateExpander.

func WithLogger

func WithLogger(l logger.Logger) Option

WithLogger overrides the default no-op Logger.

func WithNoCache added in v1.7.0

func WithNoCache(disable bool) Option

WithNoCache disables cache reads/writes for this run.

func WithOutputStore

func WithOutputStore(s OutputStore) Option

WithOutputStore overrides the default in-memory OutputStore.

func WithProber added in v1.7.0

func WithProber(p Prober) Option

WithProber overrides the default ShellProber used for skip-if/require.

func WithRunner

func WithRunner(r Runner) Option

WithRunner overrides the default ShellRunner.

type OutputStore

type OutputStore interface {
	Get(name string) (string, bool)
	Set(name, value string)
	Snapshot() map[string]string
}

OutputStore is a goroutine-safe key/value store of group outputs.

type Prober added in v1.7.0

type Prober interface {
	Probe(ctx context.Context, script string, env map[string]string) error
}

Prober evaluates a gating predicate. A nil error means the predicate succeeded (exit code 0); a non-nil error means it failed.

Predicates are short shell snippets (e.g. "test -f bin/app"), so they always run through a shell.

type Runner

type Runner interface {
	Run(ctx context.Context, g *config.Group, params []string, globalEnv map[string]string) (string, error)
}

Runner executes a single group and returns its captured stdout/stderr as a string.

type ShellProber added in v1.7.0

type ShellProber struct{}

ShellProber runs predicates through the platform shell. Output is discarded; only the exit status matters.

func (ShellProber) Probe added in v1.7.0

func (ShellProber) Probe(ctx context.Context, script string, env map[string]string) error

Probe runs script via the platform shell and returns its exit status as an error (nil on success).

type ShellRunner

type ShellRunner struct {
	// Stdout and Stderr are forwarded for live output; outputs are also captured
	// into the returned string. If nil, os.Stdout/os.Stderr are used.
	Stdout io.Writer
	Stderr io.Writer
}

ShellRunner executes a group via os/exec, optionally through a system shell.

By default (group.Shell == false) it spawns Command directly with Params as argv — no shell interpretation, no injection surface. When group.Shell is true the runner concatenates command+params into a single string and pipes it through the user's preferred shell; that mode is opt-in.

func NewShellRunner

func NewShellRunner() *ShellRunner

NewShellRunner returns a runner wired to the process stdio.

func (*ShellRunner) Run

func (r *ShellRunner) Run(ctx context.Context, g *config.Group, params []string, globalEnv map[string]string) (string, error)

Run honors ctx for cancellation. The returned string is the combined stdout+stderr capture of the child process.

The command and arguments come from user-supplied configuration; that is the point of this tool. gosec G204 is suppressed for the exec call.

type TemplateExpander

type TemplateExpander struct{}

TemplateExpander is the default placeholder substitution.

func (TemplateExpander) Expand

func (TemplateExpander) Expand(template string, outputs map[string]string) string

Expand replaces all "{{ output.<key> }}" occurrences in template with the trimmed value for that key, ignoring placeholders without a matching entry.

Jump to

Keyboard shortcuts

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