engine

package
v1.41.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 47 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package engine loads a workflow and runs it: the model of a workflow, the loader that reads it from its files, and the engine that runs its jobs.

Index

Constants

View Source
const (
	// OutputModeAuto picks spinner on an interactive terminal and stream
	// otherwise.
	OutputModeAuto = display.ModeAuto
	// OutputModeSpinner shows a spinner while running and prints the whole
	// report once every job has finished.
	OutputModeSpinner = display.ModeSpinner
	// OutputModeStream prints each job block as soon as it is final and logs
	// step progress to stderr while jobs are still running.
	OutputModeStream = display.ModeStream
)

The modes a report can be written in.

View Source
const (
	// ExitOK means every job succeeded.
	ExitOK = 0
	// ExitTestFailed means a test did not hold: it evaluated to false, could
	// not be evaluated, or did not evaluate to a boolean; or a request or a
	// response broke the contract an action checked it against.
	ExitTestFailed = 1
	// ExitConfigError means the workflow or the command line was wrong, a
	// step asked for what the guard of the run does not allow, or a report
	// file could not be written, so the run could not do what it was asked
	// to.
	ExitConfigError = 2
	// ExitActionError means an action returned an error, such as a refused
	// connection or a timeout, so a test could not be checked at all.
	ExitActionError = 3
)

Exit codes of a probe run. They tell apart what a caller such as CI or cron has to do about a failure: a failed test points at the system under test, a configuration error at the workflow or the command line, and an action error at the environment, such as a target that cannot be reached.

View Source
const (
	// DefaultMaxRepeatCount is the default upper limit for repeat count
	DefaultMaxRepeatCount = 10000
	// DefaultMaxAttempts is the default upper limit for max attempts
	DefaultMaxAttempts = 10000
	// EnvMaxRepeatCount is the environment variable name for overriding max repeat count
	EnvMaxRepeatCount = "PROBE_MAX_REPEAT_COUNT"
	// EnvMaxAttempts is the environment variable name for overriding max attempts
	EnvMaxAttempts = "PROBE_MAX_ATTEMPTS"
)
View Source
const (
	// DefaultStepTimeout is the default timeout for action execution
	DefaultStepTimeout = 5 * time.Minute
)
View Source
const (
	RunFieldRT = "rt"
)

The fields of a step that the tests of a repeated job read under steps, as repeatRuns and baselineRuns gather them and probe check knows them.

View Source
const WorkflowDefaults = -1

WorkflowDefaults is the Job of an AliasProblem in the defaults of the workflow, which belong to no job.

Variables

View Source
var (
	RepeatRunFields   = []string{runFieldRuns, runFieldSuccess, runFieldFailure, runFieldSkipped, runFieldSuccessRate, RunFieldRT}
	BaselineRunFields = []string{runFieldRuns, runFieldSuccess, runFieldSuccessRate, RunFieldRT}
	RepeatRTFields    = []string{rtFieldMin, rtFieldMean, rtFieldP50, rtFieldP90, rtFieldP95, rtFieldP99, rtFieldMax}
)

The fields of a step that the tests of a repeated job read under steps, those that the test against the run compared to reads under baseline.steps, and those of their rt, in the order probe check lists them in.

View Source
var ReadFile = os.ReadFile

ReadFile reads a file of the workflow, one given or one it includes. It is os.ReadFile but in the tests that count what is read.

Functions

func AddToSchedule

func AddToSchedule(s *schedule.Scheduler, job *Job) error

AddToSchedule adds job to s by what s waits on: its ID, its needs and whether it always runs. The jobs of a workflow are given their IDs before they are added, by assignJobIDs.

func AddedResFields

func AddedResFields(res []string) []string

AddedResFields returns res, the fields of res an action declares it returns, with those ReadActionResult adds to them: rawbody to one with a body, which a JSON body is kept as, and json to one with stdout, which stdout of JSON is read as. A field is added only to a res that has the field it comes from, so these are all a res can have.

func EachEmbeddedStep

func EachEmbeddedStep(st *Step, seen map[string]bool, visit func(file string, index int, st *Step))

EachEmbeddedStep calls visit for each step of the job file st embeds, when st is a step of the embedded action, and of the job files those steps embed in turn, with the path of the file as it is written and the position of the step in it. seen holds the files read, each of which is read once, so that job files that embed one another end.

Only what can be told before a run is read: a path that is a template is not followed, and nor is a file that cannot be read.

func FirstLine

func FirstLine(s string) string

FirstLine returns the first line of s, trimmed.

func IsInclude

func IsInclude(n ast.Node) bool

IsInclude reports whether n, an entry of steps or of jobs, includes a file.

func JobWhere

func JobWhere(jobs []Job, i int) string

JobWhere names the job at index i of jobs.

func LastKey

func LastKey(n ast.Node, key string) *ast.MappingValueNode

LastKey returns the last pair of the mapping n whose key is key, which is the one decoded; nil when there is none.

func ListNames

func ListNames(names []string) string

ListNames lists names as a, b and c.

func LoadSource

func LoadSource(path string, actions, replaceable []string, src *Source) (*Workflow, []AliasProblem, []Problem, error)

LoadSource loads src, the files of the workflow at path as read, as Load would with actions and replaceable, as Config has them, and returns the workflow with what load returns.

func NeededJobs

func NeededJobs(jobs []Job, byID map[string]int, from ...int) map[int]bool

NeededJobs returns the jobs of jobs that those at from need, directly or through the jobs they need, by their indices, given the index of each job by its id. One of from is among them only when a job it needs needs it in turn. A need that is no job's id is left out.

func ReadResTypes

func ReadResTypes(types map[string]string) map[string]string

ReadResTypes returns types, the kinds of the fields of res an action declares, as the fields are read once ReadActionResult has read them: a body, which is read as the value it holds when it holds JSON, is of any kind, and rawbody, which keeps such a body as text, is a string, as the body is. json, which stdout of JSON is read as, is of any kind.

func RepeatReads

func RepeatReads(tests ...string) map[string]bool

RepeatReads returns the ids of the steps that tests, the tests of a repeated job, read under steps; nil when they read none, or do not parse.

func Resolve

func Resolve(body, n ast.Node) ast.Node

Resolve returns n, or the node it names when it is an alias of an anchor of body.

func StepWhere

func StepWhere(job string, i int, st *Step) string

StepWhere names st, the step at index i of the job job names.

func StepsOf

func StepsOf(body, job ast.Node) *ast.MappingValueNode

StepsOf returns the pair of job, an entry of jobs, that gives its steps: its own, or those a merge key gives it, the first of them as the decoder takes them; nil when there is none.

func WorkflowActions

func WorkflowActions(workflow string) (guide.Workflow, error)

WorkflowActions returns the names the workflow gives under actions, and the directory a local path among them is taken from.

Types

type ActionResult

type ActionResult struct {
	// Req is the request the action made, as it tells it.
	Req map[string]any
	// Res is the response, with a JSON body, and a JSON stdout, decoded.
	Res map[string]any
	// RT is the time the action took, or none when it did not tell it as a
	// duration.
	RT ResponseTime
	// Status is the action's exit status: 0 for success.
	Status int
}

ActionResult is what an action returned for a step. An action sends it as a map of req, res, rt and status, as the built-in actions return it, and it is read once, as it comes back, into the parts of the step's context.

func ReadActionResult

func ReadActionResult(m map[string]any) ActionResult

ReadActionResult reads what an action returned for a step.

type ActionRunner

type ActionRunner interface {
	Run(name string, call sdk.Call, opts RunOptions) (result, newState map[string]any, err error)
}

ActionRunner runs the action of a step: the action named name, as the step writes it in uses, with what call tells it about the step and the state the action left in the job. It returns what the action returned and the state it leaves, nil to keep the one there was.

Run is called concurrently, from the steps of the jobs that run at once and of the runs of an async job, and is to return once opts.Context() is done: the step has given up on the action by then, and what Run returns after is not used. The actions that clean up once the run is over are told so by PluginActionRunner alone, so a runner of its own takes part in that only by running the action with PluginActionRunner and opts as it was given them.

type AliasProblem

type AliasProblem struct {
	// Name is the name under actions, or empty when Job is set.
	Name string
	// Job is the index of the job whose defaults are wrong, with Action the
	// key of them that is, or WorkflowDefaults for the defaults of the
	// workflow.
	Job    int
	Action string
	Msg    string
}

AliasProblem is what is wrong with a name the workflow's actions give, or with a use of one.

func (AliasProblem) Error

func (a AliasProblem) Error() string

type Config

type Config struct {
	// Warn is where what is found as the workflow is loaded, and does not
	// keep it from running, is written; nil for nowhere.
	Warn    io.Writer
	Verbose bool
	// Trace, with Verbose, also shows how each action's process is
	// started, called and stopped, and the records an action logs at trace
	// level, for debugging an action.
	Trace  bool
	Timing bool
	// Output selects how the report is delivered while jobs run.
	Output OutputMode
	// Reports lists the report files written once the run has finished.
	Reports []report.Target
	// Baseline is the report of an earlier run, which the reports compare
	// the response times of the repeated steps to; nil for none.
	Baseline *report.Report
	// Guard is what the run allows its actions to do, such as only reading,
	// and only from some hosts. Each step's action is told it, and a step
	// whose action does not keep to it is refused unless it is allowed.
	Guard sdk.Guard
	// Env are environment variables read from files, by name, for the vars
	// of the workflow to read where the environment has none of the name.
	// They are given to the vars alone: Probe reads none of its own
	// settings from them, and the actions do not have them in their
	// environment.
	Env map[string]string
	// Vars are values for the vars of the workflow, by name, given by the
	// person running it. Each is taken as it is, in place of what the
	// workflow writes for the var, and the other vars read it.
	Vars map[string]string
	// Actions are the names of the actions of Probe, which a workflow
	// cannot give to an external action under actions. When it is empty,
	// the names a workflow gives are not checked against them.
	Actions []string
	// Replaceable are those of Actions a workflow can give to an external
	// action under actions, as they are being replaced by one.
	Replaceable []string
	// Jobs narrows the run to the jobs of these ids or names, with the jobs
	// they need and those that always run after them; all jobs when it is
	// empty.
	Jobs []string
	// NeedsNoCheck are the names of the actions whose steps pass without a
	// test, as those of an action that does nothing that could fail: such
	// a step is there for its echo, or to publish what it is given, and is
	// not counted as untested. A step of any other action that nothing
	// checks is. The engine knows no action by itself: the probe command
	// sets this and Actions for the built-in ones.
	NeedsNoCheck []string
	// ActionRunner runs the action of each step. When it is nil, each runs
	// in a process of its own, as PluginActionRunner runs it.
	ActionRunner ActionRunner
}

type ErrorType

type ErrorType string

ErrorType represents different categories of errors

const (
	ErrorTypeExecution     ErrorType = "execution"
	ErrorTypeConfiguration ErrorType = "configuration"
	ErrorTypeFile          ErrorType = "file"
)

type Executor

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

Executor runs a job: once, or as many times as its repeat says, and then records what the runs came to on the job's result.

func NewExecutor

func NewExecutor(job *Job) *Executor

NewExecutor returns an Executor that runs job.

func (*Executor) Run

func (e *Executor) Run(ctx JobContext) bool

Run runs the job and records its result, and reports whether it passed. A job that did not pass is the caller's to fail the workflow for.

type ExitStatus

type ExitStatus int

ExitStatus represents the unified status across all actions

const (
	ExitStatusSuccess ExitStatus = 0 // Action succeeded
	ExitStatusFailure ExitStatus = 1 // Action failed
)

func (ExitStatus) Int

func (e ExitStatus) Int() int

Int returns the ExitStatus as an int for comparison

func (ExitStatus) String

func (e ExitStatus) String() string

String returns the ExitStatus as a string

type IncludeProblem

type IncludeProblem struct {
	Line int
	Msg  string
}

IncludeProblem is what kept an entry from including a file, on a line of the source.

type Interval

type Interval struct {
	time.Duration
}

Interval is a duration written in a workflow, as duration.Parse reads it: a duration string such as "1m30s", or a number of seconds, which may have a fraction. It is used for the interval of a repeat or a retry, the delay before a retry and a step's timeout, and cannot be negative.

func (Interval) MarshalYAML

func (i Interval) MarshalYAML() (any, error)

MarshalYAML implements custom YAML marshaling for Interval

func (*Interval) UnmarshalYAML

func (i *Interval) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements custom YAML unmarshaling for Interval

type Iteration

type Iteration struct {
	// Entries is the list written in the workflow.
	Entries []map[string]any
	// Expr is the template that gives the list, as "{{ outputs.users.rows }}".
	// It is empty when the list is written in the workflow.
	Expr string
}

Iteration is what a step runs once for each entry of, with the entry's keys as vars: a list written in the workflow, or a template that gives one when the step is reached, such as the cases read from a file or the rows an earlier step published.

func (Iteration) MarshalYAML

func (it Iteration) MarshalYAML() (any, error)

MarshalYAML writes the iteration as it is written in a workflow.

func (*Iteration) UnmarshalYAML

func (it *Iteration) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML reads a list of maps as Entries and a string as Expr.

type Job

type Job struct {
	Name  string   `yaml:"name" validate:"required"`
	ID    string   `yaml:"id,omitempty"`
	Needs []string `yaml:"needs,omitempty"`
	// Always runs the job once the jobs it needs are over, whether or not
	// they succeeded, as a job that removes what they made has to.
	Always bool    `yaml:"always,omitempty"`
	Steps  []*Step `yaml:"steps" validate:"required"`
	// FailFast skips the steps after one that failed, as steps that only
	// work on what an earlier one made would fail for its reason.
	FailFast bool    `yaml:"fail_fast,omitempty"`
	Repeat   *Repeat `yaml:"repeat"`
	Defaults any     `yaml:"defaults"`
	SkipIf   string  `yaml:"skipif,omitempty"`
}

func ReadJobFile

func ReadJobFile(path string, names map[string]string) (*Job, error)

ReadJobFile reads the job file at path, as the embedded action runs it: by names, the names the workflow that embeds it gives its external actions, and with the job's defaults applied to its steps. A nil names reads each uses as it is written.

func (*Job) ApplyDefaults

func (j *Job) ApplyDefaults()

ApplyDefaults merges the job's defaults into the with of every step that uses the action they are keyed by. A value the step sets itself wins, and nested objects are merged key by key.

func (*Job) RunStandalone

func (j *Job) RunStandalone(vars map[string]any, printer *Printer, jobID, baseDir string, opts ...StandaloneOption) JobRun

RunStandalone runs the job outside a workflow, as an embedded job is run. A local action is resolved relative to baseDir, the directory of the file the job comes from, or to the working directory when baseDir is empty.

func (*Job) UseActions

func (j *Job) UseActions(names map[string]string) error

UseActions reads the job by names, the names a workflow gives its external actions: a uses or a key of the defaults that is one of them becomes the action it stands for. The embedded action does so for the job it runs, with the names of the workflow that embeds it, before ApplyDefaults.

type JobContext

type JobContext struct {
	Vars map[string]any `expr:"vars"`
	// Outputs are those the run reads and writes (accessible via expressions
	// as "outputs"): the workflow's, or a store of the run's own in front of
	// them for a run that overlaps others.
	Outputs *Outputs `expr:"outputs"`

	Failed bool
	// Current job ID for this context
	CurrentJobID string
	// RepeatCurrent is the index of the run, from 0, warmup runs included.
	RepeatCurrent int
	// contains filtered or unexported fields
}

JobContext is what a run of a job runs with. It is copied for each run, and holds by value only what is the run's own; what the jobs of the workflow share is in runEnv, and what the runs of a repeated job share in jobRepeat, which a copy points to as the context it was copied from does.

func (*JobContext) SetFailed

func (j *JobContext) SetFailed()

SetFailed marks the job context as failed

type JobRun

type JobRun struct {
	// Success is true when every step passed or the job was skipped.
	Success bool
	// Outputs are the outputs the job's steps published.
	Outputs map[string]any
	// Report is the report of the job's steps.
	Report string
	// Err is set when the job could not run as it was written, such as when
	// a step is invalid or an action cannot be resolved. A step that fails
	// leaves it nil and Success false.
	Err error
	// Refused is set when the guard the job ran under refused a step, the
	// first one, so that the step that embeds the job is refused as well
	// rather than failing as a job whose test was false.
	Refused *sdk.Refused
	// Duration is how long the job took.
	Duration time.Duration
}

JobRun is the outcome of a job run on its own with RunStandalone.

type JobState

type JobState struct {
	// Failed is whether a step before it in the run failed, so that a step
	// that shows what helps to find why, such as a log, can be skipped when
	// none did. The skipif of a job reads it as false, as no step has run.
	Failed bool `expr:"failed"`
}

JobState is what a step reads, as job, of the run of its job before it.

type NameTakenError

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

NameTakenError reports an output whose name was taken before it was published, so that outputs.<name> holds something else. It is a warning: the step's value is kept under its id when that can be.

func (*NameTakenError) Error

func (e *NameTakenError) Error() string

type OutputMode

type OutputMode = display.Mode

OutputMode selects how a workflow run delivers its report.

func ParseOutputMode

func ParseOutputMode(s string) (OutputMode, error)

ParseOutputMode converts a user supplied name into an OutputMode.

type Outputs

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

Outputs manages step outputs across the entire workflow

func NewOutputs

func NewOutputs() *Outputs

NewOutputs creates a new Outputs instance

func (*Outputs) GetAll

func (o *Outputs) GetAll() map[string]any

GetAll returns all outputs (safe copy for expression evaluation). A run's own outputs stand in front of its parent's.

func (*Outputs) Set

func (o *Outputs) Set(stepID string, outputs map[string]any) error

Set stores outputs for a step with flat access support

func (*Outputs) SetFlat

func (o *Outputs) SetFlat(owner string, outputs map[string]any) error

SetFlat stores the outputs of a step without an id, which are read by their names alone. owner names the step, the same each time it publishes, for a later step's name to be told from its own.

type PluginActionRunner

type PluginActionRunner struct{}

PluginActionRunner is the ActionRunner a run uses unless it is given another: it runs each action in a process of its own, a built-in one served by the probe executable and an external one by its own.

func (*PluginActionRunner) Run

func (p *PluginActionRunner) Run(name string, call sdk.Call, opts RunOptions) (map[string]any, map[string]any, error)

Run runs the action for a step in a process of its own, telling it about the step, giving it the state it left in the job and returning the state it leaves.

type Printer

type Printer = display.Printer

Printer writes what a run prints: its report, its errors and warnings, and, in verbose mode, what its steps did.

func NewPrinter

func NewPrinter(verbose bool) *Printer

NewPrinter returns a printer that writes to the standard output and error. Its output is colored whatever it is written to when FORCE_COLOR or PROBE_TTY is 1: the CLI sets PROBE_TTY when its standard output is a terminal, for the printer of an embedded job, which runs in the process of an action, whose standard output is not the terminal.

type Probe

type Probe struct {
	FilePath string

	Config Config
	// contains filtered or unexported fields
}

func New

func New(path string, v bool) *Probe

func (*Probe) DagAscii

func (p *Probe) DagAscii() (string, error)

DagAscii returns the ASCII art representation of the workflow job dependencies with steps

func (*Probe) DagMermaid

func (p *Probe) DagMermaid() (string, error)

DagMermaid returns the Mermaid format representation of the workflow job dependencies

func (*Probe) Do

func (p *Probe) Do() error

func (*Probe) ExitStatus

func (p *Probe) ExitStatus() int

func (*Probe) Load

func (p *Probe) Load() error

Load reads the workflow at FilePath, as a run reads it, and refuses it for the first thing that keeps it from running as it is written.

type ProbeError

type ProbeError struct {
	Type      ErrorType
	Operation string
	Message   string
	Cause     error
}

ProbeError is the base error type, telling the operation that failed

func NewConfigurationError

func NewConfigurationError(operation, message string, cause error) *ProbeError

func NewExecutionError

func NewExecutionError(operation, message string, cause error) *ProbeError

func NewFileError

func NewFileError(operation, message string, cause error) *ProbeError

func NewProbeError

func NewProbeError(errorType ErrorType, operation, message string, cause error) *ProbeError

NewProbeError creates a new ProbeError

func (*ProbeError) Error

func (e *ProbeError) Error() string

func (*ProbeError) Is

func (e *ProbeError) Is(target error) bool

func (*ProbeError) Unwrap

func (e *ProbeError) Unwrap() error

type Problem

type Problem struct {
	// Path is the key the problem is at, such as jobs[0].steps[1].test, by
	// which probe check finds its line.
	Path string
	// Where names the job and the step it is in, such as job 0 "Login",
	// step 1; empty when it is in neither.
	Where string
	Err   error
}

Problem is what keeps a job from running as it is written. It is found as the workflow is loaded, so that the run is refused before any job starts, rather than when the job or the step it is in is reached.

func TemplateProblems

func TemplateProblems(path, where, field string, v any) []Problem

TemplateProblems returns the problems of the templates in v, a string or a map or list of them at any depth, keys too, that do not parse.

func (Problem) Error

func (p Problem) Error() string

type Repeat

type Repeat struct {
	Count    int      `yaml:"count" validate:"required,gte=0"`
	Interval Interval `yaml:"interval"`
	Async    bool     `yaml:"async,omitempty"`
	// Warmup is the number of runs before the count, which are run as any
	// other but counted in neither the results nor the times, and do not
	// fail the job.
	Warmup int `yaml:"warmup,omitempty" validate:"gte=0"`
	// Test is checked once every run is over, against the runs of the
	// steps, and decides alone whether the job passed: a run in which a
	// step failed is then counted, and fails nothing by itself.
	Test string `yaml:"test,omitempty"`
	// BaselineTest is checked once every run is over too, against the runs
	// of the steps and those of the run compared to, under baseline. It is
	// checked only when that run has the steps it reads, and then the job
	// passes only when it holds. It leaves how a failed run is taken to Test.
	BaselineTest string `yaml:"baseline_test,omitempty"`
}

Repeat defines the repeat configuration for jobs

func (*Repeat) Runs

func (r *Repeat) Runs() int

Runs returns the number of runs of the job, the warmup runs included.

func (*Repeat) Tests

func (r *Repeat) Tests() []RepeatTest

Tests returns the tests of the job, by their keys under repeat, given or not.

func (*Repeat) Validate

func (r *Repeat) Validate() error

Validate performs custom validation for Repeat

type RepeatTest

type RepeatTest struct {
	Key, Test string
}

RepeatTest is a test of a repeated job, by the key it is written under.

type RepeatTestEnv

type RepeatTestEnv struct {
	Vars     map[string]any `expr:"vars"`
	Steps    map[string]any `expr:"steps"`
	Baseline map[string]any `expr:"baseline"`
}

RepeatTestEnv is what the tests of a repeated job read: the vars of the workflow, and under steps the runs of each step by its id. The test against the run compared to reads that run's steps under baseline too.

type ResponseTime

type ResponseTime struct {
	Duration string  `expr:"duration"`
	Sec      float64 `expr:"sec"`
}

ResponseTime provides response time information for expressions

type RunOptions

type RunOptions struct {
	// Verbose raises the action's log level to debug.
	Verbose bool
	// Trace, with Verbose, raises it to trace, to show how the action's
	// process is started, called and stopped as well.
	Trace bool
	// Quiet silences the action's own log records. It is set for a retry
	// attempt that still has another attempt left: actions have no notion of
	// being retried, so a failure there would otherwise be reported at error
	// level even though the step goes on to succeed.
	Quiet bool
	// Masker hides the workflow's secrets in the action's log records.
	Masker *mask.Masker
	// BaseDir is the directory a local action's path is relative to: the
	// directory of the workflow file. The working directory is used when it
	// is empty.
	BaseDir string
	// contains filtered or unexported fields
}

RunOptions controls how a single action invocation is run and logged.

func (RunOptions) Context

func (o RunOptions) Context() context.Context

Context returns the context the action runs in, which is done once the step gives up on the action, as it does when the step times out. It is never nil: without one, the action runs until it returns.

type Source

type Source struct {
	File  *ast.File
	Files yamlnode.Files

	// Problems are what kept an entry from including a file, by the line it
	// is found on. Such an entry is left out.
	Problems []IncludeProblem
	// contains filtered or unexported fields
}

Source is a workflow as read: the text of the files given, one after another, parsed, with the steps of the file each entry of steps includes in place of the entry. The included files are numbered on past the text, each from a line of its own, so that a line of the source tells the file it is of and the line in it, as a line of the text does.

func NewSource

func NewSource(files []string, data [][]byte, text string) (*Source, error)

NewSource parses text, the files given one after another, whose contents are data, and includes the files the entries of the steps of its jobs name. The error is for a text that does not parse; what keeps an entry from including its file is told in problems.

type StandaloneOption

type StandaloneOption func(*standaloneConfig)

StandaloneOption changes how RunStandalone runs a job.

func WithActionRunner

func WithActionRunner(r ActionRunner) StandaloneOption

WithActionRunner runs the actions of the job's steps with r, as Config.ActionRunner does those of a workflow.

func WithActions

func WithActions(names map[string]string) StandaloneOption

WithActions tells the steps of the job the names a workflow gives its external actions, such as those of the workflow that embeds it, for a job the job itself embeds to be read by. The job's own steps are read by them with UseActions.

func WithBuiltinActions

func WithBuiltinActions(names []string) StandaloneOption

WithBuiltinActions tells the job the names of the actions of Probe, so that a uses that names no action stops the job before any step runs. Without it, such a step fails when it is run.

func WithCleanups

func WithCleanups(c *sdk.Cleanups) StandaloneOption

WithCleanups runs the job as part of a run that cleans up once it is over, such as the run of the step that embeds it: the actions the job would have had clean up when it ended are named in c instead, and what its steps left behind stays for the rest of that run. Without it, or with a nil c, the job cleans up after itself.

func WithGuard

func WithGuard(guard sdk.Guard) StandaloneOption

WithGuard runs the job under guard, such as the guard of the run of the step that embeds it, so that a workflow cannot get round its guard by embedding a job.

func WithNeedsNoCheck

func WithNeedsNoCheck(names []string) StandaloneOption

WithNeedsNoCheck tells the job the names of the actions whose steps pass without a test, as Config.NeedsNoCheck tells a workflow. Without it, a step that nothing checks is counted as untested whatever its action.

func WithRunID

func WithRunID(id string) StandaloneOption

WithRunID runs the job as part of the run id names, such as the run of the step that embeds it, so that its actions are told the same run. Without it the job is a run of its own.

type Step

type Step struct {
	Name      string            `yaml:"name"`
	ID        string            `yaml:"id,omitempty"`
	Uses      string            `yaml:"uses" validate:"required"`
	With      map[string]any    `yaml:"with"`
	Test      string            `yaml:"test"`
	Echo      string            `yaml:"echo"`
	Vars      map[string]any    `yaml:"vars"`
	Iteration Iteration         `yaml:"iteration"`
	Wait      string            `yaml:"wait,omitempty"`
	SkipIf    string            `yaml:"skipif,omitempty"`
	Outputs   map[string]string `yaml:"outputs,omitempty"`
	Retry     *StepRetry        `yaml:"retry,omitempty"`
	Timeout   Interval          `yaml:"timeout,omitempty"`
}

func (*Step) IDAt

func (st *Step) IDAt(pos int) string

IDAt is the id the step, written at pos in its job, is read by: its own, or the one a loaded workflow gives a step without one.

type StepContext

type StepContext struct {
	Vars        map[string]any `expr:"vars"`
	Res         map[string]any `expr:"res"`
	Req         map[string]any `expr:"req"`
	RT          ResponseTime   `expr:"rt"`
	Report      string         `expr:"report"`
	Outputs     map[string]any `expr:"outputs"`
	Status      int            `expr:"status"`
	RepeatIndex int            `expr:"repeat_index"`
	// Notes are those the steps whose results are final left for people;
	// see noteBook.snapshot.
	Notes []any `expr:"notes"`
	// Job is what the step reads of the run of its job so far.
	Job JobState `expr:"job"`
}

StepContext provides context data for step expression evaluation

type StepRetry

type StepRetry struct {
	MaxAttempts  int      `yaml:"max_attempts" validate:"required,gte=1"`
	Interval     Interval `yaml:"interval"`
	InitialDelay Interval `yaml:"initial_delay,omitempty"`
}

StepRetry defines the retry configuration for steps until success (status 0)

func (*StepRetry) Validate

func (s *StepRetry) Validate() error

Validate performs custom validation for StepRetry

type Workflow

type Workflow struct {
	Name        string         `yaml:"name" validate:"required"`
	Description string         `yaml:"description,omitempty"`
	Jobs        []Job          `yaml:"jobs" validate:"required"`
	Vars        map[string]any `yaml:"vars"`
	// Defaults are the with of each action, by its uses, for the steps of
	// every job. A job's own defaults come before them, and a step's with
	// before both.
	Defaults any `yaml:"defaults"`
	// Actions gives names to external actions, for the steps and the
	// defaults of the jobs to name them by. Load writes the action in place
	// of each name, so nothing that runs the workflow sees one.
	Actions map[string]string `yaml:"actions,omitempty"`
	// Secrets names environment variables whose values must not appear in
	// anything Probe prints or writes.
	Secrets []string `yaml:"secrets,omitempty"`
	// contains filtered or unexported fields
}

func (*Workflow) BaseDir

func (w *Workflow) BaseDir() string

BaseDir returns the directory local actions are relative to.

func (*Workflow) Env

func (w *Workflow) Env() map[string]string

Env returns the workflow's own environment, which the vars of every run read: the process's, as it was when Env was first called, unless the workflow was given one. What a run is given in Config.Env is that run's alone, and is not in it.

func (*Workflow) Graph

func (w *Workflow) Graph() dag.Graph

Graph returns the jobs and steps of the workflow in the form the DAG renderers draw. The steps of an embedded job are read from its file, at the path its `with.path` names after the workflow's vars are expanded, relative to the working directory.

func (*Workflow) RunID

func (w *Workflow) RunID() string

RunID returns the ID of the last run Start began, which every action of the run is told about, or an empty string before Start.

func (*Workflow) Start

func (w *Workflow) Start(c Config) error

Start runs the workflow with the given configuration. It prepares the run, which refuses the workflow for what keeps it from running before any job starts, executes the jobs of the run, and writes the report files the run was asked for. What a run decides and finds out is its own, so the workflow is left as it was for the next Start, but for the exit status and the ID of the last run.

Jump to

Keyboard shortcuts

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