vendoring

package
v1.223.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const ComponentManifestVersionPath = "spec.source.version"

ComponentManifestVersionPath is the fixed dot-path for a component.yaml's pinned version (singular spec.source, unlike vendor.yaml's spec.sources[] array).

View Source
const DefaultVendorFile = "vendor.yaml"

DefaultVendorFile is the default vendor manifest filename considered when no explicit --file override is given.

Variables

This section is empty.

Functions

func CollectManifestFiles

func CollectManifestFiles(vendorFile string) ([]string, error)

CollectManifestFiles returns the ordered list of physical vendor manifest files reachable from vendorFile: the file itself followed by the files it imports (resolved relative to each importing file's directory, recursively and de-duplicated). Editing operates on these concrete files so changes land in the file that declares each source.

func ComponentManifestSource

func ComponentManifestSource(cfg *schema.VendorComponentConfig, component, componentType string) *schema.AtmosVendorSource

ComponentManifestSource converts a decoded component.yaml into the same schema.AtmosVendorSource shape vendor.yaml sources use, so vendoring.Diff and vendoring.Update's checkAndUpdateSource/ isNewer/resolveLatest consume it unmodified. Targets is synthesized as a single "components/<type>/<component>" entry solely so --type filtering (sourceTargetsType) behaves identically regardless of which manifest shape the source came from.

func ComponentVersionPath

func ComponentVersionPath(vendorFile, component string) (string, error)

ComponentVersionPath resolves the dot-notation path addressing a component's pinned version in a vendor manifest file (e.g. "spec.sources[2].version"). The source is matched by component name, so manifest ordering does not matter; the returned path reflects the component's current array index. Returns an error wrapping atmosyaml.ErrYAMLPathNotFound if the component is not declared in the manifest.

func Diff

func Diff(atmosConfig *schema.AtmosConfiguration, params *DiffParams) (string, error)

Diff returns a unified diff between two versions of a vendored Git component.

func FindComponentManifestFile

func FindComponentManifestFile(componentDir string) (string, error)

FindComponentManifestFile locates a component vendoring manifest (component.yaml or component.yml) directly inside componentDir. Unlike vendor.yaml, component.yaml has no imports, so no recursion is needed.

func FindSource

func FindSource(files []string, component string) (*schema.AtmosVendorSource, string, error)

FindSource scans the given manifest files for a source declaring component and returns it along with the file that declares it.

func ReadComponentManifest

func ReadComponentManifest(file string) (*schema.VendorComponentConfig, error)

ReadComponentManifest reads and decodes a component vendoring manifest, validating its "kind".

func SetComponentManifestVersion

func SetComponentManifestVersion(file, ver string) error

SetComponentManifestVersion sets spec.source.version in a component.yaml file, preserving comments, anchors, and templates, via the same generic format-preserving primitive vendor.yaml editing uses.

func SetComponentVersion

func SetComponentVersion(vendorFile, component, version string) error

SetComponentVersion sets the version for a component in a vendor manifest file, preserving comments/anchors/formatting. The edit targets the matching source by component name (not by index), so reordering the manifest is safe. Returns an error wrapping atmosyaml.ErrYAMLPathNotFound if the component is not declared in the manifest.

func VendorFilePresent

func VendorFilePresent(override string) (string, bool)

VendorFilePresent reports whether a vendor manifest is available: override if non-empty, otherwise the location configured via atmos.yaml (vendor.base_path, falling back to <BasePath>/vendor.yaml), matching `atmos vendor pull`'s existing resolution (internal/exec/vendor_utils.go:resolveVendorConfigFilePath). This is what makes --chdir and atmos.yaml's vendor.base_path setting take effect for update/diff/get/set, instead of only ever checking the process's cwd.

Types

type ArchivedChecker

type ArchivedChecker interface {
	// IsArchived reports whether the repository at gitURI (as produced by
	// version.ExtractGitURI) is archived upstream. Implementations must treat sources that
	// don't support archived detection (non-GitHub hosts) as simply "not archived, no error".
	IsArchived(ctx context.Context, gitURI string) (bool, error)
}

ArchivedChecker reports whether a source's upstream Git repository is archived. It is an interface (mirroring version.RemoteLister) purely for testability: unit tests can fake "is this repo archived" without hitting the network.

var DefaultArchivedChecker ArchivedChecker = &githubArchivedChecker{}

DefaultArchivedChecker is the production ArchivedChecker used when UpdateParams.ArchivedChecker is nil.

type ComponentDirResolver

type ComponentDirResolver interface {
	ComponentDir(componentType, component string) (string, error)
}

ComponentDirResolver resolves a component's on-disk directory, used to locate its component.yaml fallback. An interface so this is unit-testable without loading a real atmos.yaml (same DI pattern as GitDiffer/version.RemoteLister).

type DefaultComponentDirResolver

type DefaultComponentDirResolver struct{}

DefaultComponentDirResolver resolves via a real, lazily-loaded atmosConfig (cfg.InitCliConfig), matching `atmos vendor pull`'s BasePath resolution (Components.<Type>.BasePath, including per-type env var overrides).

func (DefaultComponentDirResolver) ComponentDir

func (DefaultComponentDirResolver) ComponentDir(componentType, component string) (string, error)

ComponentDir resolves componentType/component to an absolute directory path.

type DiffParams

type DiffParams struct {
	// Source is the Git source URL of the component.
	Source string
	// From is the starting ref; defaults to the component's current pinned version.
	From string
	// To is the ending ref; when empty, the latest semver tag is used.
	To string
	// File optionally restricts the diff to a single path.
	File string
	// Lister resolves the latest tag when To is empty; defaults to version.DefaultLister.
	Lister version.RemoteLister
	// Differ performs the clone+diff; defaults to DefaultDiffer.
	Differ GitDiffer
}

DiffParams configures a vendor diff.

type GitDiffer

type GitDiffer interface {
	Diff(ctx context.Context, gitURI, fromRef, toRef, file string) (string, error)
}

GitDiffer produces a unified diff between two refs of a remote Git repository. It is an interface so the diff command can be unit-tested without network.

var DefaultDiffer GitDiffer = &GoGitDiffer{}

DefaultDiffer is the production GitDiffer backed by go-git.

type GoGitDiffer

type GoGitDiffer struct{}

GoGitDiffer clones a repository (with tags, no checkout) into a temp directory and produces a patch between two commits using go-git — no `git` binary.

func (*GoGitDiffer) Diff

func (d *GoGitDiffer) Diff(ctx context.Context, gitURI, fromRef, toRef, file string) (string, error)

Diff clones gitURI and returns the unified diff between fromRef and toRef, optionally restricted to a single file path.

type ResolveSourceParams

type ResolveSourceParams struct {
	// VendorFile is the --file override; empty means "look for ./vendor.yaml".
	VendorFile string
	// Component is the component name to resolve.
	Component string
	// ComponentType defaults to cfg.TerraformComponentType when empty.
	ComponentType string
	// Resolver defaults to DefaultComponentDirResolver{} when nil.
	Resolver ComponentDirResolver
}

ResolveSourceParams configures ResolveComponentSource.

type ResolvedSource

type ResolvedSource struct {
	Source *schema.AtmosVendorSource
	// File is the physical manifest that declares Source (a vendor.yaml/import or a
	// component.yaml) — the file version updates are written back to.
	File string
	// FromComponentManifest is true when Source was resolved from a component.yaml fallback
	// rather than a vendor.yaml source.
	FromComponentManifest bool
	// ComponentType is the component type ("terraform", "helmfile", "packer") this source was
	// resolved under, set only alongside FromComponentManifest. A repo-wide sweep
	// (DiscoverAllComponentManifests) can mix types in one run, so this travels with each
	// individual source rather than being assumed from a single CLI --type flag; see
	// SourceUpdateResult.ComponentType, which carries it into an update report.
	ComponentType string
}

ResolvedSource is the outcome of ResolveComponentSource (or a component.yaml discovered via DiscoverComponentManifests).

func DiscoverAllComponentManifests

func DiscoverAllComponentManifests(componentType string, onlyType bool) ([]*ResolvedSource, error)

DiscoverAllComponentManifests sweeps every configured component type (or just componentType, when onlyType is true) for component.yaml manifests, used by the opt-in "vendor update --component-manifests" repo-wide sweep.

func DiscoverComponentManifests

func DiscoverComponentManifests(basePath, componentType string) ([]*ResolvedSource, error)

DiscoverComponentManifests finds every component.yaml/component.yml declared directly under a component type's base directory (one level deep: <basePath>/<component>/component.yaml), for the opt-in repo-wide component-manifest sweep ("vendor update --component-manifests"). Directories without a manifest are silently skipped — not every component vendors this way; a manifest that IS found but is malformed is a hard error.

func ResolveComponentSource

func ResolveComponentSource(params *ResolveSourceParams) (*ResolvedSource, error)

ResolveComponentSource finds a component's vendor source, preferring vendor.yaml (--file override, else ./vendor.yaml, following imports) and falling back to <BasePath>/<component>/component.yaml when vendor.yaml doesn't exist, or exists but doesn't declare the component. Mirrors `atmos vendor pull`'s existing vendor.yaml-wins precedence, generalized to the per-component granularity diff/update need.

type SourceUpdateResult

type SourceUpdateResult struct {
	File           string
	Component      string
	CurrentVersion string
	LatestVersion  string
	Status         UpdateStatus
	Reason         string // Populated for StatusSkipped and StatusFailed.
	// Archived reports whether the source's upstream Git repository is archived (GitHub sources
	// only; best-effort). This is orthogonal to Status: a component can be both StatusUpToDate
	// and Archived at the same time, so it's a separate field rather than another UpdateStatus
	// value.
	Archived bool
	// ComponentType is the component type ("terraform", "helmfile", "packer") this result was
	// resolved under, populated only for component.yaml-declared sources (ResolvedSource.ComponentType;
	// see updateResolvedSource). Empty for vendor.yaml-declared sources, which don't carry a single
	// type the same way (each source's own Targets can point anywhere). Used by
	// cmd/vendor/update.go's partitionUpdatedResults to group a repo-wide "--pull" batch by type,
	// since a component-manifest sweep (DiscoverAllComponentManifests) can mix types in one report.
	ComponentType string
}

SourceUpdateResult is the per-source outcome of an update run.

type UpdateParams

type UpdateParams struct {
	// VendorFiles are the physical manifest files to process (a vendor.yaml plus
	// any imported files). Edits are applied to the file that declares each source.
	VendorFiles []string
	// ExtraSources are additional already-resolved sources to check/update alongside
	// VendorFiles — used by the opt-in --component-manifests sweep to fold in
	// component.yaml-only components. A component name already present in VendorFiles'
	// sources takes precedence (vendor.yaml wins) and its ExtraSources entry, if any, is
	// skipped.
	ExtraSources []*ResolvedSource
	// Component, when set, restricts updates to that component.
	Component string
	// Tags, when set, restricts updates to sources carrying any of these tags.
	Tags []string
	// Type, when set, restricts updates to sources targeting components of this type.
	Type string
	// DryRun reports what would change without writing files.
	DryRun bool
	// Lister lists remote tags; defaults to version.DefaultLister when nil.
	Lister version.RemoteLister
	// VersionSetter, when set, replaces SetComponentVersion for persisting a resolved
	// version. Component-manifest (component.yaml) sources need spec.source.version
	// instead of vendor.yaml's spec.sources[i].version. Defaults to SetComponentVersion.
	VersionSetter func(file, component, version string) error
	// OnProgress, when set, is called immediately before each source that passes the
	// component/tag/type filters is checked against the remote, reporting the source's
	// component name along with its 1-based position and the total number of sources
	// that will be checked. Used to drive a live "Checking <component>..." progress
	// indicator during what is otherwise a sequence of blocking network calls.
	OnProgress func(component string, index, total int)
	// ArchivedChecker checks whether a source's upstream Git repository is archived; defaults
	// to DefaultArchivedChecker when nil. The check is best-effort and non-fatal: an error here
	// never fails the overall update/check for a source, it only leaves Archived false.
	ArchivedChecker ArchivedChecker
}

UpdateParams configures an update run.

type UpdateReport

type UpdateReport struct {
	Results []SourceUpdateResult
}

UpdateReport summarizes an update run.

func Update

func Update(atmosConfig *schema.AtmosConfiguration, params *UpdateParams) (*UpdateReport, error)

Update checks each Git-backed source for a newer allowed version and updates the version field in place (preserving comments, anchors, and templates), unless DryRun is set. Non-Git and templated-version sources are skipped.

func UpdateResolved

func UpdateResolved(resolved *ResolvedSource, params *UpdateParams) (*UpdateReport, error)

UpdateResolved evaluates and, unless DryRun, updates a single already-resolved component source (from ResolveComponentSource). Used for --component, which may resolve to either a vendor.yaml source or a component.yaml fallback; auto-selects the component.yaml VersionSetter when resolved.FromComponentManifest and the caller didn't already set one.

func (*UpdateReport) UpdatedCount

func (r *UpdateReport) UpdatedCount() int

UpdatedCount returns how many sources were (or would be) updated.

type UpdateStatus

type UpdateStatus string

UpdateStatus enumerates the outcome for a single source in an update run.

const (
	// StatusUpdated means the source's version was (or would be) changed.
	StatusUpdated UpdateStatus = "updated"
	// StatusUpToDate means the source already pins the latest allowed version.
	StatusUpToDate UpdateStatus = "up-to-date"
	// StatusSkipped means the source was not checked (templated, non-Git, etc.).
	StatusSkipped UpdateStatus = "skipped"
	// StatusFailed means the source could not be checked or updated because of a hard error.
	StatusFailed UpdateStatus = "failed"
)

Directories

Path Synopsis
Package version resolves the latest allowed upstream version for a vendored Git source: it lists remote tags, parses semantic versions, and applies the configured version constraints.
Package version resolves the latest allowed upstream version for a vendored Git source: it lists remote tags, parses semantic versions, and applies the configured version constraints.

Jump to

Keyboard shortcuts

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