events

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package events defines the typed, versioned protocol the CI runner speaks to the server: the lifecycle of a multi-stack Terraform execution (init → phase → per-stack updates → finalize) plus the apply-time gate exchange. One module, one version — the runner baked into a CI image and the deployed server share these types, so they can never disagree about event shapes.

Index

Constants

View Source
const Version = 1

Version is the protocol version. Bump on any breaking change to the payloads below; runner and server are expected to share the same module version.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category added in v0.6.0

type Category = domain.Category

Category is a classification label matched by a stack. Alias of the canonical domain type (carries Name/Icon and, additively, emitted Attributes).

type Claim added in v0.15.0

type Claim struct {
	Environment string    `json:"environment"`
	StackPath   string    `json:"stack_path"`
	OwnerPR     int       `json:"owner_pr"`
	ExpiresAt   time.Time `json:"expires_at"`
}

Claim is one apply-lock claim row, mirroring store.Claim over the wire for the /api/claims/list endpoint.

type Counts added in v0.11.0

type Counts = domain.Counts

Counts is a stack's per-kind operation tally. Alias of the canonical domain type so the runner and server share one definition with the render pipeline.

type Edge

type Edge struct {
	From string `json:"from"`
	To   string `json:"to"`
}

Edge is a dependency: From must run before To.

type Finalize

type Finalize struct {
	ID             string                `json:"id"`
	ReportMarkdown string                `json:"report_markdown"`
	Projects       map[string]string     `json:"projects,omitempty"`      // stack path → grouping/target key
	StackReports   map[string]string     `json:"stack_reports,omitempty"` // stack path → rendered plan section
	Gates          []GateTarget          `json:"gates,omitempty"`         // (class,target) pairs needing approval
	Moving         []string              `json:"moving,omitempty"`        // stack paths adopting resources via a cross-state move
	Failed         bool                  `json:"failed,omitempty"`
	Categories     map[string][]Category `json:"categories,omitempty"` // stack path → matched categories
	Counts         map[string]Counts     `json:"counts,omitempty"`     // stack path → op counts
}

Finalize records the terminal plan state: the rendered report, per-stack target backfill, the gates that must be approved, and the moving/failed flags.

type GateCheck

type GateCheck struct {
	PR          int    `json:"pr"`
	Environment string `json:"environment"`
}

GateCheck is the apply-time gate pre-check (fail-closed): is every required gate for this (PR, environment) approved?

type GateRevoke

type GateRevoke struct {
	PR          int    `json:"pr"`
	Environment string `json:"environment"`
}

GateRevoke asks the server to revoke the grants it requested for this (PR, environment) — best-effort post-apply cleanup.

type GateTarget

type GateTarget struct {
	Class  string `json:"class"`
	Target string `json:"target"`
}

GateTarget names one thing that must be approved: a classification class (e.g. "iam") against a target (e.g. a cloud project/account). Generalises the single implicit IAM/project gate into (class, target) pairs so multiple approval classes are accommodated from the start.

type Graph

type Graph struct {
	Stacks []StackState `json:"stacks"`
	Edges  []Edge       `json:"edges"`
}

Graph is the changed subgraph for one execution.

type Init

type Init struct {
	ID          string       `json:"id"`
	Repo        string       `json:"repo"`
	SHA         string       `json:"sha"`
	PR          int          `json:"pr"`
	Environment string       `json:"environment"`
	LogURL      string       `json:"log_url"`           // CI log deep-link, shown on failures
	Context     string       `json:"context,omitempty"` // commit-status context this run drives
	Stacks      []StackState `json:"stacks"`
	Edges       []Edge       `json:"edges"`
}

Init registers an execution and its changed subgraph.

type LogChunk added in v0.6.0

type LogChunk struct {
	ID    string `json:"id"`
	Stack string `json:"stack"`
	Data  string `json:"data"`
}

LogChunk is a slice of one stack's combined output, streamed during execution.

type Phase

type Phase string

Phase is the execution-wide lifecycle phase, narrated before and across the per-stack work.

const (
	PhaseWarming      Phase = "warming"      // warming the provider plugin cache
	PhaseLinting      Phase = "linting"      // static lint (e.g. tflint) over modules
	PhaseInitializing Phase = "initializing" // sequential terraform init
	PhasePlanning     Phase = "planning"     // parallel plan
	PhaseApplying     Phase = "applying"     // sequential apply
	PhaseTesting      Phase = "testing"      // post-apply contract tests
	PhaseVerifying    Phase = "verifying"    // post-apply verification
)

func (Phase) Ticking added in v0.16.0

func (p Phase) Ticking() bool

Ticking reports whether a phase advances per-stack (k/N sub-progress) rather than being an instantaneous marker. The progress bar sub-fills a ticking phase's weighted band by completed/total; marker phases jump to their band.

func (Phase) Valid added in v0.16.0

func (p Phase) Valid() bool

Valid reports whether p is a known lifecycle phase.

type PhaseEvent

type PhaseEvent struct {
	ID          string `json:"id"`
	Repo        string `json:"repo,omitempty"`
	SHA         string `json:"sha,omitempty"`
	PR          int    `json:"pr,omitempty"`
	Environment string `json:"environment,omitempty"`
	LogURL      string `json:"log_url,omitempty"`
	Context     string `json:"context,omitempty"`
	Phase       Phase  `json:"phase"`
}

PhaseEvent narrates a lifecycle phase transition (may arrive before Init).

type StackState

type StackState struct {
	Path       string     `json:"path"`
	Project    string     `json:"project,omitempty"` // grouping/target key (e.g. cloud project/account)
	Status     Status     `json:"status,omitempty"`
	Detail     string     `json:"detail,omitempty"`     // optional failure detail (last error lines)
	Categories []Category `json:"categories,omitempty"` // matched classification categories
	Counts     *Counts    `json:"counts,omitempty"`     // per-kind op tally (nil until finalize)
}

StackState is one node in the execution graph.

type Status

type Status string

Status is the lifecycle of a single stack within an execution.

const (
	StatusPending      Status = "pending"      // intends to run
	StatusInitializing Status = "initializing" // terraform init running for this stack
	StatusInitialized  Status = "initialized"  // init done, awaiting plan
	StatusRunning      Status = "running"      // running now
	StatusPlanned      Status = "planned"      // plan done, no gate required
	StatusGated        Status = "gated"        // blocked on an approval gate
	StatusSafe         Status = "safe"         // approved / applied with changes / clean
	StatusNochange     Status = "nochange"     // applied, terraform reported 0 changes
	StatusMoving       Status = "moving"       // adopting resources via a cross-state move (non-gating)
	StatusFailed       Status = "failed"       // this stack errored
	StatusAborted      Status = "aborted"      // run failed elsewhere; this stack never reached a terminal tick
)

func AllStatuses added in v0.17.0

func AllStatuses() []Status

AllStatuses lists every known stack status. Retained as public API: the test suite validates all members via this, and docs/consumers enumerate statuses from it.

func ParseStatus added in v0.17.0

func ParseStatus(raw string) (Status, error)

ParseStatus validates a raw wire string into a Status, returning a coded (WIRE-001) error for an unknown non-empty value.

func (*Status) UnmarshalJSON added in v0.17.0

func (s *Status) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes a JSON string and validates it, so an unknown status in an untrusted payload fails fast at the wire boundary rather than entering the system silently. (The store does not decode status via JSON — it scans the column directly — so persisted values are never re-validated here.)

func (Status) Valid added in v0.17.0

func (s Status) Valid() bool

Valid reports whether s is a known stack status. The empty status (zero value / unset) is treated as valid so omitted fields decode cleanly.

type Update

type Update struct {
	ID     string `json:"id"`
	Stack  string `json:"stack"`
	Status Status `json:"status"`
	Detail string `json:"detail,omitempty"`
}

Update ticks a single stack's status.

Jump to

Keyboard shortcuts

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