Documentation
¶
Index ¶
Constants ¶
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.
const DefaultPrefix = "v"
DefaultPrefix that is recognized and ignored by the parser.
const DefaultTarget = Devel
The DefaultTarget when calculating the next version.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RepoHead ¶
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.
type Target ¶
type Target int
Target specifies a component of a semantic version that should be updated to.
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.