Documentation
¶
Overview ¶
Package workflow provides a declarative workflow engine for orchestrating multi-step chain operations. Workflows are defined as YAML files with typed steps (tx, query, wait, prompt, provider, output, shell, check).
Built-in workflows (deploy, update, close) ship as embedded defaults. Users can override them globally or per-context.
Index ¶
- func EvalCondition(condition string, data json.RawMessage, state *RunState) (bool, error)
- func ExtractOutputs(outputDefs map[string]string, raw json.RawMessage, state *RunState) (map[string]any, error)
- func ParseList(data string) ([]map[string]any, error)
- func ResolveParams(params map[string]string, state *RunState) (map[string]string, error)
- func ResolveTemplate(tmpl string, state *RunState) (string, error)
- type ActionLogAdapter
- type DisplayDef
- type Engine
- type ErrorAction
- type Loader
- type Logger
- type ParamDef
- type ParamType
- type RetryDef
- type RunState
- type StepDef
- type StepExecutor
- type StepRegistry
- type StepResult
- type StepType
- type WorkflowDef
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EvalCondition ¶
EvalCondition evaluates a condition expression against the run state. Returns true if the condition is met. The condition is a Go template that should render to "true" or a non-empty, non-"false" string.
func ExtractOutputs ¶
func ExtractOutputs(outputDefs map[string]string, raw json.RawMessage, state *RunState) (map[string]any, error)
ExtractOutputs extracts named outputs from a raw JSON result using template expressions. Each output entry maps a name to a template that extracts a value from the result.
func ParseList ¶
ParseList attempts to parse a string as a JSON array of objects. If the input is not JSON, returns nil.
func ResolveParams ¶
ResolveParams resolves all template values in a params map.
Types ¶
type ActionLogAdapter ¶
type ActionLogAdapter struct {
// contains filtered or unexported fields
}
ActionLogAdapter implements Logger by writing one type=workflow entry per completed step to the per-context action log (SPEC §5.6). A nil adapter or nil underlying logger is a no-op, so wiring is always safe.
func NewActionLogAdapter ¶
func NewActionLogAdapter(l *actionlog.Logger, workflow string) *ActionLogAdapter
NewActionLogAdapter creates an adapter that records steps of the named workflow to l. Returns nil when l is nil, which the engine treats as "no logging".
func (*ActionLogAdapter) LogStep ¶
func (a *ActionLogAdapter) LogStep(workflowID string, stepIndex int, result *StepResult)
LogStep records a completed workflow step. Logging is best-effort and never interrupts workflow execution.
type DisplayDef ¶
type DisplayDef struct {
Columns []string `yaml:"columns,omitempty" json:"columns,omitempty"`
}
DisplayDef defines how data is displayed in a prompt step.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine executes workflow definitions step by step.
func NewEngine ¶
func NewEngine(registry StepRegistry, logger Logger) *Engine
NewEngine creates a workflow engine with the given step registry and logger.
type ErrorAction ¶
type ErrorAction string
ErrorAction defines what happens when a step fails.
const ( OnErrorAbort ErrorAction = "abort" // Stop the workflow OnErrorContinue ErrorAction = "continue" // Log the error and proceed OnErrorSkip ErrorAction = "skip" // Skip this step silently )
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader resolves and loads workflow definitions from the filesystem and embedded defaults.
Resolution order:
- Per-context: <home>/contexts/<ctx>/workflows/<name>.yaml
- Global user: <home>/workflows/<name>.yaml
- Embedded built-in defaults
type Logger ¶
type Logger interface {
LogStep(workflowID string, stepIndex int, result *StepResult)
}
Logger is called after each step completes. The workflow engine uses this to write entries to the action log. Nil logger means no logging.
type ParamDef ¶
type ParamDef struct {
Type ParamType `yaml:"type" json:"type"`
Required bool `yaml:"required,omitempty" json:"required,omitempty"`
Default string `yaml:"default,omitempty" json:"default,omitempty"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
}
ParamDef defines a workflow input parameter. CLI flags are auto-generated from these definitions.
type RetryDef ¶
type RetryDef struct {
Max int `yaml:"max,omitempty" json:"max,omitempty"`
Delay string `yaml:"delay,omitempty" json:"delay,omitempty"` // duration string
}
RetryDef defines retry behavior for a step.
type RunState ¶
type RunState struct {
WorkflowID string `json:"workflow_id"`
Workflow string `json:"workflow"`
Account string `json:"account"`
Params map[string]any `json:"params"`
Steps map[string]*StepResult `json:"steps"`
StepOrder []string `json:"-"` // ordered step names for iteration
}
RunState holds the accumulated state of a workflow execution. It is passed through steps and provides variable resolution context.
func NewRunState ¶
NewRunState creates a fresh run state for a workflow execution.
func (*RunState) SetStepResult ¶
func (rs *RunState) SetStepResult(name string, result *StepResult)
SetStepResult records a step result in the run state.
func (*RunState) StepOutput ¶
StepOutput returns a named output value from a completed step. Returns nil if the step or output key does not exist.
type StepDef ¶
type StepDef struct {
Name string `yaml:"name" json:"name"`
Type StepType `yaml:"type" json:"type"`
// tx step fields
Msg string `yaml:"msg,omitempty" json:"msg,omitempty"` // message type, e.g. "deployment.MsgCreateDeployment"
// query / wait step fields
Query string `yaml:"query,omitempty" json:"query,omitempty"` // query path, e.g. "market.bids"
// wait step fields
Timeout string `yaml:"timeout,omitempty" json:"timeout,omitempty"` // duration template
Until string `yaml:"until,omitempty" json:"until,omitempty"` // condition expression template
// prompt step fields
Mode string `yaml:"mode,omitempty" json:"mode,omitempty"` // "interactive", "cheapest", "provider=<addr>"
Data string `yaml:"data,omitempty" json:"data,omitempty"` // template resolving to the data to prompt over
Display DisplayDef `yaml:"display,omitempty" json:"display,omitempty"` // display configuration
// provider step fields
Action string `yaml:"action,omitempty" json:"action,omitempty"` // e.g. "send-manifest", "lease-status"
// shell step fields
Command string `yaml:"command,omitempty" json:"command,omitempty"` // shell command template
// check step fields
Condition string `yaml:"condition,omitempty" json:"condition,omitempty"` // condition expression template
// output step fields
Template string `yaml:"template,omitempty" json:"template,omitempty"` // Go template for output
// Common fields
Params map[string]string `yaml:"params,omitempty" json:"params,omitempty"` // template-valued parameters
Output map[string]string `yaml:"output,omitempty" json:"output,omitempty"` // named outputs extracted from result
OnError ErrorAction `yaml:"on-error,omitempty" json:"on_error,omitempty"` // abort, continue, skip
Retry *RetryDef `yaml:"retry,omitempty" json:"retry,omitempty"` // retry configuration
OnFail ErrorAction `yaml:"on-fail,omitempty" json:"on_fail,omitempty"` // for check steps: skip or abort
}
StepDef defines a single step in a workflow.
type StepExecutor ¶
type StepExecutor interface {
Type() StepType
Execute(ctx context.Context, step StepDef, state *RunState) (*StepResult, error)
}
StepExecutor is the interface step implementations satisfy. Defined here to avoid a circular import with the steps package.
type StepRegistry ¶
type StepRegistry interface {
Get(t StepType) (StepExecutor, error)
}
StepRegistry looks up executors by step type.
type StepResult ¶
type StepResult struct {
Name string `json:"name"`
Type StepType `json:"type"`
Status string `json:"status"` // "success", "failed", "skipped"
Output map[string]any `json:"output,omitempty"`
RawResult json.RawMessage `json:"raw_result,omitempty"`
Error string `json:"error,omitempty"`
Duration time.Duration `json:"duration"`
TxHash string `json:"tx_hash,omitempty"`
Height int64 `json:"height,omitempty"`
}
StepResult holds the outcome of executing a single step.
type StepType ¶
type StepType string
StepType classifies what a workflow step does.
const ( StepTx StepType = "tx" // Broadcast a transaction StepQuery StepType = "query" // Execute a chain query StepWait StepType = "wait" // Poll a query until a condition is met StepPrompt StepType = "prompt" // Interactive user input StepProvider StepType = "provider" // Provider gateway call StepOutput StepType = "output" // Display formatted output StepShell StepType = "shell" // Run a shell command StepCheck StepType = "check" // Assert a condition )
type WorkflowDef ¶
type WorkflowDef struct {
Name string `yaml:"name" json:"name"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
Version int `yaml:"version,omitempty" json:"version,omitempty"`
Params map[string]ParamDef `yaml:"params,omitempty" json:"params,omitempty"`
Steps []StepDef `yaml:"steps" json:"steps"`
}
WorkflowDef is the top-level workflow definition loaded from YAML.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package adapters implements the narrow client interfaces the workflow engine's step executors depend on (steps.ChainClient and steps.ProviderClient), backed by the real Akash node and provider gateway clients.
|
Package adapters implements the narrow client interfaces the workflow engine's step executors depend on (steps.ChainClient and steps.ProviderClient), backed by the real Akash node and provider gateway clients. |
|
Package builtin provides embedded default workflow definitions.
|
Package builtin provides embedded default workflow definitions. |
|
Package steps defines the StepExecutor interface and a registry of built-in step type implementations for the workflow engine.
|
Package steps defines the StepExecutor interface and a registry of built-in step type implementations for the workflow engine. |