run

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 28 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package run is the `bitc run` pipeline (spec 6) and the local runner.

Index

Constants

This section is empty.

Variables

View Source
var NoProviderLeft func(pool string, last error) error

NoProviderLeft maps the last provider failure to 69 or 75 (set by internal/remote).

View Source
var RemoteWalk func(ctx context.Context, inv Invocation, p *Prepared, provider string, stderr io.Writer) (Outcome, bool, error)

RemoteWalk runs a remote provider (internal/remote sets it). handled=false means "try the next"; err is then this provider's failure, for the no-provider-left rule.

Functions

func ApplyHookEnv

func ApplyHookEnv(env []string, kv []KV, bitc []string) []string

ApplyHookEnv applies env-hook output, then re-asserts the BITC_* variables.

func BaseEnv

func BaseEnv(in EnvInput) ([]string, error)

BaseEnv: caller env, minus [defaults].env_unset; env_default for unset keys; env; minus the pool's env_unset; then the BITC_* variables (spec 6.3). Host and repo already merged (5.3).

func BitcVars

func BitcVars(in EnvInput) []string

BitcVars are set last and re-asserted after the env hook.

func Debugf

func Debugf(p *Prepared, w io.Writer, format string, a ...any)

Debugf prints a "bitc: debug:" line at log level debug (BITC_LOG=debug or -v).

func Main

func Main(ctx context.Context, inv Invocation) int

Main runs the whole pipeline in the foreground.

func TemplateVars

func TemplateVars(eff *config.Effective, pool *config.Pool, hold *admit.Hold, job string) config.Vars

TemplateVars are [vars] plus {pool} and {job}; with a hold also the host-only variables.

func WrapArgv

func WrapArgv(eff *config.Effective, pool *config.Pool, vars config.Vars, argv []string) ([]string, error)

WrapArgv prefixes the first wrap rule whose when_worktree matches the work tree (spec 6.5). It always returns a new slice, never argv itself, so a caller may change the result without touching argv (and the reverse).

func WriteResult

func WriteResult(path string, r Result) error

WriteResult writes r atomically (temp + rename, 0600).

Types

type EnvInput

type EnvInput struct {
	Caller []string
	Eff    *config.Effective
	Pool   *config.Pool
	Hold   *admit.Hold
	Job    string
	Vars   config.Vars
}

EnvInput is everything the job's environment derives from (spec 6.3).

type ExecResult

type ExecResult struct {
	Code        int            // the command's code, 128+N if it died of signal N, or 128+N after terminate
	Interrupted syscall.Signal // the signal bitc received, 0 if none
	StartErr    error          // the command could not start (Code 126 or 127)
}

ExecResult is how the command ended.

func Exec

func Exec(ctx context.Context, s ExecSpec) (ExecResult, error)

Exec runs the command as bitc's child and returns how it ended (spec 6.4).

type ExecSpec

type ExecSpec struct {
	Argv          []string
	Env           []string
	Dir           string
	Stdin         *os.File
	Stdout        *os.File
	Stderr        *os.File
	OnSignal      string // "terminate" | "forward-and-wait"
	Grace         time.Duration
	MaxSignalWait time.Duration
	Started       func(pid, pgid int, leaderStart uint64)
	Pending       chan os.Signal // optional: a channel the caller registered; Exec takes it over
	NoHangup      bool           // detached supervisor (spec 7): SIGHUP is neither handled nor forwarded
}

ExecSpec is one command run under a hold (spec 6.4).

type HookCall

type HookCall struct {
	Kind     HookKind
	Hook     config.Hook
	Pool     string
	Vars     config.Vars
	Env      []string
	Worktree string
	Stderr   io.Writer
}

HookCall is one hook invocation.

type HookKind

type HookKind string

HookKind names the pipeline step a hook runs at (spec 6.5).

const (
	PreRun  HookKind = "pre_run"
	EnvHook HookKind = "env"
	PostRun HookKind = "post_run"
)

type Invocation

type Invocation struct {
	Flags  config.Flags
	Args   []string
	Stdin  *os.File
	Stdout *os.File
	Stderr *os.File
	Env    []string
	Cwd    string
	// Detached is the supervisor's replay (spec 7): SIGHUP is neither a cancel nor forwarded.
	Detached bool
	// Pending, if set, is the supervisor's early signal channel; runLocal takes it over.
	Pending chan os.Signal
}

Invocation is one `bitc run` call (or the supervisor's replay of one).

type KV

type KV struct{ Name, Value string }

KV is one NAME=VALUE pair from an env hook.

func ParseEnvOutput

func ParseEnvOutput(b []byte) ([]KV, error)

ParseEnvOutput parses env-hook output (spec 6.5): one [export ]NAME=VALUE per line, blank and # lines skipped. VALUE concatenates unquoted chars (not blanks, control characters or ' " \ $ ` ; & | < > ( )), '...' literals and "..." with only \" \\ \` \$ escapes. No form admits a control character (< 0x20 or 0x7f). Never evaluated. A CR is a control character, so CRLF output is unparsable.

func RunHook

func RunHook(ctx context.Context, c HookCall) ([]KV, error)

RunHook runs a hook argv with the job's env, cwd = work-tree top, stdin /dev/null and its timeout, and maps the result (spec 6.5).

type Outcome

type Outcome struct {
	Code   int
	Result Result
}

Outcome is the final exit code and result.json content.

func Execute

func Execute(ctx context.Context, inv Invocation, p *Prepared, stderr io.Writer) Outcome

Execute runs step 6 (provider walk) and, for local, steps 7-11.

type Prepared

type Prepared struct {
	Args   RunArgs
	Eff    *config.Effective
	Pool   *config.Pool
	Layout state.Layout
	Job    string
	Redact *redact.Set
}

Prepared is what steps 1-4 decided.

func Prepare

func Prepare(inv Invocation, red *redact.Set) (*Prepared, error)

Prepare runs steps 1-4: parse, load and merge config, narrow, resolve the pool, refuse rules. Credentials join red as soon as the config loads.

func (*Prepared) InfoWriter

func (p *Prepared) InfoWriter(w io.Writer) io.Writer

InfoWriter is w, or io.Discard under BITC_LOG=quiet. Only informational lines use it.

type Result

type Result struct {
	Origin      string `json:"origin"`  // "bitc" | "command"
	Outcome     string `json:"outcome"` // ok | command-failed | starved | refused | config | unavailable | interrupted | lost | internal
	ExitCode    int    `json:"exit_code"`
	Reason      string `json:"reason,omitempty"`
	Pool        string `json:"pool"`
	Slot        int    `json:"slot,omitempty"`
	Provider    string `json:"provider"`
	Job         string `json:"job"`
	Generation  int    `json:"generation,omitempty"`
	HoldStarted string `json:"hold_started,omitempty"`
	WaitMS      int64  `json:"wait_ms"`
	RunMS       int64  `json:"run_ms"`
}

Result is result.json (spec 4).

type RunArgs

type RunArgs struct {
	Detach    bool
	Name      string
	Log       string
	Wait      string
	Local     bool
	Provider  string
	Artifacts *[]string
	Result    string
	Pool      string
	Argv      []string
}

RunArgs are the parsed `bitc run` arguments (spec 3.1). Values stay raw; the config layer validates them (5.2).

func ParseRunArgs

func ParseRunArgs(args []string) (RunArgs, error)

ParseRunArgs parses flags (before <pool>), the pool, an optional "--" and the argv.

type Signalled

type Signalled syscall.Signal

Signalled is a context cause: the run was cancelled as if by this signal (`cancel --kill`).

func (Signalled) Error

func (s Signalled) Error() string

Jump to

Keyboard shortcuts

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