Documentation
¶
Overview ¶
Package tagfmt renders and parses tag formats ({version}, {env}, {build}) and derives the globs and patterns that list an environment's tags.
Index ¶
- Variables
- func DeriveHeadingVersionPattern(template string) string
- func DeriveTagPattern(template string, t Tokens) string
- func GlobPattern(template string, t Tokens) (string, error)
- func ParseVersion(template, tag string) (string, error)
- func Render(template string, t Tokens) (string, error)
- func ValidateBuildID(build string) error
- func ValidateVersionOverride(version string) error
- type Tokens
Constants ¶
This section is empty.
Variables ¶
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
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]
prod/{version} [prod/1.2.3] → [1.2.3]
Literal text is stripped like a token, so an env spelled out in the format reads as one written {env}. Returns "" when there is nothing to strip: no {version}, or a plain or "v"-prefixed version (whose 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
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 ¶
GlobPattern returns a git tag glob pattern for listing tags under the given env.
func ParseVersion ¶
ParseVersion extracts the version string from a tag using the given template.
func Render ¶
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
ValidateBuildID checks that a build ID is usable as a tag component: non-empty and made of letters, digits, ".", "_" and "-" (ADR-0074). The value reaches the tag and from there the hook commands, so shell and git metacharacters, "/" and whitespace are refused. CI build IDs like a run number, a pipeline ID or a short SHA satisfy this.
func ValidateVersionOverride ¶ added in v0.32.0
ValidateVersionOverride checks that a --set-version value is usable as a tag/version override: non-empty, free of whitespace (git ref constraints) and made only of 0-9A-Za-z._+/-, the characters every SemVer and CalVer version (build metadata and a full tag wrapping included) is built from (ADR-0074). Unlike ValidateBuildID, "/" and "+" are allowed. The value reaches tags and hook environments, so anything a shell or a glob would read as syntax is refused here, under whatever scheme the user's tag_format expects.
Types ¶
type Tokens ¶ added in v0.62.1
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.