taggrammar

package
v0.12.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package taggrammar is the single source of truth for the shape of cascade's own release tags. It is intentionally dependency-free (stdlib only) so that both version discovery and git tagging can share one grammar without pulling in cascade internals.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parsed

type Parsed struct {
	Major      int
	Minor      int
	Patch      int
	PreRelease int
	Hotfix     int
}

Parsed holds the numeric fields of a version tag. PreRelease and Hotfix use -1 to mean absent, matching the convention used elsewhere in cascade.

type Spec

type Spec struct {
	// Prefix is the literal string that leads a tag, historically "v".
	Prefix string
	// PreReleaseToken names a pre-release, historically "rc".
	PreReleaseToken string
	// PreReleaseSeparator sits between the token and its number,
	// historically ".".
	PreReleaseSeparator string
	// DryRunToken names a rehearsal tag, historically "dryrun". Rehearsal
	// tags are deliberately not version-parseable so they stay invisible to
	// version discovery.
	DryRunToken string
	// StrictPrefix, when true, reads the prefix literally. When false the
	// read side accepts any alphabetic prefix so historical and foreign-cased
	// tags still parse.
	StrictPrefix bool
}

Spec describes the shape of a release tag. The zero value is not usable; construct a Spec with Default and override individual fields as needed. Every field defaults to cascade's historical grammar.

func Default

func Default() Spec

Default returns the historical cascade grammar: v-prefixed semantic versions with "rc." pre-releases and "dryrun" rehearsal tags.

func (Spec) Format

func (s Spec) Format(p Parsed) string

Format renders p under this Spec. It always emits the prefix and numeric core, appends "-<token><separator><n>" when PreRelease is present, and appends ".hotfix.<m>" when Hotfix is present.

func (Spec) IsVersionTag

func (s Spec) IsVersionTag(tag string) bool

IsVersionTag reports whether tag is a version-parseable tag under this Spec. Rehearsal (dryrun) tags and foreign tags return false so they stay invisible to version discovery.

func (Spec) Parse

func (s Spec) Parse(tag string) (Parsed, bool)

Parse extracts the numeric fields of tag under this Spec. It returns ok=false when tag is not a version tag. An absent pre-release or hotfix is reported as -1.

func (Spec) PreReleaseStripSedBRE

func (s Spec) PreReleaseStripSedBRE() string

PreReleaseStripSedBRE returns the anchored sed basic-regular-expression that matches this spec's pre-release segment at the end of a version string, for example "-rc\.[0-9]*$" for the default grammar and "-beta[0-9]*$" for a beta token with an empty separator. Both the token and the separator are escaped, so a metacharacter such as "." (a value the config allowlist otherwise permits in either field) matches literally instead of as a wildcard. Code generators bake this into the driven repo's release workflow so the emitted strip follows the configured grammar.

func (Spec) StripPreRelease

func (s Spec) StripPreRelease(tag string) string

StripPreRelease returns tag with its pre-release segment (and anything after it, such as a nested hotfix) removed, leaving just the prefix and numeric core. It cuts at this spec's pre-release marker ("-" + token + separator), so the default grammar cuts at "-rc." exactly as the historical literal strip did, byte for byte. A tag without the marker is returned unchanged.

Jump to

Keyboard shortcuts

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