exprparser

package
v13.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTruthy

func IsTruthy(input any) bool

func Mutate

func Mutate(input string, mutations ...Mutation) (string, error)

Given a workflow string which may contain an expression, apply an expression `Mutation` to the string and return a new one. Mutations have the capability to replace parts of the abstract-syntax-tree (AST) for the expression with new contents, allowing for sophisticated changes to the expression.

As the expressions within the string are parsed into an AST, mutated, and then re-rendered from the new AST to text, arbitrary formatting changes may occur, particularly with whitespace. For example, a function call like `format('id={0}',123)` will be returned with a space between function parameters, even if a mutator didn't change this function.

func MutateYamlNode

func MutateYamlNode(node *yaml.Node, mutations ...Mutation) error

Where `Mutate` operates on a single expression string, `MutateYamlNode` will iterate through an entire yaml tree and perform the mutations on all string values found within.

func RewriteSubExpression

func RewriteSubExpression(in string, forceFormat bool) string

The expression parsing library that runner uses to evaluate workflow expressions (eg. `${{ ... }}`) doesn't support a string which is partially text and partially expression, like `Hello ${{ vars.world }}!`. `RewriteSubExpression` converts a string in this format into a single expression evaluation, such as `format('Hello {0}!', vars.world)`. The return value may still be `${{ ... }}` delimited.

Types

type Config

type Config struct {
	Run        *model.Run
	WorkingDir string
	Context    string

	OverrideSuccess   func() (bool, error)
	OverrideFailure   func() (bool, error)
	OverrideCancelled func() (bool, error)
}

type DefaultStatusCheck

type DefaultStatusCheck int
const (
	DefaultStatusCheckNone DefaultStatusCheck = iota
	DefaultStatusCheckSuccess
	DefaultStatusCheckAlways
	DefaultStatusCheckCanceled
	DefaultStatusCheckFailure
)

func (DefaultStatusCheck) String

func (dsc DefaultStatusCheck) String() string

type EnvReferencedError

type EnvReferencedError struct {
	Key    string
	String string
}

func (*EnvReferencedError) Error

func (e *EnvReferencedError) Error() string

func (*EnvReferencedError) Is

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

type EnvWrapper

type EnvWrapper struct {
	Env map[string]string
}

type ErrorMode

type ErrorMode int
const (
	InvalidJobOutput ErrorMode = 1 << iota
	InvalidMatrixDimension
	BlockEnv
	BlockSecrets
)

type EvaluationEnvironment

type EvaluationEnvironment struct {
	Github    *model.GithubContext
	Env       map[string]string
	Job       *model.JobContext
	Jobs      *map[string]*model.WorkflowCallResult
	Steps     map[string]*model.StepResult
	Runner    map[string]any
	Secrets   map[string]string
	Vars      map[string]string
	Strategy  map[string]any
	Matrix    map[string]any
	Needs     map[string]Needs
	Inputs    map[string]any
	HashFiles func([]reflect.Value) (any, error)
	ErrorMode ErrorMode
}

type Interpreter

type Interpreter interface {
	Evaluate(input string, defaultStatusCheck DefaultStatusCheck) (any, error)
}

func NewInterpreter

func NewInterpreter(env *EvaluationEnvironment, config Config) Interpreter

type InvalidJobOutputReferencedError

type InvalidJobOutputReferencedError struct {
	JobID      string
	OutputName string
	String     string
}

func (*InvalidJobOutputReferencedError) Error

type InvalidMatrixDimensionReferencedError

type InvalidMatrixDimensionReferencedError struct {
	Dimension string
	String    string
}

func (*InvalidMatrixDimensionReferencedError) Error

type JobOutputsWrapper

type JobOutputsWrapper struct {
	JobID string
	Needs *Needs
}

type MatrixWrapper

type MatrixWrapper struct {
	Matrix map[string]any
}

type Mutation

type Mutation interface {
	// Given a single AST node, return either `nil` to allow the original node to be used, or a new `ExprNode` to
	// replace it in the AST.
	SingleNodeMutation(exprNode actionlint.ExprNode) (actionlint.ExprNode, error)
}

Mutations are provided to `Mutate` to change an expression.

type Needs

type Needs struct {
	Outputs map[string]string `json:"outputs"`
	Result  string            `json:"result"`
}

type NeedsWrapper

type NeedsWrapper struct {
	JobID   string
	Outputs map[string]string
}

type SecretsReferencedError

type SecretsReferencedError struct {
	Key    string
	String string
}

func (*SecretsReferencedError) Error

func (e *SecretsReferencedError) Error() string

func (*SecretsReferencedError) Is

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

type SecretsWrapper

type SecretsWrapper struct {
	Secrets map[string]string
}

type VariableAccessMutator

type VariableAccessMutator struct {
	// Variable to trigger the mutator upon.  If set to `needs`, for example, then `needs.hello` will trigger
	// `Rewriter`.
	Variable string
	// Rewrite routine to use.  `property` will be an AST node representing the property accessed.  Typically you would
	// not want to inspect inside the contents of the `property` as it could be any type of AST from a simple string
	// literal to a function call.
	Rewriter func(property actionlint.ExprNode) actionlint.ExprNode
}

VariableAccessMutator is used to rewrite access to top-level variables (contexts, in the runner terminology). When a variable matching the name `Variable` is accessed, invoke the Rewriter function to get a replacement `ExprNode`. Both access to a variable with an object dereference (eg. `var.foo`) and an index-style access (`var.['foo']`) is supported for mutation. Note that because index-style access is supported, the mutator does not know the specific value of the property name being accessed -- it could be computed or derived from another property (`var[other-var.something]`).

func (*VariableAccessMutator) SingleNodeMutation

func (vam *VariableAccessMutator) SingleNodeMutation(exprNode actionlint.ExprNode) (actionlint.ExprNode, error)

Jump to

Keyboard shortcuts

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