Help us shape the future of Go! Take the 2026 Go Developer Survey

pin

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package pin implements the two-phase pin lifecycle: Plan builds a complete Record of what to pin (pure computation + network reads), and Commit writes the Record to disk (workflow files + lockfile).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Audit added in v0.3.0

func Audit(ctx context.Context, rec *Record, store *lockfile.State, report *checks.Report, copts *CommitOptions) error

Audit holds each finding parity deferred (checks.Deferred) to the write rec plans. It applies the write of every workflow still due to be written to a preview of store, with the code Commit and Save use, and a deferred finding holds only if its entry then is gone, or records a commit this run verified, or, for a full-SHA key, a new ref for the same commit. Otherwise the finding goes back on its workflow, which is then no longer written, so Audit runs again without that workflow's write: a finding that held only because of it goes back too. It stops once a pass blocks no further workflow.

func Commit

func Commit(ctx context.Context, rec *Record, store *lockfile.State, copts *CommitOptions) error

Commit writes a planned Record to disk: rewrites workflow files and updates the lockfile store. All-or-nothing semantics — if any write fails, previously written files are not rolled back (best-effort), but the error is returned immediately.

func PlanEntryRepairs added in v0.3.0

func PlanEntryRepairs(ctx context.Context, rec *Record, store *lockfile.State, resolver *resolve.Resolver, report *checks.Report, copts *CommitOptions) error

PlanEntryRepairs finds the tag at the commit, else a branch containing it, for each entry recording its own SHA as its ref that the planned write leaves reachable from a workflow it updates. It previews that write with the code Commit uses (see Audit), so whatever keeps such an entry, a workflow's own pin, a composite the run reuses from the lock, or a root it replaces, is followed. An entry only unwritten workflows reach is left as recorded, and one nothing reaches is dropped by Save. A commit no tag or branch contains is Unresolved, so nothing is written.

Types

type CommitOptions

type CommitOptions struct {
	// OnProgress is called at each phase boundary. Nil means no progress.
	OnProgress func(phase string)
	// SkipNewWorkflowEntries forces the Commit phase to skip workflows with no existing lockfile entry.
	SkipNewWorkflowEntries bool
}

CommitOptions configures the Commit pass.

type Entry

type Entry struct {
	Hostname     string
	NWO          string
	Ref          string
	SHA          string
	ObservedSHA  string
	Resolution   Resolution
	Issue        string
	Reason       string
	Suggestion   string
	AutoFixedRef string // original ref before sane-release rewrite
	OnBranch     string
	Tag          string
	Workflows    []string
	RequiredBy   []string
	Direct       bool
	// RenamedFrom lists the lockfile keys this pin had before a
	// same-repository rename, so their recorded `uses:` carry over.
	RenamedFrom []string
	FullScan    bool
	// ReRecorded marks a full-SHA pin whose entry recorded the SHA itself
	// as its ref; Commit records the tag or branch found for it instead.
	ReRecorded bool
	// FromLock marks an entry taken from the lockfile without reading its
	// manifest (see dep.Dependency.FromLock).
	FromLock bool
}

Entry records the plan decision for one action dependency.

type EntryRepair added in v0.3.0

type EntryRepair struct {
	Key string
	Ref string
	// Workflows are the written workflows that reach the entry; the repair
	// applies only while one of them is written.
	Workflows []string
}

EntryRepair re-records the ref of an existing lockfile entry.

type PlanOptions

type PlanOptions struct {
	Resolver  *resolve.Resolver
	Tagger    *tag.Lister
	Store     *lockfile.State
	Pool      *pinpool.Pool
	RepoOwner string // for same-owner narrowing skip
	RepoName  string
	// NoNarrow disables tag narrowing: mutable version refs (v4, v3.1)
	// are kept as the lock comment instead of being resolved to full
	// patch tags (v4.2.1). Bare-SHA reverse lookup still applies.
	NoNarrow bool

	// AcceptMoved treats ref-moved and unreachable-pin findings as
	// resolvable: affected deps are pruned from the inventory and
	// re-resolved to their current live SHA.
	AcceptMoved bool

	// Relock treats ref-moved findings (a branch or partial-version ref
	// that legitimately advanced) as resolvable, re-pinning them to the
	// current live SHA. Unlike AcceptMoved it leaves unreachable-pin
	// findings untouched so possible tampering stays a hard error.
	Relock bool

	// PartialScan reports that explicit workflow paths, rather than the full
	// workflow directory, define this run's mutation authority.
	PartialScan bool

	// OnProgress is called at each phase boundary with a human-readable
	// label (e.g. "Resolving actions/checkout"). Nil means no progress.
	OnProgress func(phase string)
	// contains filtered or unexported fields
}

PlanOptions configures the Plan pass.

type Record

type Record struct {
	Entries   []Entry
	Workflows []WorkflowPlan
	// EntryRepairs re-record entries the workflows reach only through
	// another entry's `uses:`; see planEntryRepairs.
	EntryRepairs []EntryRepair
}

Record is the complete output of Plan: everything Commit needs to write all changes atomically.

func Plan

func Plan(ctx context.Context, report *checks.Report, opts PlanOptions) (*Record, error)

Plan walks an actionmanager Report and produces a Record describing every pin action to take. It does network reads (resolve, reverse lookup, reachability) but no disk writes.

func (*Record) Investigated

func (r *Record) Investigated() []Entry

Investigated returns entries with Resolution == Investigate.

func (*Record) Narrowed added in v0.1.0

func (r *Record) Narrowed() []Entry

Narrowed returns verified entries whose refs were upgraded (AutoFixedRef set).

func (*Record) Pinned

func (r *Record) Pinned() []Entry

Pinned returns entries with Resolution == Pinned.

func (*Record) Unresolved

func (r *Record) Unresolved() []Entry

Unresolved returns entries with Resolution == Unresolved.

func (*Record) Valid

func (r *Record) Valid() bool

Valid reports whether the record contains no investigate or unresolved entries.

func (*Record) Verified added in v0.3.0

func (r *Record) Verified() []Entry

Verified returns entries with Resolution == Verified.

type Resolution

type Resolution string

Resolution describes the outcome for a single action reference.

const (
	Pinned      Resolution = "pinned"
	Verified    Resolution = "verified"
	Investigate Resolution = "needs-investigation"
	Skipped     Resolution = "skipped"
	Unresolved  Resolution = "unresolved"
)

Resolution values reported for an action reference.

func (Resolution) String

func (r Resolution) String() string

String returns the resolution as a string.

type WorkflowPlan

type WorkflowPlan struct {
	Path     string
	Rewrites map[string]string
	// RequiredRewrites move redirected `uses:` to the canonical repository;
	// Commit fails rather than skip one.
	RequiredRewrites map[string]string
	// RewrittenIn lists, per RequiredRewrites key, the files Commit found it in.
	RewrittenIn map[string][]string
	// SelfActionFiles are in-repo action definition files reached from this
	// workflow through `$/…`. The same rewrites apply to their `uses:` lines.
	SelfActionFiles []string
}

WorkflowPlan records what Commit must write for one workflow file.

Jump to

Keyboard shortcuts

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