version

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package version parses and increments SemVer versions, and matches them against a configurable tag-format template.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bump

type Bump int

Bump is a SemVer increment severity. Zero value is BumpNone (no bump).

const (
	BumpNone Bump = iota
	BumpPatch
	BumpMinor
	BumpMajor
)

func Max

func Max(a, b Bump) Bump

Max returns the higher-severity of a and b.

type Format

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

Format is a parsed tag-format template such as "v{{version}}" or "{{package}}-v{{version}}". {{package}} is accepted here even though single-mode matching (Match) never uses it — multi-mode range-finding reuses this same parser once it exists.

func ParseFormat

func ParseFormat(raw string) (*Format, error)

ParseFormat compiles raw into a matcher. raw must contain {{version}} — a tag format that can't identify a version can't be used to find "the last release".

func (*Format) ForPackage

func (f *Format) ForPackage(name string) (*Format, error)

ForPackage returns a Format with {{package}} resolved to name, so Match only matches tags belonging to that specific package (multi mode).

func (*Format) Match

func (f *Format) Match(tag string) (SemVer, bool)

Match reports whether tag matches the format, returning its version when so.

func (*Format) Render

func (f *Format) Render(ver, pkg string) string

Render substitutes ver (and pkg, for a {{package}} placeholder, if any) into the format's template, producing a concrete tag string — the counterpart to Match, used when creating a new tag rather than finding an existing one.

type SemVer

type SemVer struct {
	Major, Minor, Patch int
}

SemVer is a parsed major.minor.patch version. Pre-release and build metadata aren't supported — tag-format's {{version}} placeholder only matches bare major.minor.patch tags.

func Parse

func Parse(s string) (SemVer, error)

Parse reads a bare "major.minor.patch" string.

func (SemVer) Apply

func (v SemVer) Apply(bump Bump) SemVer

Apply returns the version after applying bump. BumpNone returns v unchanged.

func (SemVer) GreaterThan

func (v SemVer) GreaterThan(o SemVer) bool

GreaterThan reports whether v is a later version than o.

func (SemVer) String

func (v SemVer) String() string

Jump to

Keyboard shortcuts

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