action

package
v1.0.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: ISC Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Name        string            `yaml:"name"`
	Version     string            `yaml:"version"`
	Description string            `yaml:"description"`
	Author      string            `yaml:"author"`
	Inputs      map[string]Input  `yaml:"inputs"`
	Outputs     map[string]Output `yaml:"outputs"`
	Tasks       []Task            `yaml:"tasks"`
}

Action is the parsed representation of an action.yml file.

func ParseAction

func ParseAction(data []byte) (*Action, error)

ParseAction parses action YAML bytes into an Action.

type CacheResolver

type CacheResolver struct {
	CacheDir string
}

CacheResolver resolves versioned action refs from the local user cache at ~/.preflight/actions/. Refs of the form "github.com/org/name@v1.2" map to <cacheDir>/github.com/org/name@v1.2/action.yml.

func NewCacheResolver

func NewCacheResolver(cacheDir string) *CacheResolver

NewCacheResolver creates a CacheResolver. If cacheDir is empty it defaults to ~/.preflight/actions/.

func (*CacheResolver) Name

func (r *CacheResolver) Name() string

func (*CacheResolver) Resolve

func (r *CacheResolver) Resolve(_ context.Context, ref string) (*Action, error)

type Chain

type Chain []Resolver

Chain tries each Resolver in order, returning the first non-nil result. If no resolver handles the ref, it returns an error.

func DefaultChain

func DefaultChain(projectDir string) Chain

DefaultChain builds the standard resolver chain:

embedded stdlib → local ./actions/ → user cache → git (stub)

func (Chain) Resolve

func (c Chain) Resolve(ctx context.Context, ref string) (*Action, error)

Resolve walks the chain and returns the first non-nil Action result.

type EmbeddedResolver

type EmbeddedResolver struct {
	FS fs.FS
}

EmbeddedResolver resolves stdlib actions from an embedded filesystem. It handles refs with the "preflight/" prefix, mapping them to actions/preflight/<name>/action.yml inside the FS.

func NewEmbeddedResolver

func NewEmbeddedResolver(fsys fs.FS) *EmbeddedResolver

NewEmbeddedResolver creates a resolver backed by the provided embedded FS.

func (*EmbeddedResolver) Name

func (r *EmbeddedResolver) Name() string

Name returns a human-readable identifier for this resolver.

func (*EmbeddedResolver) Resolve

func (r *EmbeddedResolver) Resolve(ctx context.Context, ref string) (*Action, error)

Resolve returns the Action for refs prefixed with "preflight/". Returns (nil, nil) for refs it does not handle.

type GitResolver

type GitResolver struct {
	CacheDir string
}

GitResolver fetches action definitions from remote Git repositories. The ref format is "github.com/org/repo@version" or "github.com/org/repo@sha". This implementation is a stub — full git fetch support is a future milestone.

func NewGitResolver

func NewGitResolver(cacheDir string) *GitResolver

NewGitResolver creates a GitResolver that would cache fetched actions in cacheDir.

func (*GitResolver) Name

func (r *GitResolver) Name() string

func (*GitResolver) Resolve

func (r *GitResolver) Resolve(_ context.Context, ref string) (*Action, error)

type Input

type Input struct {
	Type        string `yaml:"type"` // string, bool, int, path
	Required    bool   `yaml:"required"`
	Default     any    `yaml:"default"`
	Description string `yaml:"description"`
}

Input describes a typed input parameter for an action.

type LocalResolver

type LocalResolver struct {
	BaseDir string
}

LocalResolver resolves action refs from a local project actions directory. A ref like "myorg/display-config" maps to <BaseDir>/myorg/display-config/action.yml.

Refs that look like remote URLs (contain "://", start with "github.com/", etc.) are not handled by this resolver.

func NewLocalResolver

func NewLocalResolver(baseDir string) *LocalResolver

NewLocalResolver creates a resolver that looks up actions under baseDir.

func (*LocalResolver) Name

func (r *LocalResolver) Name() string

Name returns a human-readable identifier for this resolver.

func (*LocalResolver) Resolve

func (r *LocalResolver) Resolve(ctx context.Context, ref string) (*Action, error)

Resolve returns the Action for a simple ref like "myorg/display-config". Returns (nil, nil) for refs that look like remote refs (contain a dot-separated hostname component, e.g. "github.com/…") or stdlib refs ("preflight/…").

type LockEntry

type LockEntry struct {
	Ref    string `json:"ref"`
	SHA    string `json:"sha"`
	Pinned string `json:"pinned"` // original ref before SHA pinning
}

LockEntry records a pinned action reference.

type Lockfile

type Lockfile struct {
	Actions map[string]LockEntry `json:"actions"`
}

Lockfile manages the preflight.lock file which pins remote action refs to exact Git SHAs for reproducible builds.

func LoadLockfile

func LoadLockfile(path string) (*Lockfile, error)

LoadLockfile reads and parses a lockfile from path. If the file does not exist, an empty Lockfile is returned without error.

func (*Lockfile) Lookup

func (l *Lockfile) Lookup(ref string) (LockEntry, bool)

Lookup returns the LockEntry for ref, or false if not pinned.

func (*Lockfile) Pin

func (l *Lockfile) Pin(ref, sha string)

Pin records a pinned SHA for the given ref.

func (*Lockfile) Save

func (l *Lockfile) Save(path string) error

Save writes the lockfile to path as indented JSON.

type Output

type Output struct {
	Type        string `yaml:"type"`
	Description string `yaml:"description"`
}

Output describes a named output emitted by an action.

type Playbook

type Playbook struct {
	Name        string         `yaml:"name"`
	Description string         `yaml:"description"`
	Vars        map[string]any `yaml:"vars"`
	Import      []string       `yaml:"import"`
	Tasks       []Task         `yaml:"tasks"`
}

Playbook is the parsed representation of a playbook.yml file.

func ParsePlaybook

func ParsePlaybook(data []byte) (*Playbook, error)

ParsePlaybook parses playbook YAML bytes into a Playbook.

func ParsePlaybookFile

func ParsePlaybookFile(path string) (*Playbook, error)

ParsePlaybookFile reads a file at path and parses it as a Playbook.

type Resolver

type Resolver interface {
	// Resolve returns the Action for the given ref, or (nil, nil) if this
	// resolver does not handle the ref.
	Resolve(ctx context.Context, ref string) (*Action, error)
	// Name returns a human-readable name for this resolver (for error messages).
	Name() string
}

Resolver resolves an action ref to an Action definition.

type Task

type Task struct {
	Name         string         `yaml:"name"`
	Uses         string         `yaml:"uses"`
	With         map[string]any `yaml:"with"`
	Module       string         `yaml:"-"` // resolved module name
	Params       map[string]any `yaml:"-"` // resolved module params
	When         string         `yaml:"when"`
	DependsOn    []string       `yaml:"depends_on"`
	IgnoreErrors bool           `yaml:"ignore_errors"`
	Tags         []string       `yaml:"tags"`

	// Inline module fields — at most one may be non-nil per task.
	Registry       map[string]any `yaml:"registry"`
	Service        map[string]any `yaml:"service"`
	File           map[string]any `yaml:"file"`
	Directory      map[string]any `yaml:"directory"`
	Package        map[string]any `yaml:"package"`
	Shortcut       map[string]any `yaml:"shortcut"`
	ScheduledTask  map[string]any `yaml:"scheduled_task"`
	User           map[string]any `yaml:"user"`
	WindowsFeature map[string]any `yaml:"windows_feature"`
	Environment    map[string]any `yaml:"environment"`
	FirewallRule   map[string]any `yaml:"firewall_rule"`
	Powershell     map[string]any `yaml:"powershell"`
	Shell          map[string]any `yaml:"shell"`
	Reboot         map[string]any `yaml:"reboot"`
	Wait           map[string]any `yaml:"wait"`
}

Task is a single step inside an action or playbook.

func (*Task) ResolveModule

func (t *Task) ResolveModule() error

ResolveModule inspects inline module fields and sets Module + Params. Returns an error if more than one inline module field is set, or if both "uses" and an inline module field are set.

Jump to

Keyboard shortcuts

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