procedure

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package procedure runs procedures from data: ordered steps that invoke toolchain tools over variables, capture their output, branch and loop on CEL expressions, ask for confirmation, call other procedures and hand the residue to registered Go steps. A dry run reports every mutating step's command instead of running it.

Index

Constants

View Source
const (
	// VarOS is the operating system the procedure runs on (runtime.GOOS: "linux",
	// "darwin", "windows"); an input of that name overrides it.
	VarOS = "os"

	// VarArch is the processor architecture (runtime.GOARCH: "amd64", "arm64"); an
	// input of that name overrides it.
	VarArch = "arch"

	// VarFailed is true when a step failed or errored.
	VarFailed = "failed"

	// VarCanceled is true when the run's context was cancelled.
	VarCanceled = "canceled"
)

The variables every procedure sees beyond its inputs: the platform it runs on, and, for its Finally steps, the run's outcome.

View Source
const DefaultFinallyTimeout = 30 * time.Second

DefaultFinallyTimeout bounds a procedure's Finally steps when it sets no FinallyTimeout: long enough for a container teardown, short enough that an interrupted run still exits.

Variables

This section is empty.

Functions

func NewFromConfig

func NewFromConfig(cfg Config, deps Deps) (interfaces.ProcedureRunner, error)

NewFromConfig validates and compiles cfg's procedures. A duplicate name, a step that does not run exactly one thing, an unknown tool, step or called procedure, a bad capture mode or a CEL expression that does not compile is CodeInvalidInput naming the procedure and step; the Finally steps are checked the same way. Building does no I/O.

Types

type Config

type Config struct {
	// Procedures are the procedures, by unique name.
	Procedures []types.Procedure
}

Config holds the procedures.

type Deps

type Deps struct {
	// Runner runs the tools and checks they are installed.
	Runner interfaces.CommandRunner

	// Tools resolves a step's tool name to its spec; false means the toolchain does not
	// know the tool.
	Tools func(name string) (interfaces.ToolSpec, bool)

	// Steps are the registered Go steps, by the name Step fields use.
	Steps map[string]StepFunc

	// Prompter asks Confirm questions; nil refuses every confirmation not answered by
	// RunOptions.Yes.
	Prompter interfaces.Prompter

	// Root is the working-tree root a step's Cwd is relative to.
	Root string
}

Deps carries what the procedures run against.

type StepFunc

type StepFunc func(
	ctx context.Context,
	vars Vars,
	opts types.RunOptions,
) (types.StepResults, Vars, error)

StepFunc is a registered Go step: it reads the variables and returns its results and the variables it sets.

type Vars

type Vars map[string]any

Vars are a procedure run's variables.

func (Vars) Bool added in v0.0.20

func (v Vars) Bool(key string) bool

Bool returns key's boolean value; a missing or non-boolean value is false.

func (Vars) Int added in v0.0.20

func (v Vars) Int(key string) int

Int returns key's integer value — an int, the int64 a capture stores or the float64 JSON decodes to; a missing or other value is 0.

func (Vars) Strings added in v0.0.20

func (v Vars) Strings(key string) []string

Strings returns key's string list, accepting the JSON-decoded form a tool call sends (a list of any); a missing or other value is nil.

func (Vars) Text added in v0.0.20

func (v Vars) Text(key string) string

Text returns key's string value; a missing or non-string value is "".

Jump to

Keyboard shortcuts

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