runner

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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)

Types

type Cache

type Cache interface {
	Get(ctx context.Context, parentDir string, stepResource StepResource) (*proto.SpecDefinition, error)
}

type Describer

type Describer interface {
	Describe() string
}

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

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 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)

func (*Environment) ValueOf

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

func (*Environment) Values

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

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, specDef *proto.SpecDefinition) *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

func NewFileSystemStepResource

func NewFileSystemStepResource(path []string, filename string) *FileSystemStepResource

func (*FileSystemStepResource) Describe

func (sr *FileSystemStepResource) Describe() string

func (*FileSystemStepResource) Interpolate

func (*FileSystemStepResource) ToProtoStepRef

func (sr *FileSystemStepResource) ToProtoStepRef() *proto.Step_Reference

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(url string, version string, path []string, filename string) *GitStepResource

func (*GitStepResource) Describe

func (sr *GitStepResource) Describe() string

func (*GitStepResource) Interpolate

func (*GitStepResource) ToProtoStepRef

func (sr *GitStepResource) ToProtoStepRef() *proto.Step_Reference

type GlobalContext

type GlobalContext struct {
	WorkDir string
	Job     map[string]string
	Env     *Environment
	Stdout  io.Writer
	Stderr  io.Writer
}

func NewGlobalContext

func NewGlobalContext(env *Environment) *GlobalContext

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

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, resourceLoader Cache, parser StepParser, stepReference *proto.Step, stepResource StepResource, workDir string) *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]*context.Variable
	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(globalCtx *GlobalContext, stepCache Cache) *Parser

func (*Parser) Parse

func (p *Parser) Parse(specDef *proto.SpecDefinition, 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, specDef *proto.SpecDefinition, 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 StepParser

type StepParser interface {
	Parse(specDef *proto.SpecDefinition, params *Params, loadedFrom 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 {
	Describer
	Interpolate(*expression.InterpolationContext) (StepResource, error)
	ToProtoStepRef() *proto.Step_Reference
}

StepResource knows how to load a Step

type StepResultBuilder

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

func NewStepResultBuilder

func NewStepResultBuilder(loadedFrom StepReference, params *Params, specDef *proto.SpecDefinition) *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 {
	*GlobalContext

	StepDir    string                       // The path to the YAML definition directory so steps can find their files and sub-steps with relative references know where to start.
	OutputFile *StepFile                    // The path to the output file.
	ExportFile *StepFile                    // The path to the export file.
	Env        *Environment                 // Expanded environment values of the executing step.
	Inputs     map[string]*structpb.Value   // Expanded input values of the executing step.
	Steps      map[string]*proto.StepResult // Results of previously executed steps.
}

func NewStepsContext

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

func (*StepsContext) Cleanup

func (s *StepsContext) Cleanup()

func (*StepsContext) ExpandAndApplyEnv

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

func (*StepsContext) GetEnvList

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

func (*StepsContext) GetEnvs

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

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

Directories

Path Synopsis
test_steps

Jump to

Keyboard shortcuts

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