gotversion

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2018 License: MIT Imports: 11 Imported by: 0

README

GotVersion

GotVersion is a small tool that examines your Git repositry and tries to come up with the most meaningful and consistent semantic version string. It's inspired by GitVersion. If you are looking for a mature and super configurable solution you should definitely look into it.

Goals

The goal of GotVersion is to be lightweight, fast and friendly to CI pipelines usage. It currently output JSON and VSO renders of the calculated solution. There is currently no configuration which means it's a bit opiniated on your usage of Git tags. If you use GitFlow or GitHubFlow it should fit perfectly.

Building

The easiest way to buld GotVersion is using Docker

$ git clone https://github.com/loafoe/gotversion.git
$ cd gotversion
$ docker build -t gotversion .

Running

The Docker image will examine the Git repo mounted on /repo:

$ docker run --rm -v /path/to/git/repository:/repo gotversion 

By default it outputs VSO lines:

##vso[task.setvariable variable=SemVer;isOutput=true;]0.4.0
##vso[task.setvariable variable=FullSemVer;isOutput=true;]0.4.0
##vso[task.setvariable variable=SHA;isOutput=true;]0de2be93db13828f1d5f43896406f4902ab4159c
##vso[task.setvariable variable=CommitDate;isOutput=true;]2018-10-04
##vso[task.setvariable variable=BranchName;isOutput=true;]master

Azure DevOPS

These lines, when executed as a Docker run task in an Azure DevOPS (VSTS) pipeline will inject the following variable for use in downstream tasks:

Variable ENV name Description
$(Docker.GotSemVer) $DOCKER_SEMVER Abbreviated semantic version of the current build
$(Docker.GotFullSemVer) $DOCKER_FULLSEMVER The full semantic version (recommended)
$(Docker.GotSHA) $DOCKER_SHA The full SHA1 of the branch head
$(Docker.GotCommitDate) $DOCKER_COMMITDATE The date of the commit in YYYY-MM-DD format
$(Docker.GotBranchName) $DOCKER_BRANCHNAME The Git branch name

You can also have it emit JSON:

$ docker run --rm -v /path/to/git/repository:/repo gotversion -json

Will output something like:

{
  "Major": 0,
  "Minor": 4,
  "Patch": 0,
  "SemVer": "0.4.0",
  "FullSemVer": "0.4.0",
  "MajorMinorPatch": "0.4.0",
  "BranchName": "master",
  "Sha": "0de2be93db13828f1d5f43896406f4902ab4159c",
  "CommitDate": "2018-10-04",
  "FullBuildMetaData": "Branch.master.Sha.0de2be93db13828f1d5f43896406f4902ab4159c"
}

License

License is MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotATag = errors.New("not a tag")
)

Errors

View Source
var (
	ErrOutputNotFound = errors.New("output not found")
)

Error conditions

Functions

func BranchName

func BranchName(r *git.Repository) string

BranchName returns the branch name which we're on

func Bump

func Bump(currentVersion *version.Version, strategy Strategy) (*version.Version, error)

Bump the Tag version based on the strategy

func OutputJSON

func OutputJSON(base *Base) error

OutputJSON outputs gotversion results in JSON

func OutputVSO

func OutputVSO(base *Base) error

OutputVSO outputs variables to Azure DevOPS output

func SemverTags

func SemverTags(r *git.Repository) (*[]Tag, error)

SemverTags returns only valid semver tags

Types

type Base

type Base struct {
	*version.Version
	Head     *object.Commit
	Branch   string
	Strategy Strategy
	Offset   int
	Tag      Tag
}

Base is a (potential) base version

func (Base) BranchName

func (b Base) BranchName() string

BranchName returns the branch name

func (Base) BuildMetadata

func (b Base) BuildMetadata() int

BuildMetadata returns the offset

func (*Base) Bump

func (b *Base) Bump() error

Bump version

func (Base) Commit

func (b Base) Commit() string

Commit returns the hash of the head

func (Base) CommitDate

func (b Base) CommitDate() string

CommitDate returns the commit date of head

func (Base) FullBuildMetaData

func (b Base) FullBuildMetaData() string

FullBuildMetaData returns branch and SHA details

func (Base) FullSemver

func (b Base) FullSemver() string

FullSemver returns Semver with offset in case no tags are there

func (Base) HeadTag

func (b Base) HeadTag() bool

HeadTag returns true if the tag is on the branch head Typically this means we should not Bump() the version

func (Base) IsDevelopBranch

func (b Base) IsDevelopBranch() bool

IsDevelopBranch return true if we are on the develop branch

func (Base) IsFeatureBranch

func (b Base) IsFeatureBranch() bool

IsFeatureBranch returns true if we are on a feature branch

func (Base) IsMasterBranch

func (b Base) IsMasterBranch() bool

IsMasterBranch returns true if we are on the master branch

func (Base) Major

func (b Base) Major() int

Major returns the Major semver element

func (Base) MajorMinorPatch

func (b Base) MajorMinorPatch() string

MajorMinorPatch returns the primary semver string

func (Base) Minor

func (b Base) Minor() int

Minor returns the Minor semver element

func (Base) Patch

func (b Base) Patch() int

Patch returns the Major semver element

func (Base) PreReleaseLabel

func (b Base) PreReleaseLabel() string

PreReleaseLabel is determined by the branch name

func (Base) PreReleaseNumber

func (b Base) PreReleaseNumber() string

PreReleaseNumber returns the number of commits since the Base

func (Base) Semver

func (b Base) Semver() string

Semver where it all boils down to

func (Base) String

func (b Base) String() string

type BaseCollection

type BaseCollection []*Base

BaseCollection implements the Sortable interface

func (BaseCollection) Len

func (v BaseCollection) Len() int

func (BaseCollection) Less

func (v BaseCollection) Less(i, j int) bool

func (BaseCollection) Swap

func (v BaseCollection) Swap(i, j int)

type Outputer

type Outputer interface {
	Output(base *Base) error
}

Outputer interface

type Outputs

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

Outputs holds all the output plugins

func NewOutputs

func NewOutputs() *Outputs

NewOutputs returns a new output registry

func (*Outputs) Output

func (o *Outputs) Output(name string, base *Base) error

Output performs the output for the given outputer, if present

func (*Outputs) Register

func (o *Outputs) Register(name string, output Outputer)

Register registers a Outputer by name. This is expected to happen during app startup.

func (*Outputs) Registered

func (o *Outputs) Registered() []string

Registered enumerates the names of all registered plugins.

type Strategy

type Strategy int

Strategy determines which part of semver to bump

const (
	Major Strategy = 0
	Minor Strategy = 1
	Patch Strategy = 2
)

Const definitions

func (Strategy) String

func (strategy Strategy) String() string

type Tag

type Tag struct {
	*version.Version
	Reference plumbing.Reference
	IsAnnoted bool
	Hash      string
}

Tag holds our representation of a Tag (both annoted and lightweight)

func HeadTag

func HeadTag(r *git.Repository) (*Tag, error)

HeadTag returns the tag name of HEAD, if any

func (Tag) String

func (t Tag) String() string

type TagCollection

type TagCollection []*Tag

TagCollection implements the Sortable interface

func (TagCollection) Len

func (v TagCollection) Len() int

func (TagCollection) Less

func (v TagCollection) Less(i, j int) bool

func (TagCollection) Swap

func (v TagCollection) Swap(i, j int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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