chain

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package chain provides workflow chain execution and template interpolation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExportAsBash

func ExportAsBash(chainName string, chain *config.Chain, variables map[string]string, branch string) string

ExportAsBash generates a bash script from a chain definition. The script is lossy: it does not include wait conditions or failure handling.

func Interpolate

func Interpolate(template string, ctx *InterpolationContext) (string, error)

Interpolate replaces template expressions in a string. Supported expressions:

  • {{ var.key }} - Value from chain-level variables
  • {{ previous.inputs.key }} - Value from previous step's inputs
  • {{ steps.N.inputs.key }} - Value from step N's inputs (0-indexed)

func InterpolateInputs

func InterpolateInputs(inputs map[string]string, ctx *InterpolationContext) (map[string]string, error)

InterpolateInputs interpolates all values in an input map.

Types

type ChainExecutor

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

ChainExecutor manages the execution of a workflow chain.

func NewExecutor

func NewExecutor(client GitHubClient, w RunWatcher, chainName string, chain *config.Chain) *ChainExecutor

NewExecutor creates a new chain executor.

func NewExecutorFromHistory

func NewExecutorFromHistory(
	client GitHubClient,
	w RunWatcher,
	chainName string,
	chain *config.Chain,
	previousResults []PreviousStepResult,
	resumeFromStep int,
) *ChainExecutor

NewExecutorFromHistory creates a chain executor that resumes from a specific step. Steps 0..resumeFromStep-1 are pre-populated from previousResults.

func (*ChainExecutor) Start

func (e *ChainExecutor) Start(variables map[string]string, branch string) error

Start begins executing the chain with the given variables.

func (*ChainExecutor) State

func (e *ChainExecutor) State() ChainState

State returns the current chain state.

func (*ChainExecutor) Stop

func (e *ChainExecutor) Stop()

Stop stops the chain execution. Safe to call multiple times.

func (*ChainExecutor) Updates

func (e *ChainExecutor) Updates() <-chan ChainUpdate

Updates returns the channel for receiving chain updates.

type ChainState

type ChainState struct {
	Error        error
	StepResults  map[int]*StepResult
	ChainName    string
	Status       ChainStatus
	StepStatuses []StepStatus
	CurrentStep  int
}

ChainState represents the current state of a chain execution.

type ChainStatus

type ChainStatus string

ChainStatus represents the overall status of a chain execution.

const (
	ChainPending   ChainStatus = "pending"
	ChainRunning   ChainStatus = "running"
	ChainCompleted ChainStatus = "completed"
	ChainFailed    ChainStatus = "failed"
)

Overall chain execution statuses.

type ChainUpdate

type ChainUpdate struct {
	State ChainState
}

ChainUpdate is sent when the chain state changes.

type GitHubClient

type GitHubClient interface {
	GetWorkflowRun(runID int64) (*github.WorkflowRun, error)
	GetWorkflowRunJobs(runID int64) ([]github.Job, error)
	GetLatestRun(workflowName string) (*github.WorkflowRun, error)
	Owner() string
	Repo() string
}

GitHubClient defines the interface for GitHub API operations needed by the chain executor.

type InterpolationContext

type InterpolationContext struct {
	Var      map[string]string // chain-level variables (replaces Trigger)
	Previous *StepResult
	Steps    map[int]*StepResult
}

InterpolationContext provides values for template interpolation.

type PreviousStepResult

type PreviousStepResult struct {
	Workflow   string
	Status     string
	Conclusion string
	RunID      int64
}

PreviousStepResult contains the result of a previously completed step.

type RunWatcher

type RunWatcher interface {
	Watch(runID int64, workflowName string)
	Unwatch(runID int64)
	Updates() <-chan watcher.RunUpdate
}

RunWatcher defines the interface for watching workflow runs.

type StepResult

type StepResult struct {
	Inputs     map[string]string
	Workflow   string
	RunURL     string
	Status     StepStatus
	Conclusion string
	RunID      int64
}

StepResult represents the result of a completed step.

type StepStatus

type StepStatus string

StepStatus represents the status of a single step.

const (
	StepPending   StepStatus = "pending"
	StepRunning   StepStatus = "running"
	StepWaiting   StepStatus = "waiting"
	StepCompleted StepStatus = "completed"
	StepFailed    StepStatus = "failed"
	StepSkipped   StepStatus = "skipped"
)

Per-step execution statuses.

Jump to

Keyboard shortcuts

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