version

package
v7.0.0-...-2238254 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FullFormat    = "x.y.z-p+m"
	NoMetaFormat  = "x.y.z-p"
	NoPreFormat   = "x.y.z"
	NoPatchFormat = "x.y"
	NoMinorFormat = "x"
)

Predefined format strings to be used with the Format function.

View Source
const DefaultPrefix = "v"

DefaultPrefix that is recognized and ignored by the parser.

View Source
const DefaultTarget = Devel

The DefaultTarget when calculating the next version.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option = func(*options)

func WithMatchPattern

func WithMatchPattern(pattern string) Option

type RepoHead

type RepoHead struct {
	LastTag         string
	CommitsSinceTag int
	Hash            string
}

RepoHead provides statistics about the head commit of a git repository like its commit-hash, the number of commits since the last tag and the name of the last tag.

func GitDescribe

func GitDescribe(path string, opts ...Option) (*RepoHead, error)

GitDescribe looks at the git repository at path and figures out versioning relvant information about the head commit.

type Tag

type Tag struct {
	Name string
	When time.Time
}

type Target

type Target int

Target specifies a component of a semantic version that should be updated to.

const (
	Devel Target = iota // updates to the next development version (e.g. updating pre.N)
	Patch               // updates to the next patch level
	Minor               // updates to the next minor version
	Major               // updates to the next major version
)

func (*Target) Set

func (t *Target) Set(value string) error

func (*Target) String

func (t *Target) String() string

type Version

type Version struct {
	Prefix string
	Major  int
	Minor  int
	Patch  int

	Commits int
	Meta    string
	// contains filtered or unexported fields
}

Version holds the parsed components of git describe.

func NewFromHead

func NewFromHead(head *RepoHead, prefix string) (Version, error)

NewFromHead creates a new Version based on the given head revision, which can be created with GitDescribe.

The prefix is an arbitrary string that is prepended to the version number. The not SemVer commpliant but commonly used prefix v will be automatically detected.

func NewFromRepo

func NewFromRepo(path, prefix, pattern string) (Version, error)

NewFromRepo calculates a semantic version for the head commit of the repo at path. If the latest commit is not tagged, the version will have a pre-release-suffix appended to it (e.g.: 1.2.3-pre.3+fcf2c8f). The suffix has the format pre.<n>+<hash>, whereas n is the number of commits since the last tag and hash is the commit hash of the latest commit. NewFromRepo will also increment the patch-level version component in case it detects that the current version is a pre-release. If the last tag has itself a pre-release-identifier and the last commit is not tagged, NewFromRepo will not increment the patch-level version. The prefix is an arbitrary string that is prepended to the version number. The not SemVer commpliant but commonly used prefix v will be automatically detected. The glob pattern can be used to limit the tags that are being considered in the calculation. The pattern allows the syntax described for filepath.Match.

func (Version) BumpTo

func (v Version) BumpTo(target Target) Version

BumpTo increases the version to the next patch/minor/major version. The version components with lower priority than the update target will be reset to zero.

  • If target devel -> x.y.z-pre.(n+1)
  • If target patch -> x.y.(z+1)
  • If target minor -> x.(y+1).0
  • If target major -> (x+1).0.0

func (Version) Format

func (v Version) Format(format string) (string, error)

Format returns a string representation of the version including the parts defined in the format string. The format can have the following components:

  • x -> major version
  • y -> minor version
  • z -> patch version
  • p -> pre-release
  • m -> metadata

x, y and z are separated by a dot. p is seprated by a hyphen and m by a plus sign. E.g.: x.y.z-p+m or x.y .

func (Version) PreRelease

func (v Version) PreRelease() string

PreRelease formats the pre-release version depending on the number n of commits since the last tag. If n is zero it returns the parsed pre-release version. If n is greater than zero it will append the string "pre.<n>" to the pre-release version.

func (Version) String

func (v Version) String() string

Jump to

Keyboard shortcuts

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