shell

package
v0.1.27 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultInterpreter string
View Source
var DefaultInterpreterArgs []string

Functions

func CreateCommandFromScript

func CreateCommandFromScript(ctx context.Context, script string) (*exec.Cmd, error)

CreateCommandFromScript creates an os/exec.Cmd from the script, using the interpreter specified in the shebang line if present.

func DetectDefaultInterpreter

func DetectDefaultInterpreter() (string, []string)

DetectDefaultInterpreter detects the default interpreter based on the OS.

func DetectInterpreterFromShebang

func DetectInterpreterFromShebang(script string) (string, []string)

DetectInterpreterFromShebang reads the first line of the script to detect the interpreter from the shebang line.

func JQ

func JQ(ctx context.Context, path string, script string) (string, error)

func TrimLine

func TrimLine(lines string, prefix string) string

func YQ

func YQ(ctx context.Context, path string, script string) (string, error)

Types

type Artifact

type Artifact struct {
	Path    string        `json:"path" yaml:"path" template:"true"`
	Content io.ReadCloser `json:"-" yaml:"-"`
}

+kubebuilder:object:generate=true

func (*Artifact) DeepCopy

func (in *Artifact) DeepCopy() *Artifact

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Artifact.

func (*Artifact) DeepCopyInto

func (in *Artifact) DeepCopyInto(out *Artifact)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type Checkout added in v0.1.13

type Checkout struct {
	Mode       CheckoutMode `json:"mode,omitempty" yaml:"mode,omitempty"`
	URL        string       `json:"url,omitempty" yaml:"url,omitempty"`
	Path       string       `json:"path,omitempty" yaml:"path,omitempty"`
	Connection string       `json:"connection,omitempty" yaml:"connection,omitempty"`
	Ref        string       `json:"ref,omitempty" yaml:"ref,omitempty"`
	Depth      *int         `json:"depth,omitempty" yaml:"depth,omitempty"`
	// Since is a commit-ish. When set, the merge-base diff against HEAD is
	// folded into the reported `dirtyFiles`. Purely informational — it has no
	// bearing on what the worktree contains.
	Since string `json:"since,omitempty" yaml:"since,omitempty"`
	// Deprecated: no-op, retained so existing configs keep parsing. What a new
	// worktree contains is controlled by Worktree.Uncommitted and
	// Worktree.Ignored; dirtyFiles reporting is controlled by Since.
	Dirty    *Dirty    `json:"dirty,omitempty" yaml:"dirty,omitempty"`
	Worktree *Worktree `json:"worktree,omitempty" yaml:"worktree,omitempty"`
}

type CheckoutMode added in v0.1.13

type CheckoutMode string
const (
	CheckoutNone   CheckoutMode = "none"
	CheckoutLocal  CheckoutMode = "local"
	CheckoutRemote CheckoutMode = "remote"
)

type CloneMode added in v0.1.27

type CloneMode string

CloneMode says what a new worktree ends up containing. It describes the destination, not a mechanism applied to the source.

const (
	CloneClone CloneMode = "clone"
	CloneSkip  CloneMode = "skip"
)

func (CloneMode) IsClone added in v0.1.27

func (c CloneMode) IsClone() bool

type Dirty deprecated added in v0.1.13

type Dirty struct {
	Stash StashMode `json:"stash,omitempty" yaml:"stash,omitempty"`
	Since string    `json:"since,omitempty" yaml:"since,omitempty"`
}

Deprecated: no-op. See Checkout.Dirty.

type Exec

type Exec struct {
	Script      string
	Connections connection.ExecConnections
	Checkout    *connection.GitConnection
	Artifacts   []Artifact

	EnvVars []types.EnvVar
	DotEnv  []string
	Chroot  string
	BaseDir string
}

type ExecDetails

type ExecDetails struct {
	Stdout   string   `json:"stdout"`
	Stderr   string   `json:"stderr"`
	ExitCode int      `json:"exitCode"`
	Path     string   `json:"path"`
	Args     []string `json:"args"`

	// Any extra details about the command execution, e.g. git commit id, etc.
	Extra map[string]any `json:"extra,omitempty"`

	Error     error      `json:"-" yaml:"-"`
	Artifacts []Artifact `json:"-" yaml:"-"`
}

func Run

func Run(ctx context.Context, exec Exec) (*ExecDetails, error)

func RunCmd

func RunCmd(ctx context.Context, exec Exec, cmd *osExec.Cmd) (*ExecDetails, error)

func (*ExecDetails) GetArtifacts

func (e *ExecDetails) GetArtifacts() []Artifact

func (ExecDetails) String

func (e ExecDetails) String() string

type Setup added in v0.1.13

type Setup struct {
	Cwd         string                     `json:"cwd,omitempty" yaml:"cwd,omitempty"`
	BaseDir     string                     `json:"baseDir,omitempty" yaml:"baseDir,omitempty"`
	DotEnv      []string                   `json:"dotenv,omitempty" yaml:"dotenv,omitempty"`
	EnvVars     []types.EnvVar             `json:"envVars,omitempty" yaml:"envVars,omitempty"`
	Checkout    *Checkout                  `json:"checkout,omitempty" yaml:"checkout,omitempty"`
	Connections connection.ExecConnections `json:"connections,omitempty" yaml:"connections,omitempty"`
	Env         []string                   `json:"-" yaml:"-"`
}

func (Setup) Resolve added in v0.1.25

func (s Setup) Resolve(baseDir string) (Setup, error)

Resolve returns an independent setup whose filesystem paths are absolute and anchored to baseDir. This makes a serialized setup safe to execute from a long-lived server whose process directory may differ from the caller's workspace.

Independence comes from merge.Clone, structurally — every field, including ones added after this was written. Anchoring the paths is the only thing left for this function to do.

func (Setup) ToExec added in v0.1.13

func (s Setup) ToExec() *Exec

type SetupResult added in v0.1.13

type SetupResult struct {
	Env       []string
	Cwd       string
	Extra     map[string]any
	Artifacts []Artifact
	Cleanup   func() error
}

func Prepare added in v0.1.13

func Prepare(ctx context.Context, setup *Setup) (*SetupResult, error)

func SetupEnv added in v0.1.13

func SetupEnv(ctx context.Context, exec *Exec) (*SetupResult, error)

type StashMode deprecated added in v0.1.13

type StashMode string

Deprecated: no-op. See Checkout.Dirty.

const (
	StashNone      StashMode = "none"
	StashUntracked StashMode = "untracked"
	StashUnstaged  StashMode = "unstaged"
	StashStaged    StashMode = "staged"
	StashAll       StashMode = "all"
)

Deprecated: no-op. See Checkout.Dirty.

type Worktree added in v0.1.13

type Worktree struct {
	Mode   WorktreeMode `json:"mode,omitempty" yaml:"mode,omitempty"`
	Prefix string       `json:"prefix,omitempty" yaml:"prefix,omitempty"`
	Base   string       `json:"base,omitempty" yaml:"base,omitempty"`
	Path   string       `json:"path,omitempty" yaml:"path,omitempty"`
	Keep   bool         `json:"keep,omitempty" yaml:"keep,omitempty"`

	// Uncommitted controls whether staged, unstaged and untracked changes are
	// carried from the source repo into the new worktree. Nothing is ever
	// stashed — the source repo is never mutated.
	Uncommitted CloneMode `json:"uncommitted,omitempty" yaml:"uncommitted,omitempty"`
	// Ignored controls whether gitignored content (node_modules/, .env, build
	// caches) is copied into the new worktree. `git worktree add` never brings
	// it, so without this the worktree is missing everything .gitignore hides.
	Ignored CloneMode `json:"ignored,omitempty" yaml:"ignored,omitempty"`
}

func (*Worktree) ApplyDefaults added in v0.1.27

func (w *Worktree) ApplyDefaults() []string

ApplyDefaults fills in the worktree defaults and returns any downgrade warnings the caller should surface. Callers opt in explicitly — Prepare does not call it, so an unset Worktree keeps git's own fallbacks.

Defaults: base=HEAD, ignored=clone, uncommitted=clone when base is HEAD. Uncommitted work is a diff against *your* HEAD; replaying it onto a worktree branched elsewhere applies to the wrong context, so a non-HEAD base degrades uncommitted to skip unless it was set explicitly.

type WorktreeMode added in v0.1.13

type WorktreeMode string
const (
	WorktreeNone     WorktreeMode = "none"
	WorktreeNew      WorktreeMode = "new"
	WorktreeExisting WorktreeMode = "existing"
)

Jump to

Keyboard shortcuts

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