runner

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LogLevelEnvName = "CI_STEPS_LOG_LEVEL"
View Source
var RunningInDebugMode, _ = strconv.ParseBool(os.Getenv("CI_STEPS_DEBUG"))
View Source
var StepDefinedInGitLabJob = NewNamedStepReference("", nil)

StepDefinedInGitLabJob is a step defined in a GitLab jobs using the run: syntax or STEPS: variable

Functions

func WithErrCtxLogAdditionalCtx added in v0.2.0

func WithErrCtxLogAdditionalCtx(logAdditionalCtx bool) func(*ErrorCtx)

func WithStepsCtxExportFile added in v0.7.0

func WithStepsCtxExportFile(exportFile *StepFile) func(*StepsContext)

func WithStepsCtxOutputFile added in v0.7.0

func WithStepsCtxOutputFile(outputFile *StepFile) func(*StepsContext)

func WithStepsCtxStepResults added in v0.7.0

func WithStepsCtxStepResults(results map[string]*proto.StepResult) func(*StepsContext)

Types

type Describer

type Describer interface {
	Describe() string
}

Describer types know how to describe themselves in a language to be read by humans

type DynamicStepResource added in v0.9.0

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

DynamicStepResource knows how to convert an expression into a step resource

func NewDynamicStepResource added in v0.9.0

func NewDynamicStepResource(parser stepResourceParser, workDir, shortRef string) *DynamicStepResource

func (*DynamicStepResource) Fetch added in v0.9.0

type Environment

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

Environment represents environment variables. Environment variables are used in places such as the step export_file, step definitions with ENV, and OS environment. Environment does not merge maps, and so does not lose information. Merging of environments occurs when values are retrieved. An environment can be added as "lexical scope", these values have higher precedence when looking up a variable. Mutations to the environment take precedence over initialized variables, most recent mutations have the highest precedence

func GlobalEnvironment added in v0.6.0

func GlobalEnvironment(parent *Environment, jobVars JobVariables) (*Environment, error)

GlobalEnvironment sets environment variables that are always available for any step

func NewEmptyEnvironment

func NewEmptyEnvironment() *Environment

func NewEnvironment

func NewEnvironment(vars map[string]string) *Environment

func NewEnvironmentFromOS

func NewEnvironmentFromOS(rejectIf ...func(string) bool) (*Environment, error)

NewEnvironmentFromOS returns the environment variables found in the OS runtime. Variables can be filtered by name, passing no names will return all variables.

func NewEnvironmentFromOSWithKnownVars

func NewEnvironmentFromOSWithKnownVars() (*Environment, error)

func NewKVEnvironment

func NewKVEnvironment(keyValues ...string) *Environment

NewKVEnvironment creates an environment from a list of key values

func (*Environment) AddLexicalScope

func (e *Environment) AddLexicalScope(vars map[string]string) *Environment

func (*Environment) Len

func (e *Environment) Len() int

func (*Environment) Mutate

func (e *Environment) Mutate(env *Environment)

Mutate adds a mutation to the environment.

func (*Environment) ValueOf

func (e *Environment) ValueOf(key string) string

ValueOf returns the value of a specific environment variable. This ensures consistency by acquiring locks in the same order as Values().

func (*Environment) Values

func (e *Environment) Values() map[string]string

Values returns a merged map of all environment variables. This method ensures a consistent snapshot by acquiring all locks in the chain.

type ErrorCtx added in v0.2.0

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

func NewErrorCtx added in v0.2.0

func NewErrorCtx(description string, additionalCxt []byte, options ...func(*ErrorCtx)) *ErrorCtx

func (*ErrorCtx) Errorf added in v0.2.0

func (e *ErrorCtx) Errorf(message string, v ...any) error

type ExecResult

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

func NewExecResult

func NewExecResult(workDir string, cmdArgs []string, exitCode int) *ExecResult

func (*ExecResult) ToProto

func (ec *ExecResult) ToProto() *proto.StepResult_ExecResult

type ExecutableStep

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

ExecutableStep is a step that executes a command.

func NewExecutableStep

func NewExecutableStep(loadedFrom StepReference, params *Params, funcDesc *FunctionDescriptor) *ExecutableStep

func (*ExecutableStep) Describe

func (s *ExecutableStep) Describe() string

func (*ExecutableStep) Run

func (s *ExecutableStep) Run(ctx ctx.Context, stepsCtx *StepsContext) (*proto.StepResult, error)

type FileSystemStepResource

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

FileSystemStepResource knows how to load a step from the file system using an absolute path

func NewFileSystemStepResource

func NewFileSystemStepResource(workDir string, stepPath, filename string) *FileSystemStepResource

func (*FileSystemStepResource) Describe

func (sr *FileSystemStepResource) Describe() string

func (*FileSystemStepResource) Fetch added in v0.9.0

type FixedStepResource added in v0.9.0

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

func NewFixedStepResource added in v0.9.0

func NewFixedStepResource(funcDesc *FunctionDescriptor) *FixedStepResource

func (*FixedStepResource) Fetch added in v0.9.0

type FunctionDescriptor added in v0.24.0

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

FunctionDescriptor describes a Function that has been fetched

func NewFunctionDescriptor added in v0.24.0

func NewFunctionDescriptor(spec *proto.Spec, definition *proto.Definition, dir string) *FunctionDescriptor

NewFunctionDescriptor creates a FunctionDescriptor If the function has been fetched, directory should be the location where the function files are downloaded If the function is dynamic, dir should be empty string

func (*FunctionDescriptor) DefinitionOutputs added in v0.24.0

func (sd *FunctionDescriptor) DefinitionOutputs() map[string]*structpb.Value

func (*FunctionDescriptor) DelegateTo added in v0.24.0

func (sd *FunctionDescriptor) DelegateTo() string

func (*FunctionDescriptor) DescribeType added in v0.24.0

func (sd *FunctionDescriptor) DescribeType() string

func (*FunctionDescriptor) Dir added in v0.24.0

func (sd *FunctionDescriptor) Dir() string

func (*FunctionDescriptor) Env added in v0.24.0

func (sd *FunctionDescriptor) Env() map[string]string

func (*FunctionDescriptor) ExecCommand added in v0.24.0

func (sd *FunctionDescriptor) ExecCommand() []string

func (*FunctionDescriptor) ExecWorkDir added in v0.24.0

func (sd *FunctionDescriptor) ExecWorkDir() string

func (*FunctionDescriptor) FunctionName added in v0.24.0

func (sd *FunctionDescriptor) FunctionName() string

func (*FunctionDescriptor) IsDelegateOutputs added in v0.24.0

func (sd *FunctionDescriptor) IsDelegateOutputs() bool

func (*FunctionDescriptor) IsTypeExec added in v0.24.0

func (sd *FunctionDescriptor) IsTypeExec() bool

func (*FunctionDescriptor) IsTypeFunction added in v0.24.0

func (sd *FunctionDescriptor) IsTypeFunction() bool

func (*FunctionDescriptor) IsTypeSteps added in v0.24.0

func (sd *FunctionDescriptor) IsTypeSteps() bool

func (*FunctionDescriptor) SpecInputWithName added in v0.24.0

func (sd *FunctionDescriptor) SpecInputWithName(name string) (*proto.Spec_Content_Input, bool)

func (*FunctionDescriptor) SpecInputs added in v0.24.0

func (sd *FunctionDescriptor) SpecInputs() map[string]*proto.Spec_Content_Input

func (*FunctionDescriptor) SpecOutputs added in v0.24.0

func (sd *FunctionDescriptor) SpecOutputs() map[string]*proto.Spec_Content_Output

func (*FunctionDescriptor) Steps added in v0.24.0

func (sd *FunctionDescriptor) Steps() []*proto.Step

func (*FunctionDescriptor) ToProto added in v0.24.0

func (sd *FunctionDescriptor) ToProto() *proto.SpecDefinition

type FunctionStepResource added in v0.17.0

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

FunctionStepResource knows how to load a step from the known registered step functions

func NewFunctionStepResource added in v0.17.0

func NewFunctionStepResource(functionName string, findStepFunction StepFuncFinder) *FunctionStepResource

func (*FunctionStepResource) Fetch added in v0.17.0

type GitStepResource

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

GitStepResource knows how to load a step from a Git repository

func NewGitStepResource

func NewGitStepResource(fetcher *git.GitFetcher, url string, version string, stepDir string, filename string) *GitStepResource

func (*GitStepResource) Fetch added in v0.9.0

type GlobalContext

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

func NewGlobalContext

func NewGlobalContext(workDir string, job JobVariables, env *Environment, stdout, stderr io.Writer) *GlobalContext

func (*GlobalContext) AddGlobalEnv added in v0.7.0

func (gc *GlobalContext) AddGlobalEnv(env *Environment)

func (*GlobalContext) Env

func (gc *GlobalContext) Env() *Environment

func (*GlobalContext) EnvWithLexicalScope added in v0.7.0

func (gc *GlobalContext) EnvWithLexicalScope(envVars map[string]string) *Environment

func (*GlobalContext) Job

func (gc *GlobalContext) Job() JobVariables

func (*GlobalContext) Logf added in v0.2.0

func (gc *GlobalContext) Logf(format string, v ...any) error

func (*GlobalContext) Logln added in v0.2.0

func (gc *GlobalContext) Logln(format string, v ...any) error

func (*GlobalContext) LookupEnv added in v0.20.0

func (gc *GlobalContext) LookupEnv(key string) (string, bool)

func (*GlobalContext) Pipe added in v0.7.0

func (gc *GlobalContext) Pipe() (io.Writer, io.Writer)

func (*GlobalContext) ProjectDir added in v0.18.0

func (gc *GlobalContext) ProjectDir() string

func (*GlobalContext) WorkDir

func (gc *GlobalContext) WorkDir() string

type JobVariables added in v0.16.0

type JobVariables map[string]*structpb.Value

func (JobVariables) ProjectDir added in v0.18.0

func (v JobVariables) ProjectDir() string

func (JobVariables) StringValueOf added in v0.16.0

func (v JobVariables) StringValueOf(key string) string

type Kind added in v0.17.0

type Kind int
const (
	KindNull Kind = iota + 1 // same types as structpb.Value Kind
	KindNumber
	KindString
	KindBool
	KindStruct
	KindList
)

func ValueToKind added in v0.17.0

func ValueToKind(value *structpb.Value) (Kind, error)

func (Kind) String added in v0.17.0

func (k Kind) String() string

type LazilyLoadedStep

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

LazilyLoadedStep is a step that dynamically fetches, parses and executes a step definition.

func NewLazilyLoadedStep

func NewLazilyLoadedStep(globalCtx *GlobalContext, parser StepParser, stepReference *proto.Step, stepResource StepResource) *LazilyLoadedStep

func (*LazilyLoadedStep) Describe

func (s *LazilyLoadedStep) Describe() string

func (*LazilyLoadedStep) Run

func (s *LazilyLoadedStep) Run(ctx ctx.Context, parentStepsCtx *StepsContext) (*proto.StepResult, error)

Run fetches a step definition, parses the step, and executes it. The step reference inputs and environment are expanded. The current environment is cloned into params in preparation for a recursive call to Run.

type NamedStepReference

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

NamedStepReference is a step that is loaded using a name and a reference

func NewNamedStepReference

func NewNamedStepReference(name string, ref *proto.Step_Reference) *NamedStepReference

func (*NamedStepReference) Describe added in v0.2.0

func (sr *NamedStepReference) Describe() string

func (*NamedStepReference) ToProtoStep

func (sr *NamedStepReference) ToProtoStep(params *Params) *proto.Step

type Params

type Params struct {
	Inputs map[string]*structpb.Value
	Env    map[string]string
}

Params are the input and environment parameters for an execution.

func (*Params) NewInputsWithDefault

func (p *Params) NewInputsWithDefault(specInputs map[string]*proto.Spec_Content_Input) map[string]*structpb.Value

type Parser

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

func NewParser

func NewParser(stepResParser *StepResourceParser, stepFuncFinder StepFuncFinder) *Parser

func (*Parser) Parse

func (p *Parser) Parse(globalCtx *GlobalContext, funcDesc *FunctionDescriptor, params *Params, loadedFrom StepReference) (Step, error)

type SequenceOfSteps

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

SequenceOfSteps is a step that executes many steps.

func NewSequenceOfSteps

func NewSequenceOfSteps(loadedFrom StepReference, params *Params, funcDesc *FunctionDescriptor, steps ...Step) *SequenceOfSteps

func (*SequenceOfSteps) Describe

func (s *SequenceOfSteps) Describe() string

func (*SequenceOfSteps) Run

func (s *SequenceOfSteps) Run(ctx ctx.Context, stepsCtx *StepsContext) (*proto.StepResult, error)

type Step

type Step interface {
	Describer
	Run(ctx ctx.Context, stepsCtx *StepsContext) (*proto.StepResult, error)
}

type StepFile

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

func NewStepFile

func NewStepFile(path string) *StepFile

func NewStepFileInDir

func NewStepFileInDir(dir string) (*StepFile, error)

func NewStepFileInTmp

func NewStepFileInTmp() (*StepFile, error)

func (*StepFile) Path

func (s *StepFile) Path() string

func (*StepFile) ReadDotEnv

func (s *StepFile) ReadDotEnv() (map[string]string, error)

func (*StepFile) ReadEnvironment

func (s *StepFile) ReadEnvironment() (*Environment, error)

func (*StepFile) ReadKeyValueLines

func (s *StepFile) ReadKeyValueLines() (map[string]*structpb.Value, error)

func (*StepFile) ReadStepResult

func (s *StepFile) ReadStepResult() (*proto.StepResult, error)

func (*StepFile) ReadValues

func (s *StepFile) ReadValues(specOutputs map[string]*proto.Spec_Content_Output) (map[string]*structpb.Value, error)

func (*StepFile) Remove

func (s *StepFile) Remove() error

type StepFileLine added in v0.2.0

type StepFileLine struct {
	Name  *string         `json:"name"`
	Value *structpb.Value `json:"value"`
}

type StepFunc added in v0.17.0

type StepFunc func(ctx context.Context, stepsCtx *StepsContext) error

type StepFuncFinder added in v0.17.0

type StepFuncFinder func(stepName string) (*proto.Spec, StepFunc, error)

type StepFunction added in v0.17.0

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

StepFunction is a step that executes a step as a function. Only functions registered as steps can be called.

func NewStepFunction added in v0.17.0

func NewStepFunction(loadedFrom StepReference, params *Params, funcDesc *FunctionDescriptor, stepFuncFinder StepFuncFinder) *StepFunction

func (*StepFunction) Describe added in v0.17.0

func (s *StepFunction) Describe() string

func (*StepFunction) Run added in v0.17.0

func (s *StepFunction) Run(ctx ctx.Context, stepsCtx *StepsContext) (*proto.StepResult, error)

type StepFunctionRepository added in v0.17.0

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

func NewStepFunctionRepository added in v0.17.0

func NewStepFunctionRepository() *StepFunctionRepository

func (*StepFunctionRepository) Find added in v0.17.0

func (*StepFunctionRepository) Register added in v0.17.0

func (r *StepFunctionRepository) Register(step string, spec *proto.Spec, stepFunc StepFunc) error

type StepParser

type StepParser interface {
	Parse(*GlobalContext, *FunctionDescriptor, *Params, StepReference) (Step, error)
}

type StepReference

type StepReference interface {
	ToProtoStep(*Params) *proto.Step
	Describer
}

StepReference knows how the step was loaded

type StepResource

type StepResource interface {
	Fetch(context.Context, *expression.InterpolationContext) (*FunctionDescriptor, error)
}

StepResource knows how to load a Step

type StepResourceParser added in v0.9.0

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

func NewStepResourceParser added in v0.9.0

func NewStepResourceParser(gitFetcher *git.GitFetcher, stepFuncFinder StepFuncFinder) *StepResourceParser

func (*StepResourceParser) Parse added in v0.9.0

func (p *StepResourceParser) Parse(workDir string, stepRef *proto.Step_Reference) (StepResource, error)

type StepResultBuilder

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

func NewStepResultBuilder

func NewStepResultBuilder(loadedFrom StepReference, params *Params, funcDesc *FunctionDescriptor) *StepResultBuilder

func (*StepResultBuilder) Build

func (bldr *StepResultBuilder) Build() *proto.StepResult

func (*StepResultBuilder) BuildFailure

func (bldr *StepResultBuilder) BuildFailure() *proto.StepResult

func (*StepResultBuilder) ObserveEnv

func (bldr *StepResultBuilder) ObserveEnv(env *Environment, err error) error

func (*StepResultBuilder) ObserveExecutedCmd

func (bldr *StepResultBuilder) ObserveExecutedCmd(execResult *ExecResult, err error) error

func (*StepResultBuilder) ObserveExports

func (bldr *StepResultBuilder) ObserveExports(exports *Environment, err error) (*Environment, error)

func (*StepResultBuilder) ObserveOutputs

func (bldr *StepResultBuilder) ObserveOutputs(outputs map[string]*structpb.Value, err error) error

func (*StepResultBuilder) ObserveStepResult

func (bldr *StepResultBuilder) ObserveStepResult(stepResult *proto.StepResult, err error) (*proto.StepResult, error)

func (*StepResultBuilder) WithEnv

func (bldr *StepResultBuilder) WithEnv(env map[string]string) *StepResultBuilder

func (*StepResultBuilder) WithExecResult

func (bldr *StepResultBuilder) WithExecResult(executedCmd *ExecResult) *StepResultBuilder

func (*StepResultBuilder) WithExports

func (bldr *StepResultBuilder) WithExports(exports *Environment) *StepResultBuilder

func (*StepResultBuilder) WithOutputs

func (bldr *StepResultBuilder) WithOutputs(outputs map[string]*structpb.Value) *StepResultBuilder

func (*StepResultBuilder) WithSubStepResult

func (bldr *StepResultBuilder) WithSubStepResult(result *proto.StepResult) *StepResultBuilder

type StepsContext

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

func NewStepsContext

func NewStepsContext(globalCtx *GlobalContext, stepDir string, inputs map[string]*structpb.Value, env *Environment, options ...func(*StepsContext)) (*StepsContext, error)

func (*StepsContext) AddGlobalEnv added in v0.7.0

func (s *StepsContext) AddGlobalEnv(env *Environment)

func (*StepsContext) Cleanup

func (s *StepsContext) Cleanup()

func (*StepsContext) EnvWithLexicalScope added in v0.7.0

func (s *StepsContext) EnvWithLexicalScope(envVars map[string]string) *Environment

func (*StepsContext) ExpandAndApplyEnv

func (s *StepsContext) ExpandAndApplyEnv(env map[string]string) (*Environment, error)

func (*StepsContext) GetEnv added in v0.17.0

func (s *StepsContext) GetEnv(name string) string

func (*StepsContext) GetEnvList

func (s *StepsContext) GetEnvList() []string

func (*StepsContext) GetEnvs

func (s *StepsContext) GetEnvs() map[string]string

func (*StepsContext) GetExportFile added in v0.17.0

func (s *StepsContext) GetExportFile() string

func (*StepsContext) GetInput added in v0.17.0

func (s *StepsContext) GetInput(name string, kind Kind) (*structpb.Value, error)

func (*StepsContext) GetInputWithDefault added in v0.18.0

func (s *StepsContext) GetInputWithDefault(name string, kind Kind, inputSpec map[string]*proto.Spec_Content_Input) (*structpb.Value, error)

func (*StepsContext) GetOutputFile added in v0.17.0

func (s *StepsContext) GetOutputFile() string

func (*StepsContext) Logln added in v0.7.0

func (s *StepsContext) Logln(format string, v ...any) error

func (*StepsContext) LookupEnv added in v0.20.0

func (s *StepsContext) LookupEnv(key string) (string, bool)

func (*StepsContext) Pipe added in v0.7.0

func (s *StepsContext) Pipe() (io.Writer, io.Writer)

func (*StepsContext) ProjectDir added in v0.18.0

func (s *StepsContext) ProjectDir() string

func (*StepsContext) ReadExportedEnv added in v0.7.0

func (s *StepsContext) ReadExportedEnv() (*Environment, error)

func (*StepsContext) ReadOutputStepResult added in v0.7.0

func (s *StepsContext) ReadOutputStepResult() (*proto.StepResult, error)

func (*StepsContext) ReadOutputValues added in v0.7.0

func (s *StepsContext) ReadOutputValues(specOutputs map[string]*proto.Spec_Content_Output) (map[string]*structpb.Value, error)

func (*StepsContext) RecordResult

func (s *StepsContext) RecordResult(stepResult *proto.StepResult)

RecordResult captures the result of a step even if it failed

func (*StepsContext) StepResults

func (s *StepsContext) StepResults() []*proto.StepResult

func (*StepsContext) View

func (*StepsContext) WorkDir added in v0.7.0

func (s *StepsContext) WorkDir() string

Jump to

Keyboard shortcuts

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