Documentation
¶
Overview ¶
Package chain provides workflow chain execution and template interpolation.
Index ¶
- Variables
- func ExportAsBash(chainName string, chain *config.Chain, variables map[string]string, ...) string
- func Interpolate(template string, ctx *InterpolationContext) (string, error)
- func InterpolateInputs(inputs map[string]string, ctx *InterpolationContext) (map[string]string, error)
- func ResolveExistingRun(client GitHubClient, workflow, branch string) (*github.WorkflowRun, error)
- type ChainExecutor
- type ChainState
- type ChainStatus
- type ChainUpdate
- type Dispatcher
- type ExistingRunResolver
- type GitHubClient
- type InterpolationContext
- type Option
- type PreviousStepResult
- type ResolvedStep
- type RunWatcher
- type StepResult
- type StepStatus
Constants ¶
This section is empty.
Variables ¶
var ErrChainExecutionStopped = errors.New("chain execution stopped")
ErrChainExecutionStopped indicates the chain was stopped while waiting for a run.
var ErrNoExistingRun = errors.New("no queued or in-progress run found")
ErrNoExistingRun indicates a source: existing step found no queued or in-progress run of its workflow on the branch to adopt.
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.
func ResolveExistingRun ¶ added in v1.12.0
func ResolveExistingRun(client GitHubClient, workflow, branch string) (*github.WorkflowRun, error)
ResolveExistingRun asks GitHub for the newest in-progress or queued run of workflow on branch. It never falls back to dispatching.
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, opts ...Option, ) *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 Dispatcher ¶ added in v1.8.0
type Dispatcher func(cfg runner.RunConfig, client GitHubClient) (int64, error)
Dispatcher starts one workflow and reports the run it started.
The executor holds one rather than calling the runner directly, because the dispatch is the one step a test cannot take: internal/exec's mutation guard panics on `gh workflow run`, so the branch and failure handling around it were unreachable while the call was hard-wired.
type ExistingRunResolver ¶ added in v1.12.0
type ExistingRunResolver func(client GitHubClient, workflow, branch string) (*github.WorkflowRun, error)
ExistingRunResolver finds the run a source: existing step should adopt, rather than dispatching a fresh one.
type GitHubClient ¶
type GitHubClient interface {
GetWorkflowRun(runID int64) (*github.WorkflowRun, error)
GetWorkflowRunJobs(runID int64) ([]github.Job, error)
GetLatestRun(workflowName string) (*github.WorkflowRun, error)
ListRuns(q github.RunQuery) ([]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 Option ¶ added in v1.8.0
type Option func(*ChainExecutor)
Option configures an executor.
func WithDispatcher ¶ added in v1.8.0
func WithDispatcher(d Dispatcher) Option
WithDispatcher replaces how a step starts its workflow.
func WithExistingRunResolver ¶ added in v1.12.0
func WithExistingRunResolver(r ExistingRunResolver) Option
WithExistingRunResolver replaces how a source: existing step finds the run to adopt.
func WithPollInterval ¶ added in v1.8.0
WithPollInterval sets how often a step waiting on a run asks about it.
type PreviousStepResult ¶
PreviousStepResult contains the result of a previously completed step.
type ResolvedStep ¶ added in v1.2.1
type ResolvedStep struct {
Inputs map[string]string
// Err is the interpolation failure, if the step had one. A preview renders
// it and carries on; only the executor treats it as fatal.
Err error
Workflow string
// Command is the gh dispatch command a dispatch-source step runs. Empty
// for a source: existing step, which adopts a run instead of starting one.
Command string
Source config.SourceKind
}
ResolvedStep is one chain step with its templates interpolated and the gh command it dispatches. Building it once is what keeps the preview modal, the bash export, and the command list a chain records in history agreeing with what ChainExecutor actually runs.
func ResolveSteps ¶ added in v1.2.1
ResolveSteps interpolates every step's inputs in order, so a step's `previous` names the step directly above it.
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.