reporter

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package reporter formats engine events for the user. Two sinks are provided: pretty (human, default) and json (one event per line, for scripting).

Index

Constants

View Source
const (
	StatusSucceeded   = "succeeded"
	StatusFailed      = "failed"
	StatusInfraFailed = "infrafailed"
	StatusSkipped     = "skipped"
	StatusNotRun      = "not-run"
	StatusTimeout     = "timeout"
)

Status values that can appear on task-end. Existing values are unchanged; "timeout" is new in v1.2.

Variables

This section is empty.

Functions

func ResolveColor added in v1.2.0

func ResolveColor(mode ColorMode, isTerminal bool, env func(string) (string, bool)) bool

ResolveColor decides whether to emit ANSI codes.

Precedence (highest first):

  1. mode = Always or Never — explicit user choice wins.
  2. NO_COLOR env (any non-empty value) — disables color, per https://no-color.org.
  3. FORCE_COLOR or CLICOLOR_FORCE (any non-empty value) — enables color.
  4. mode = Auto — color iff isTerminal.

env is the lookup function (typically os.LookupEnv) so this can be tested without touching process state.

Types

type ColorMode added in v1.2.0

type ColorMode int

ColorMode is how the user requested coloring be decided.

const (
	ColorAuto   ColorMode = iota // honor TTY + env
	ColorAlways                  // always emit ANSI
	ColorNever                   // never emit ANSI
)

func ParseColorMode added in v1.2.0

func ParseColorMode(s string) (ColorMode, error)

ParseColorMode accepts auto|always|never (case-insensitive). Empty string maps to ColorAuto.

type Event

type Event struct {
	Kind     EventKind     `json:"kind"`
	Time     time.Time     `json:"time"`
	RunID    string        `json:"runId,omitempty"`
	Pipeline string        `json:"pipeline,omitempty"`
	Task     string        `json:"task,omitempty"`
	Step     string        `json:"step,omitempty"`
	Stream   string        `json:"stream,omitempty"` // stdout|stderr
	Line     string        `json:"line,omitempty"`
	Status   string        `json:"status,omitempty"`
	ExitCode int           `json:"exitCode,omitempty"`
	Duration time.Duration `json:"durationMs,omitempty"`
	Message  string        `json:"message,omitempty"`
	// Attempt is 1-based and present on task-retry (the attempt that just
	// failed) and on task-end (the attempt that produced the final outcome).
	Attempt int `json:"attempt,omitempty"`
	// Results holds resolved Pipeline.spec.results on a run-end event.
	// Map values are one of: string, []string, map[string]string. Empty
	// or nil when the pipeline declared no results.
	Results map[string]any `json:"results,omitempty"`
	// DisplayName is the human-readable label for the entity this event
	// describes. Carried on:
	//   - run-start, run-end:    Pipeline.spec.displayName
	//   - task-start/end/skip/retry: PipelineTask.displayName
	//   - step-log:              Step.displayName
	// Empty when the source YAML didn't set a displayName. Agents
	// should fall back to the corresponding `pipeline` / `task` / `step`
	// name field.
	//
	// Note: step-start / step-end are defined as event kinds but are
	// not emitted by production code today (v1.5). If they are added
	// later, they will carry DisplayName the same way step-log does.
	DisplayName string `json:"display_name,omitempty"`

	// Description carries:
	//   - run-start: Pipeline.spec.description
	//   - task-start: TaskSpec.description (the resolved Task)
	// Omitted from terminal events to keep line size down — the start
	// event already carried it. Also omitted from step-log to avoid
	// ballooning every line of streamed output.
	Description string `json:"description,omitempty"`

	// Resolver names the resolver protocol (git | hub | http | bundles |
	// cluster | <custom-in-remote-mode>).
	Resolver string `json:"resolver,omitempty"`
	// Cached is true when resolver-end fires for a per-run cache hit
	// (no fresh fetch happened). Surfaces in pretty output as "(cached)".
	Cached bool `json:"cached,omitempty"`
	// SHA256 is the hex digest of the resolved bytes. Used by the
	// on-disk cache invalidation diagnostics; agents can compare across
	// runs to detect upstream drift.
	SHA256 string `json:"sha256,omitempty"`
	// Source is a human-readable origin string for the resolver (e.g.
	// "git: github.com/tektoncd/catalog@abc123 -> task/...").
	Source string `json:"source,omitempty"`

	// Matrix is set on task-start / task-end / task-skip events
	// emitted from a PipelineTask.matrix expansion. Nil for
	// ordinary tasks (omitempty). Carries the original PipelineTask
	// name (Parent), the 0-based row index, the total expansion
	// count, and the row's matrix-contributed params.
	Matrix *MatrixEvent `json:"matrix,omitempty"`
}

type EventKind

type EventKind string
const (
	EvtRunStart  EventKind = "run-start"
	EvtRunEnd    EventKind = "run-end"
	EvtTaskStart EventKind = "task-start"
	EvtTaskEnd   EventKind = "task-end"
	EvtTaskSkip  EventKind = "task-skip"
	EvtTaskRetry EventKind = "task-retry"
	EvtStepStart EventKind = "step-start"
	EvtStepEnd   EventKind = "step-end"
	EvtStepLog   EventKind = "step-log"
	// Sidecar events surface long-lived helper containers' lifecycle
	// on the JSON event stream. The Step field carries the sidecar
	// name (no dedicated payload field — agents that need the
	// disambiguation can branch on Kind or Stream).
	EvtSidecarStart  EventKind = "sidecar-start"
	EvtSidecarEnd    EventKind = "sidecar-end"
	EvtSidecarLog    EventKind = "sidecar-log"
	EvtError         EventKind = "error"
	EvtResolverStart EventKind = "resolver-start"
	EvtResolverEnd   EventKind = "resolver-end"
)

type LogSink

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

LogSink is the engine-facing log forwarder; reporters expose this so the backend interface stays decoupled from the reporter type.

func NewLogSink

func NewLogSink(r Reporter) *LogSink

func (*LogSink) EmitSidecarEnd added in v1.6.0

func (s *LogSink) EmitSidecarEnd(taskName, sidecarName string, exitCode int, status, message string)

EmitSidecarEnd fires the terminal EvtSidecarEnd for a sidecar. status mirrors the Task* enum (succeeded / failed / infrafailed).

func (*LogSink) EmitSidecarStart added in v1.6.0

func (s *LogSink) EmitSidecarStart(taskName, sidecarName string)

EmitSidecarStart fires an EvtSidecarStart for the named sidecar. Backends that need to surface sidecar lifecycle on the JSON event stream (the docker backend; the cluster backend's pod-watch loop) invoke this directly. Reuses Event.Step for the sidecar name and sets Stream = "sidecar".

func (*LogSink) Reporter added in v1.6.0

func (s *LogSink) Reporter() Reporter

Reporter exposes the wrapped reporter so callers that need to emit non-log events (e.g. the cluster backend's matrix-fallback warning) can do so without taking a separate dependency on the reporter type. Returns nil when the LogSink was constructed without a backing reporter.

func (*LogSink) SidecarLog added in v1.6.0

func (s *LogSink) SidecarLog(taskName, sidecarName, stream, line string)

SidecarLog forwards a sidecar's stdout/stderr line as an EvtSidecarLog event. The sidecar name lands in Event.Step (reused from the step contract) and stream is one of "sidecar-stdout" / "sidecar-stderr" — never plain "stdout" / "stderr" — so consumers can attribute the line to a sidecar without re-parsing.

func (*LogSink) StepLog

func (s *LogSink) StepLog(taskName, stepName, stepDisplayName, stream, line string)

type MatrixEvent added in v1.6.0

type MatrixEvent struct {
	Parent string            `json:"parent"`
	Index  int               `json:"index"`
	Of     int               `json:"of"`
	Params map[string]string `json:"params,omitempty"`
}

MatrixEvent identifies one expansion of a matrix-fanned PipelineTask. Parent is the original PipelineTask name; Index is the 0-based row index in the expansion order; Of is the total number of expansions of this Parent; Params holds the row's matrix-contributed params (string-keyed string values). The engine constructs this from tektontypes.MatrixInfo before emitting the event.

type PrettyOptions added in v1.2.0

type PrettyOptions struct {
	Color     bool      // already resolved via ResolveColor
	Verbosity Verbosity // Quiet | Normal | Verbose
}

PrettyOptions configures NewPretty.

type Reporter

type Reporter interface {
	Emit(e Event)
	Close() error
}

Reporter consumes events.

func NewJSON

func NewJSON(w io.Writer) Reporter

func NewPretty

func NewPretty(w io.Writer, opt PrettyOptions) Reporter

NewPretty returns a Reporter that prints human-readable, live-ordered output. Step logs stream as they arrive, prefixed with their task and step names so parallel runs remain readable.

type Tee

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

Tee writes each event to all underlying reporters.

func NewTee

func NewTee(rs ...Reporter) *Tee

func (*Tee) Close

func (t *Tee) Close() error

func (*Tee) Emit

func (t *Tee) Emit(e Event)

type Verbosity added in v1.2.0

type Verbosity int

Verbosity controls how much the pretty reporter prints.

Quiet  → final task + run summaries only
Normal → pipeline header + live step logs + task/run summaries (default)
Verbose → adds step-start/step-end markers
const (
	Quiet   Verbosity = -1
	Normal  Verbosity = 0
	Verbose Verbosity = 1
)

Jump to

Keyboard shortcuts

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