runner

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildCommand

func BuildCommand(runCommand, shell string) []string

BuildCommand builds the command slice for a given shell and run command.

func BuildNeedsContext

func BuildNeedsContext(
	job workflow.Job,
	jobResults map[string]Status,
	jobOutputs map[string]map[string]string,
	matrixJobs map[string]bool,
) map[string]JobNeedsData

BuildNeedsContext builds the needs context map for expression evaluation.

func CollectSecrets

func CollectSecrets(secretsMap map[string]any, envMaps ...map[string]string) []string

CollectSecrets collects secret strings from a secrets map and environment variable maps.

func DeduplicateAndSortSecrets

func DeduplicateAndSortSecrets(secrets []string) []string

DeduplicateAndSortSecrets deduplicates and sorts secret strings by length descending.

func FindRepoRoot added in v1.0.3

func FindRepoRoot(startPath string) (string, error)

FindRepoRoot finds the git repository root by walking up from startPath. Returns the directory containing .git/ or .github/. Falls back to the workflow file's directory if neither is found.

func IsSecretKey

func IsSecretKey(key string) bool

IsSecretKey returns true if key contains common secret keywords (case-insensitive).

func MaskSecrets

func MaskSecrets(output string, secrets []string) string

MaskSecrets replaces all occurrences of secret values in output with "***".

func NormalizeLineEndings added in v1.4.0

func NormalizeLineEndings(content string, mode string) (string, error)

NormalizeLineEndings handles line ending conversion based on mode. Modes: "convert" (CRLF→LF), "preserve" (keep as-is), "error" (reject CRLF)

func ParseTimeoutMinutes

func ParseTimeoutMinutes(value any) (time.Duration, error)

ParseTimeoutMinutes parses timeout-minutes value which can be integer or float.

func TopologicalSort

func TopologicalSort(wf *workflow.Workflow) ([]string, error)

TopologicalSort returns job IDs of the workflow sorted in topological execution order.

func ValidateNeeds

func ValidateNeeds(wf *workflow.Workflow) error

ValidateNeeds validates the job needs graph in a workflow.

func WithTimeout

func WithTimeout(ctx context.Context, timeout time.Duration) (context.Context, context.CancelFunc)

WithTimeout returns a context with a timeout and its cancel function.

Types

type ExpressionContext

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

ExpressionContext holds the context for expression interpolation.

func NewExpressionContext

func NewExpressionContext(
	env map[string]string,
	github map[string]string,
	runner map[string]string,
	stepOutputs *StepOutputs,
) *ExpressionContext

NewExpressionContext creates a new ExpressionContext.

func (*ExpressionContext) Interpolate

func (ec *ExpressionContext) Interpolate(input string) (string, error)

Interpolate interpolates expressions in a string. Supports: ${{ env.KEY }}, ${{ github.KEY }}, ${{ runner.KEY }}, ${{ steps.STEP_ID.outputs.KEY }}, ${{ matrix.KEY }}, ${{ needs.JOB_ID.result }}, ${{ needs.JOB_ID.outputs.KEY }}

func (*ExpressionContext) InterpolateMap

func (ec *ExpressionContext) InterpolateMap(input map[string]string) (map[string]string, error)

InterpolateMap interpolates expressions in all values of a map.

func (*ExpressionContext) InterpolateWith

func (ec *ExpressionContext) InterpolateWith(input map[string]any) (map[string]any, error)

InterpolateWith interpolates expressions in all values of a map[string]any (e.g. step.With).

func (*ExpressionContext) SetCancelled

func (ec *ExpressionContext) SetCancelled(cancelled bool)

SetCancelled sets the cancelled state.

func (*ExpressionContext) SetCurrentStepID

func (ec *ExpressionContext) SetCurrentStepID(stepID string)

SetCurrentStepID sets the current step ID for steps context.

func (*ExpressionContext) SetMatrix

func (ec *ExpressionContext) SetMatrix(matrix map[string]any)

SetMatrix sets the matrix context for expression evaluation.

func (*ExpressionContext) SetNeedsContext

func (ec *ExpressionContext) SetNeedsContext(needs map[string]JobNeedsData)

SetNeedsContext sets the needs context for expression evaluation.

func (*ExpressionContext) SetStepResults

func (ec *ExpressionContext) SetStepResults(results []*StepResult)

SetStepResults sets the step results for status function evaluation.

type GitHubEnvFile

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

GitHubEnvFile handles the GITHUB_ENV file for a job.

func NewGitHubEnvFile

func NewGitHubEnvFile(jobInstanceID string) *GitHubEnvFile

NewGitHubEnvFile creates a new GitHubEnvFile for a job.

func (*GitHubEnvFile) EnsureDir

func (f *GitHubEnvFile) EnsureDir() error

EnsureDir creates the directory for the file.

func (*GitHubEnvFile) Path

func (f *GitHubEnvFile) Path() string

Path returns the path to the GITHUB_ENV file.

func (*GitHubEnvFile) ReadAndParse

func (f *GitHubEnvFile) ReadAndParse() (map[string]string, error)

ReadAndParse reads the GITHUB_ENV file, parses it, and returns the parsed variables. It also truncates the file to avoid reapplying values. Supports both single-line (KEY=value) and multiline (KEY<<DELIMITER ... DELIMITER) formats.

func (*GitHubEnvFile) Write

func (f *GitHubEnvFile) Write(key, value string) error

Write writes a key-value pair to the GITHUB_ENV file. Supports both single-line and multiline formats.

type GitHubOutputFile

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

GitHubOutputFile handles the GITHUB_OUTPUT file for a step.

func NewGitHubOutputFile

func NewGitHubOutputFile(jobInstanceID, stepID string) *GitHubOutputFile

NewGitHubOutputFile creates a new GitHubOutputFile for a step.

func (*GitHubOutputFile) EnsureDir

func (f *GitHubOutputFile) EnsureDir() error

EnsureDir creates the directory for the file.

func (*GitHubOutputFile) Path

func (f *GitHubOutputFile) Path() string

Path returns the path to the GITHUB_OUTPUT file.

func (*GitHubOutputFile) ReadAndParse

func (f *GitHubOutputFile) ReadAndParse() (map[string]string, error)

ReadAndParse reads the GITHUB_OUTPUT file, parses it, and returns the outputs.

func (*GitHubOutputFile) Write

func (f *GitHubOutputFile) Write(key, value string) error

Write writes a key-value pair to the GITHUB_OUTPUT file. Supports both single-line and multiline formats.

type GitHubPathFile

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

GitHubPathFile handles the GITHUB_PATH file for a job.

func NewGitHubPathFile

func NewGitHubPathFile(jobInstanceID string) *GitHubPathFile

NewGitHubPathFile creates a new GitHubPathFile for a job.

func (*GitHubPathFile) EnsureDir

func (f *GitHubPathFile) EnsureDir() error

EnsureDir creates the directory for the file.

func (*GitHubPathFile) Path

func (f *GitHubPathFile) Path() string

Path returns the path to the GITHUB_PATH file.

func (*GitHubPathFile) ReadAndParse

func (f *GitHubPathFile) ReadAndParse() ([]string, error)

ReadAndParse reads the GITHUB_PATH file, parses it, and returns the paths. It also truncates the file to avoid reapplying values.

func (*GitHubPathFile) Write

func (f *GitHubPathFile) Write(path string) error

Write writes a path to the GITHUB_PATH file.

type JobNeedsData

type JobNeedsData struct {
	Result   string
	Outputs  map[string]string
	IsMatrix bool
}

JobNeedsData contains the aggregated result and resolved outputs of a needed job.

type JobResult

type JobResult struct {
	JobID    string
	Steps    []*StepResult
	ExitCode int
	Error    error
	Status   Status
	Outputs  map[string]string
}

JobResult represents the result of executing a job.

type JobRunner

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

JobRunner handles execution of jobs within Docker containers.

func NewJobRunner

func NewJobRunner(cli *client.Client, offline bool, platform string, crlf string) *JobRunner

NewJobRunner creates a new job runner.

func (*JobRunner) RunJob

func (jr *JobRunner) RunJob(ctx context.Context, job workflow.Job, jobID string, workflowEnv map[string]string, workflowDefaults *workflow.Defaults, wf *workflow.Workflow, workspacePath string, needsCtx map[string]JobNeedsData) (*JobResult, error)

RunJob executes a job in a Docker container.

type JobStatus

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

JobStatus represents the current job execution status.

type RunConfig

type RunConfig struct {
	WorkflowPath  string
	Job           string
	DryRun        bool
	Parallel      int
	CRLF          string
	Platform      string
	Offline       bool
	TimeoutConfig TimeoutConfig
}

RunConfig holds configuration for a workflow run.

type Runner

type Runner interface {
	// RunWorkflow executes a workflow and returns the result.
	RunWorkflow(ctx context.Context, wf *workflow.Workflow) (*WorkflowResult, error)

	// RunJob executes a single job and returns the result.
	RunJob(ctx context.Context, job workflow.Job, jobID string, workflowEnv map[string]string, workflowDefaults *workflow.Defaults, wf *workflow.Workflow) (*JobResult, error)
}

Runner defines the interface for running workflows.

type ShellResolver

type ShellResolver struct {
	WorkflowDefaults *workflow.Defaults
	JobDefaults      *workflow.Defaults
}

ShellResolver provides shell resolution with precedence logic.

func NewShellResolver

func NewShellResolver(workflowDefaults, jobDefaults *workflow.Defaults) *ShellResolver

NewShellResolver creates a new shell resolver.

func (*ShellResolver) Resolve

func (sr *ShellResolver) Resolve(step workflow.Step) string

Resolve returns the shell to use for a step, with precedence: step.shell > job.defaults.run.shell > workflow.defaults.run.shell > "bash"

type Status

type Status string

Status represents the execution status of a step, job, or workflow.

const (
	// StatusPending indicates the item has not started yet.
	StatusPending Status = "pending"
	// StatusRunning indicates the item is currently executing.
	StatusRunning Status = "running"
	// StatusSuccess indicates the item completed successfully.
	StatusSuccess Status = "success"
	// StatusFailure indicates the item failed.
	StatusFailure Status = "failure"
	// StatusCancelled indicates the item was cancelled.
	StatusCancelled Status = "cancelled"
	// StatusSkipped indicates the item was skipped.
	StatusSkipped Status = "skipped"
)

func AggregateJobResults

func AggregateJobResults(instanceResults []*JobResult) Status

AggregateJobResults aggregates job instance results per original job ID.

type StepOutputs

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

StepOutputs stores outputs from steps for expression interpolation.

func NewStepOutputs

func NewStepOutputs() *StepOutputs

NewStepOutputs creates a new StepOutputs store.

func (*StepOutputs) GetOutput

func (so *StepOutputs) GetOutput(stepID, key string) (string, bool)

GetOutput returns a specific output value for a step.

func (*StepOutputs) GetOutputs

func (so *StepOutputs) GetOutputs(stepID string) map[string]string

GetOutputs returns the outputs for a step.

func (*StepOutputs) SetOutputs

func (so *StepOutputs) SetOutputs(stepID string, outputs map[string]string)

SetOutputs sets the outputs for a step.

type StepResult

type StepResult struct {
	ExitCode        int
	Stdout          string
	Stderr          string
	Status          Status
	Outcome         Status // Raw outcome before continue-on-error
	Conclusion      Status // Final conclusion after continue-on-error
	ContinueOnError bool
}

StepResult represents the result of executing a step.

type StepRunner

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

StepRunner handles execution of individual steps within a job container.

func NewStepRunner

func NewStepRunner(cli *client.Client, containerID, workingDir string, crlf string) *StepRunner

NewStepRunner creates a new step runner for a job container.

func (*StepRunner) RunStep

func (sr *StepRunner) RunStep(ctx context.Context, step workflow.Step, jobEnv map[string]string, shell, workingDir string, githubOutputFile *GitHubOutputFile, exprContext *ExpressionContext, jobTimeout, stepTimeout time.Duration) (*StepResult, error)

RunStep executes a single step and returns the result.

func (*StepRunner) SetSecrets

func (sr *StepRunner) SetSecrets(secrets []string)

SetSecrets sets the secret values to mask in step output.

type TimeoutConfig

type TimeoutConfig struct {
	JobTimeout  time.Duration
	StepTimeout time.Duration
	DefaultJob  time.Duration
	DefaultStep time.Duration
}

TimeoutConfig holds timeout configuration for job/step execution.

func DefaultTimeoutConfig

func DefaultTimeoutConfig() TimeoutConfig

DefaultTimeoutConfig returns sensible defaults for timeouts.

func (*TimeoutConfig) GetEffectiveJobTimeout

func (tc *TimeoutConfig) GetEffectiveJobTimeout(jobTimeout time.Duration) time.Duration

GetEffectiveJobTimeout returns the effective timeout for a job. Uses default if not set.

func (*TimeoutConfig) GetEffectiveStepTimeout

func (tc *TimeoutConfig) GetEffectiveStepTimeout(jobTimeout, stepTimeout time.Duration) time.Duration

GetEffectiveStepTimeout returns the effective timeout for a step. Step timeout overrides job timeout. If neither is set, uses default.

type UnsupportedError

type UnsupportedError struct {
	Message  string
	ExitCode int
}

UnsupportedError represents an error for unsupported features with exit code 3.

func NewUnsupportedError

func NewUnsupportedError(msg string) *UnsupportedError

NewUnsupportedError creates a new UnsupportedError with exit code 3.

func (*UnsupportedError) Code

func (e *UnsupportedError) Code() int

func (*UnsupportedError) Error

func (e *UnsupportedError) Error() string

type WorkflowResult

type WorkflowResult struct {
	Jobs     map[string]*JobResult
	JobOrder []string
	ExitCode int
	Error    error
	Status   Status
}

WorkflowResult represents the result of executing a workflow.

type WorkflowRunner

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

WorkflowRunner handles execution of workflows including job dependency ordering.

func NewWorkflowRunner

func NewWorkflowRunner(jobRunner *JobRunner, offline bool) *WorkflowRunner

NewWorkflowRunner creates a new WorkflowRunner.

func (*WorkflowRunner) RunWorkflow

func (wr *WorkflowRunner) RunWorkflow(
	ctx context.Context,
	wf *workflow.Workflow,
	expandedWf *workflow.Workflow,
	workspacePath string,
	workflowEnv map[string]string,
	jobFilter string,
	parallel int,
) (*WorkflowResult, error)

RunWorkflow runs a workflow with parallel job execution for unblocked jobs.

Jump to

Keyboard shortcuts

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