exprparser

package
v12.5.2 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 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 added in v12.2.0

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 added in v12.2.0

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 added in v12.2.0

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
}

type DefaultStatusCheck

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

func (DefaultStatusCheck) String

func (dsc DefaultStatusCheck) String() string

type ErrorMode added in v12.1.0

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

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 added in v12.1.1

type InvalidJobOutputReferencedError struct {
	JobID      string
	OutputName string
	String     string
}

func (*InvalidJobOutputReferencedError) Error added in v12.1.1

type InvalidMatrixDimensionReferencedError added in v12.1.1

type InvalidMatrixDimensionReferencedError struct {
	Dimension string
	String    string
}

func (*InvalidMatrixDimensionReferencedError) Error added in v12.1.1

type JobOutputsWrapper added in v12.1.1

type JobOutputsWrapper struct {
	JobID string
	Needs *Needs
}

type MatrixWrapper added in v12.1.1

type MatrixWrapper struct {
	Matrix map[string]any
}

type Mutation added in v12.2.0

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 added in v12.1.0

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

type VariableAccessMutator added in v12.2.0

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 added in v12.2.0

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