version

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Version is the semantic version of the application
	Version = "0.1.0"

	// Commit is the git commit hash
	Commit = "none"

	// Date is the build date
	Date = "unknown"
)

Version information for the application These values are typically set at build time via ldflags

Functions

func ApplyBump

func ApplyBump(current semver.Version, changeType types.ChangeType) semver.Version

ApplyBump applies a change type bump to a version and returns the new version

func ApplyBumpMap

func ApplyBumpMap(currentVersions map[string]semver.Version, bumps map[string]types.ChangeType) map[string]semver.Version

ApplyBumpMap applies version bumps to a map of packages Returns a new map with updated versions Packages not in the bumps map remain at their current version

func CalculateDirectBumps

func CalculateDirectBumps(consignments []*consignment.Consignment) map[string]string

CalculateDirectBumps calculates the highest priority change type for each package based on consignments. Returns a map of package name to change type string.

When multiple consignments affect the same package, the highest priority change type is selected according to: major > minor > patch

func CalculateNewVersions

func CalculateNewVersions(
	currentVersions map[string]semver.Version,
	directBumps map[string]types.ChangeType,
	propagatedBumps map[string]types.ChangeType,
) map[string]semver.Version

CalculateNewVersions combines direct and propagated bumps, taking the higher of the two Returns a map of package name to new version

func FilterBumpsByPackages

func FilterBumpsByPackages(bumps map[string]types.ChangeType, packages []string) map[string]types.ChangeType

FilterBumpsByPackages filters a bump map to only include specified packages

func GetBumpPriority

func GetBumpPriority(changeType types.ChangeType) int

GetBumpPriority returns a numeric priority for a change type Higher number = higher priority

func GetChangePriority

func GetChangePriority(changeType string) int

GetChangePriority returns the numeric priority of a change type. Higher numbers indicate higher priority. Priority order: major (3) > minor (2) > patch (1) > unknown (0)

func GetPackagesWithBumps

func GetPackagesWithBumps(bumps map[string]types.ChangeType) []string

GetPackagesWithBumps returns a sorted list of package names that have version bumps

func IsHigherPriority

func IsHigherPriority(a, b string) bool

IsHigherPriority returns true if change type a has higher priority than b. Priority order: major > minor > patch

func MaxChangeType

func MaxChangeType(a, b types.ChangeType) types.ChangeType

MaxChangeType returns the higher priority change type Priority order: major > minor > patch

func MergeBumpMaps

func MergeBumpMaps(map1, map2 map[string]types.ChangeType) map[string]types.ChangeType

MergeBumpMaps merges two bump maps, taking the maximum change type for each package If a package exists in both maps, the higher priority change type wins

func PropagateLinked

func PropagateLinked(
	g *graph.DependencyGraph,
	currentVersions map[string]semver.Version,
	directBumps map[string]string,
) (map[string]VersionBump, error)

PropagateLinked propagates version bumps through linked dependencies in the graph. Returns a map of all version bumps (both direct and propagated).

Algorithm:

  1. Start with direct bumps and apply them to result
  2. For each changed package, find packages that depend on it
  3. If dependency has "linked" strategy, propagate the bump (respecting bump mapping)
  4. Skip packages that already have direct bumps (direct takes precedence)
  5. Continue until no more changes propagate

func ResolveConflicts

func ResolveConflicts(bumps map[string]VersionBump) map[string]VersionBump

ResolveConflicts resolves conflicting version bump requests for packages.

In the current implementation, conflicts are prevented by PropagateLinked() which only processes each package once. Direct bumps take precedence over propagated bumps, and the first propagation to reach a package wins.

This function serves as:

  1. A validation pass to ensure no actual conflicts exist
  2. A clear extension point for more complex conflict resolution strategies
  3. Documentation of the conflict resolution policy

Conflict Resolution Policy:

  • Direct bumps always win over propagated bumps
  • Cycle-resolved bumps have already unified all members
  • For propagated bumps, first-to-arrive wins (handled by PropagateLinked)

Future enhancements could include:

  • Explicit priority levels for different propagation sources
  • User-configurable conflict resolution strategies
  • Warnings/errors for detected conflicts requiring manual resolution

func ResolveCycleBumps

func ResolveCycleBumps(
	g *graph.DependencyGraph,
	currentVersions map[string]semver.Version,
	directBumps map[string]string,
) (map[string]VersionBump, error)

ResolveCycleBumps resolves version bumps for packages in cycles (SCCs). When packages form a cycle, all members must receive the same version bump. The highest priority bump among cycle members is selected and applied to all.

Prerequisites: FindStronglyConnectedComponents must be called on the graph first to populate SCC IDs.

Algorithm:

  1. Group packages by their SCC ID
  2. For each SCC with direct bumps: - Find the highest priority bump among members - Apply that bump to ALL members of the SCC
  3. Mark cycle-resolved bumps with source="cycle"
  4. Non-cycle packages keep source="direct"

Types

type Propagator

type Propagator struct {
	// contains filtered or unexported fields
}

Propagator handles version bump propagation through a dependency graph

func NewPropagator

func NewPropagator(g *graph.DependencyGraph) (*Propagator, error)

NewPropagator creates a new version propagator for the given dependency graph

func (*Propagator) Propagate

func (p *Propagator) Propagate(
	currentVersions map[string]semver.Version,
	consignments []*consignment.Consignment,
) (map[string]VersionBump, error)

Propagate calculates version bumps for all packages based on consignments and dependency relationships. Returns a map of package name to VersionBump.

Algorithm:

  1. Calculate direct bumps from consignments
  2. Run SCC detection and compress graph
  3. Topologically sort compressed graph
  4. Propagate bumps through dependencies (respecting strategies)
  5. Resolve conflicts (multiple sources requesting different bumps)

type VersionBump

type VersionBump struct {
	Package    string         // Package name
	OldVersion semver.Version // Current version
	NewVersion semver.Version // New version after bump
	ChangeType string         // Type of change: "patch", "minor", or "major"
	Source     string         // Source of bump: "direct", "propagated", "cycle"
}

VersionBump represents a version change for a package

type VersionDiff

type VersionDiff struct {
	Package    string
	OldVersion semver.Version
	NewVersion semver.Version
	ChangeType types.ChangeType
}

VersionDiff represents a version change

func CalculateVersionDiffs

func CalculateVersionDiffs(
	currentVersions map[string]semver.Version,
	newVersions map[string]semver.Version,
	bumps map[string]types.ChangeType,
) []VersionDiff

CalculateVersionDiffs computes the differences between current and new versions

Jump to

Keyboard shortcuts

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