Documentation ¶
Index ¶
- func CheckGitRepo(dir string) (repo string, err error)
- type DefaultGitter
- func (dg DefaultGitter) GetBranch(repo string) (branch string)
- func (dg DefaultGitter) GetBranchesFromTag(repo, tag string) (branches []string)
- func (dg DefaultGitter) GetBuild(repo string) string
- func (dg DefaultGitter) GetTag(repo string) string
- func (dg DefaultGitter) GetTagForHEAD(repo string) (tag string)
- type Environment
- type Gitter
- type OsEnvironment
- type VersionInfo
- type VersionStringer
- func (vs *VersionStringer) GetBranch(repo string) (branchText, branchName string)
- func (vs *VersionStringer) GetBuild(repo string) (build string)
- func (vs *VersionStringer) GetTag(repo string) (tag string, err error)
- func (vs *VersionStringer) GetVersion(repo string) (vi VersionInfo, err error)
- func (vs *VersionStringer) IsEnvTrue(envvar string) bool
- func (vs *VersionStringer) IsReleaseBranch(branchName string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckGitRepo ¶
CheckGitRepo checks that the given directory is part of a git repository, meaning that it or one of it's parent directories has a '.git' subdirectory. If it is, it returns the absolute path of the git repo and a nil error.
Types ¶
type DefaultGitter ¶
type DefaultGitter string
func (DefaultGitter) GetBranch ¶
func (dg DefaultGitter) GetBranch(repo string) (branch string)
func (DefaultGitter) GetBranchesFromTag ¶
func (dg DefaultGitter) GetBranchesFromTag(repo, tag string) (branches []string)
func (DefaultGitter) GetBuild ¶
func (dg DefaultGitter) GetBuild(repo string) string
func (DefaultGitter) GetTag ¶
func (dg DefaultGitter) GetTag(repo string) string
func (DefaultGitter) GetTagForHEAD ¶
func (dg DefaultGitter) GetTagForHEAD(repo string) (tag string)
type Environment ¶
Environment allows us to mock the OS environment
type Gitter ¶
type Gitter interface { // GetTag returns the latest Git tag that starts with a lowercase 'v' followed by a number, otherwise an empty string. GetTag(repo string) string // GetBranch returns the current branch in the repository, or the string "HEAD" if we're in a Git repo, otherwise an empty string. GetBranch(repo string) string // GetBranchesFromTag returns the non-HEAD branches in the repository that have the tag, otherwise an empty string. GetBranchesFromTag(repo, tag string) []string // GetBuild returns the number of commits in the currently checked out branch as a string, or an empty string GetBuild(repo string) string // GetTagForHEAD returns the tag that exactly match the current HEAD, or an empty string GetTagForHEAD(repo string) string }
Gitter is an interface exposing the required Git functionality
func NewDefaultGitter ¶
type OsEnvironment ¶
type OsEnvironment struct{}
OsEnvironment calls the OS functions.
func (OsEnvironment) Getenv ¶
func (OsEnvironment) Getenv(key string) string
type VersionInfo ¶
type VersionInfo struct { Tag string // git tag, e.g. "v1.2.3" Branch string // git branch, e.g. "mybranch" Build string // git or CI build number, e.g. "456" Version string // composite version, e.g. "v1.2.3-mybranch.456" }
func (*VersionInfo) Render ¶
func (vi *VersionInfo) Render(pkgName string) (string, error)
Render returns either the Version string followed by a newline, or, if the pkgName is not an empty string, a small piece of Go code defining global variables named "PkgName" and "PkgVersion" with the given pkgName and the contents of Version. If the pkgName is given but isn't a valid Go identifier, an error is returned.
type VersionStringer ¶
type VersionStringer struct { Git Gitter // Git Env Environment // environment }
func NewVersionStringer ¶
func NewVersionStringer(gitBin string) (vs *VersionStringer, err error)
NewVersionStringer returns a VersionStringer ready to examine the git repositories using the given Git binary.
func (*VersionStringer) GetBranch ¶
func (vs *VersionStringer) GetBranch(repo string) (branchText, branchName string)
GetBranch returns the current branch as a string suitable for inclusion in the semver text as well as the actual branch name in the build system or Git. If no branch name can be found, then "HEAD" is returned if we are running within a Git repo, or an empty string if we're not.
func (*VersionStringer) GetBuild ¶
func (vs *VersionStringer) GetBuild(repo string) (build string)
GetBuild returns the build counter. This is taken from the CI system if available, otherwise the Git commit count is used. Returns an empty string if no reasonable build counter can be found.
func (*VersionStringer) GetTag ¶
func (vs *VersionStringer) GetTag(repo string) (tag string, err error)
GetTag returns the git version tag. Returns an error if the tag is not in the form "vX.Y.Z".
func (*VersionStringer) GetVersion ¶
func (vs *VersionStringer) GetVersion(repo string) (vi VersionInfo, err error)
GetVersion returns a version string for the source code in the Git repository.
func (*VersionStringer) IsEnvTrue ¶
func (vs *VersionStringer) IsEnvTrue(envvar string) bool
IsEnvTrue returns true if the given environment variable exists and is set to the string "true" (not case sensitive).
func (*VersionStringer) IsReleaseBranch ¶
func (vs *VersionStringer) IsReleaseBranch(branchName string) bool
IsReleaseBranch returns true if the given branch name should be allowed to use 'release mode', where the version string doesn't contains build information suffix.