gitsemver

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BumpTypePatch     = "patch"
	BumpTypeMinor     = "minor"
	BumpTypeMajor     = "major"
	BumpTypePatchRC   = "patch-rc"
	BumpTypeMinorRC   = "minor-rc"
	BumpTypeMajorRC   = "major-rc"
	BumpTypeRC        = "rc"
	BumpTypeRCRelease = "rc-release"
)

Bump type constants for use with ComputeNextVersion and NextVersion.

Variables

ValidBumpTypes lists all accepted bump-type values in their canonical order.

Functions

func ComputeNextVersion added in v1.1.0

func ComputeNextVersion(lastTag, bumpType string) (string, error)

ComputeNextVersion returns the next version after lastTag for the given bumpType. It is a pure function — no git access is required.

Valid from a stable tag (X.Y.Z): patch, minor, major, patch-rc, minor-rc, major-rc. Valid from an RC tag (X.Y.Z-rc.N): rc (bump counter), rc-release (finalize to stable).

The returned string never carries a leading "v".

Callers are responsible for stripping the GS_GIT_TAG_PREFIX and the separating "/" before passing lastTag to this function. For example, "module-a/v1.2.3" must be passed as "v1.2.3" (or "1.2.3").

func IsValid

func IsValid(version string) bool

IsValid reports whether version is a valid version string in any of the three recognised formats: stable, RC, or dev build.

func IsValidDev

func IsValidDev(version string) bool

IsValidDev reports whether version is a valid dev-build version (X.Y.Z-dev.<branch>.<YYYY-MM-DD>.<HH-MM-SS> or with a leading v, no leading zeros in X.Y.Z components).

func IsValidRC

func IsValidRC(version string) bool

IsValidRC reports whether version is a valid release-candidate version (X.Y.Z-rc.N or vX.Y.Z-rc.N, no leading zeros in any numeric component).

func IsValidStable

func IsValidStable(version string) bool

IsValidStable reports whether version is a valid stable release version (X.Y.Z or vX.Y.Z, no leading zeros in any component).

func TopLevel

func TopLevel(path string) (string, error)

TopLevel finds absolute path of top-level git directory. The output is the same as `git rev-parse --show-toplevel`.

Types

type Config

type Config struct {
	AuthBasicToken string
	Dir            string
	URL            string
}

type ExecutionFailedError

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

func (*ExecutionFailedError) Error

func (e *ExecutionFailedError) Error() string

func (*ExecutionFailedError) Is

func (e *ExecutionFailedError) Is(target error) bool

type FileNotFoundError

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

func (*FileNotFoundError) Error

func (e *FileNotFoundError) Error() string

func (*FileNotFoundError) Is

func (e *FileNotFoundError) Is(target error) bool

type FolderNotFoundError

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

func (*FolderNotFoundError) Error

func (e *FolderNotFoundError) Error() string

func (*FolderNotFoundError) Is

func (e *FolderNotFoundError) Is(target error) bool

type InvalidConfigError

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

func (*InvalidConfigError) Error

func (e *InvalidConfigError) Error() string

func (*InvalidConfigError) Is

func (e *InvalidConfigError) Is(target error) bool

type ReferenceNotFoundError

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

func (*ReferenceNotFoundError) Error

func (e *ReferenceNotFoundError) Error() string

func (*ReferenceNotFoundError) Is

func (e *ReferenceNotFoundError) Is(target error) bool

type Repo

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

func New

func New(config Config) (*Repo, error)

func (*Repo) EnsureUpToDate

func (r *Repo) EnsureUpToDate(ctx context.Context) error

EnsureUpToDate fetches latest changes from remote.

func (*Repo) HeadBranch

func (r *Repo) HeadBranch(ctx context.Context) (string, error)

HeadBranch returns branch name for the HEAD ref.

func (*Repo) HeadSHA

func (r *Repo) HeadSHA(ctx context.Context) (string, error)

HeadSHA returns sha for the HEAD ref.

func (*Repo) HeadTag

func (r *Repo) HeadTag(ctx context.Context) (string, error)

HeadTag returns tag for the HEAD ref.

If GS_GIT_TAG_PREFIX environment variable is set, it looks for tags prefixed with that. For example, when the value is 'module-a', it filters found tags to 'module-a/v1.2.0', must match <module_name>/v<semantic_version>.

Note: if GS_GIT_TAG_PREFIX is not set, all tags matching the prefixed tag regex are filtered out!

It returns a *ReferenceNotFoundError when the HEAD ref is not tagged, detectable via errors.Is(err, &ReferenceNotFoundError{}).

func (*Repo) NextVersion added in v1.1.0

func (r *Repo) NextVersion(ctx context.Context, bumpType string) (string, error)

NextVersion returns the next version tag after the highest-semver tag reachable from HEAD for the given bumpType.

Valid bump types from a stable tag: patch, minor, major, patch-rc, minor-rc, major-rc. Valid bump types from an RC tag: rc (bump counter), rc-release (finalize to stable).

When no version tags are reachable from HEAD, v0.0.0 is used as the implicit base, which means only the stable bump types (patch/minor/major/patch-rc/minor-rc/major-rc) are valid.

The returned string never carries a leading "v". If GS_GIT_TAG_PREFIX is set, only tags carrying that prefix are considered (monorepo support).

func (*Repo) ReadFileAtRef added in v1.1.0

func (r *Repo) ReadFileAtRef(ctx context.Context, path, ref string) ([]byte, error)

ReadFileAtRef retrieves content of file stored at path on version specified in ref. When empty ref defaults to master branch. Note: internally this checks out the given ref, mutating the working tree.

func (*Repo) ReadFolderAtRef added in v1.1.0

func (r *Repo) ReadFolderAtRef(ctx context.Context, path, ref string) ([]os.FileInfo, error)

ReadFolderAtRef retrieves content of a folder stored at path on version specified in ref. When empty ref defaults to master branch. Note: internally this checks out the given ref, mutating the working tree.

func (*Repo) ResolveVersion

func (r *Repo) ResolveVersion(ctx context.Context, ref string) (string, error)

ResolveVersion resolves the version for a git reference:

  • Stable tag vX.Y.Z on the commit → returns "X.Y.Z"
  • Pre-release tag vX.Y.Z-<pre> on the commit → returns "X.Y.Z-<pre>" (e.g. "1.2.3-rc.1")
  • Untagged commit → returns a semVer dev build: "X.Y.(Z+1)-dev.<branch>.<YYYY-MM-DD>.<HH-MM-SS>" where X.Y.Z is the most recent stable (non-pre-release) ancestor tag reachable from the reference, or "0.0.0" when no stable ancestor exists. The branch name is resolved from GS_BRANCH_NAME env var, then the HEAD branch of the CWD git repo, then "unknown". Non-reachable tags are never used as the base.

If GS_GIT_TAG_PREFIX is set, only tags prefixed with "<value>/" are considered, e.g. "module-a/v1.2.3". The prefix, separator, and "v" are stripped from the result.

It returns a *ReferenceNotFoundError when the reference cannot be resolved, detectable via errors.Is(err, &ReferenceNotFoundError{}).

type RepositoryNotFoundError

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

func (*RepositoryNotFoundError) Error

func (e *RepositoryNotFoundError) Error() string

func (*RepositoryNotFoundError) Is

func (e *RepositoryNotFoundError) Is(target error) bool

Jump to

Keyboard shortcuts

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