expr

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package expr parses the GitHub Actions expression language (${{ ... }}) and extracts the context references it contains: secrets.X, vars.X, env.X, matrix.X, needs.X.outputs.Y and friends.

Two rules govern this package, and they come straight from the product principles: detection is purely deterministic, and anything that cannot be resolved statically is reported as unresolved rather than guessed. A caller must never turn an unresolved reference into a finding.

Index

Constants

View Source
const (
	CtxSecrets  = "secrets"
	CtxVars     = "vars"
	CtxEnv      = "env"
	CtxMatrix   = "matrix"
	CtxNeeds    = "needs"
	CtxInputs   = "inputs"
	CtxGitHub   = "github"
	CtxSteps    = "steps"
	CtxJob      = "job"
	CtxJobs     = "jobs"
	CtxRunner   = "runner"
	CtxStrategy = "strategy"
)

Context names that can root a reference chain.

Variables

This section is empty.

Functions

func HasExpression

func HasExpression(s string) bool

HasExpression reports whether s contains a ${{ }} block.

Types

type Ref

type Ref struct {
	Context string   // root context, lowercased ("secrets")
	Path    []string // resolved segments after the root
	Dynamic bool     // true when a segment could not be resolved statically
	Raw     string   // source text of the reference
	Offset  int      // byte offset of the reference in the scanned string
	End     int      // byte offset just past the reference
}

Ref is one reference to a context, for example secrets.NPM_TOKEN.

Dynamic marks a reference whose path could not be fully resolved at rest, such as secrets[format('{0}_KEY', env.REGION)]. Path then holds only the segments resolved before the dynamic one, and callers must treat the reference as UNKNOWN.

func (Ref) Name

func (r Ref) Name() string

Name returns the first path segment, which for secrets and vars is the secret or variable name. It is empty for a dynamic or bare reference.

func (Ref) String

func (r Ref) String() string

String renders the reference the way a user writes it.

type Result

type Result struct {
	Refs       []Ref
	Unresolved []Unresolved
	Blocks     int // number of ${{ }} blocks found
}

Result is the outcome of scanning one string.

func Scan

func Scan(s string) Result

Scan extracts every reference from the ${{ }} blocks in s. Text outside the blocks is ignored. Offsets are relative to s.

func ScanBare

func ScanBare(s string) Result

ScanBare parses s as a single expression with no ${{ }} delimiters.

func ScanCondition

func ScanCondition(s string) Result

ScanCondition scans an `if:` value, which GitHub accepts either wrapped in ${{ }} or bare.

type Unresolved

type Unresolved struct {
	Text   string // the expression source, without the ${{ }} delimiters
	Offset int    // byte offset of the expression in the scanned string
	Reason string
}

Unresolved is an expression Yumlab could not parse. It never becomes a finding: it is counted and reported as UNKNOWN.

Jump to

Keyboard shortcuts

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