tagfmt

package
v0.76.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBuildIDRequired = errors.New("tag format template contains " + buildToken + " but no build ID was provided; " +
	"pass --set-build-id <id> (with --set-version <version> if not already given) to " +
	"`heraut changelog`, `heraut release` or `heraut version next`")

ErrBuildIDRequired is returned by Render when the template contains {build} but no build ID was supplied. Callers classify it with errors.Is — a missing build ID is a usage problem, not a runtime failure.

Functions

func DeriveHeadingVersionPattern added in v0.20.0

func DeriveHeadingVersionPattern(template string) string

DeriveHeadingVersionPattern returns a heading-postprocessor regex, consumed by native, that strips every non-{version} token (env prefix/suffix and build) from a changelog version heading, leaving only the version. The replacement is "[$1]". Examples:

{version}_{env}          [2026.3.0_prod]      → [2026.3.0]
{env}/{version}+{build}  [uat/7.4.1+158404]   → [7.4.1]
{env}/{version}          [prod/1.2.3]         → [1.2.3]

Returns "" when there is nothing to strip — no {version}, or neither {env} nor {build} present (a plain or "v"-prefixed version heading is already clean).

All wildcards exclude "]" so a match can never span two headings (postprocessors run against the whole rendered document). The greedy version capture plus the anchored trailing token handle SemVer pre-release segments (e.g. 7.4.1-rc.1) under the "+" build separator without special-casing.

func DeriveTagPattern added in v0.20.0

func DeriveTagPattern(template string, t Tokens) string

DeriveTagPattern returns an anchored regex, consumed by native to scope its tag walk, that matches only the given environment's tags. {env} becomes the literal t.Env, {version} and {build} become wildcards. Returns "" when the template has no {env} token or t.Env is empty — there is nothing to scope in those cases.

func GlobPattern

func GlobPattern(template string, t Tokens) (string, error)

GlobPattern returns a git tag glob pattern for listing tags under the given env.

func ParseVersion

func ParseVersion(template, tag string) (string, error)

ParseVersion extracts the version string from a tag using the given template.

func Render

func Render(template string, t Tokens) (string, error)

Render substitutes {version}, {env}, and {build} tokens in template. t.Build may be empty when {build} is not present in the template; if {build} is present but t.Build is empty, ErrBuildIDRequired is returned.

func ValidateBuildID added in v0.19.0

func ValidateBuildID(build string) error

ValidateBuildID checks that a build ID is usable as a tag component: non-empty, no "/" (path separator) and no whitespace (git ref constraints). CI build IDs like "$CI_PIPELINE_ID" and "$GITHUB_RUN_NUMBER" satisfy this.

func ValidateVersionOverride added in v0.32.0

func ValidateVersionOverride(version string) error

ValidateVersionOverride checks that a --set-version value is usable as a tag/version override: non-empty and free of whitespace (git ref constraints). Unlike ValidateBuildID, "/" is allowed — a full tag override may legitimately contain one. heraut is strategy-agnostic about the shape of the override (SemVer, CalVer, or any other scheme the user's tag_format expects).

Types

type Tokens added in v0.62.1

type Tokens struct {
	Version string
	Env     string
	Build   string
}

Tokens holds the substitution values for a tag format template. Bundling them as a struct (rather than growing the positional-parameter list of every function below) gives future tokens — e.g. a monorepo {package} token — a seam to land in without re-touching every call site's signature a second time.

Jump to

Keyboard shortcuts

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