Documentation
¶
Overview ¶
Package config messages - error and log message constants Exported so tests can compare against them
Index ¶
- Constants
- func DefaultConfigYAML() string
- func DeleteCustom(key string) error
- func GetAllCustom() (map[string]string, error)
- func GetCustom(key string) (string, bool, error)
- func SetCustom(key, value string) error
- func Snapshot() (func() error, error)
- func ValidateTemplate(template string) error
- func WriteConfig(config *Config) error
- type BranchVersioningConfig
- type Config
- type DirtyConfig
- type GitConfig
- type LoggingConfig
- type MetadataConfig
- type PreReleaseConfig
- type ReleaseConfig
- type UpdateConfig
Constants ¶
const ( DefaultTagTemplate = "{{Prefix}}{{MajorMinorPatch}}{{PreReleaseWithDash}}" DefaultBranchTemplate = "{{BranchPrefix}}{{Tag}}" DefaultMessageTemplate = "Release {{MajorMinorPatch}}{{PreReleaseWithDash}}{{MetadataWithPlus}}" )
Release template defaults.
The tag default reproduces the historical tag ("v1.2.3") with one deliberate exception: build metadata is omitted. Go module versions reject SemVer build metadata, so a tag carrying "+" cannot be resolved as a module version. The metadata still reaches the tag message, and a project that wants it in the tag can append {{MetadataWithPlus}} to its own template.
The branch default is expressed in terms of {{BranchPrefix}} so that the existing branchPrefix setting keeps working untouched; a project that sets branchTemplate explicitly takes full control of the branch name.
const ( ErrConfigNotFound = "config file not found" ErrConfigParseFail = "failed to parse config file" ErrInvalidTemplateSyntax = "invalid template syntax" )
Error messages
const ( LogConfigLoaded = "config_loaded" LogConfigSaved = "config_saved" LogConfigCreated = "config_created" )
Log messages for structured logging
const ( // FilePermission is the default permission for created files (owner rw, group/other r) FilePermission os.FileMode = 0644 )
File permission constants
Variables ¶
This section is empty.
Functions ¶
func DefaultConfigYAML ¶
func DefaultConfigYAML() string
DefaultConfigYAML returns a well-documented default configuration as YAML
func DeleteCustom ¶
DeleteCustom removes a custom key from the config
func GetAllCustom ¶
GetAllCustom returns all custom key-value pairs
func Snapshot ¶ added in v0.3.0
Snapshot records the config file's exact bytes (or that there is none) and returns a function that puts them back. A command that writes the config before a version change that may be refused restores it with this, so the refusal leaves the config as it was, byte for byte.
func ValidateTemplate ¶
ValidateTemplate checks if a Mustache template is syntactically valid
func WriteConfig ¶
Types ¶
type BranchVersioningConfig ¶ added in v0.1.0
type BranchVersioningConfig struct {
// Enabled controls whether branch-aware versioning is active
// Default: false (opt-in)
Enabled bool `yaml:"enabled"`
// MainBranches is a list of branch patterns that produce clean versions
// Supports exact matches and glob patterns (e.g., "release/*")
// Default: ["main", "master", "release/*"]
MainBranches []string `yaml:"mainBranches"`
// PrereleaseTemplate is a Mustache template for the branch pre-release identifier
// Default: "{{EscapedBranchName}}-{{CommitsSinceTag}}"
PrereleaseTemplate string `yaml:"prereleaseTemplate"`
// Mode controls how branch pre-release interacts with existing pre-release
// "replace" (default): Branch pre-release replaces any existing pre-release
// "append": Branch pre-release is appended to existing pre-release
Mode string `yaml:"mode"`
}
BranchVersioningConfig holds branch-aware versioning configuration
type Config ¶
type Config struct {
Prefix string `yaml:"prefix"`
PreRelease PreReleaseConfig `yaml:"prerelease"`
Metadata MetadataConfig `yaml:"metadata"`
Release ReleaseConfig `yaml:"release"`
BranchVersioning BranchVersioningConfig `yaml:"branchVersioning"`
Logging LoggingConfig `yaml:"logging"`
Dirty DirtyConfig `yaml:"dirty,omitempty"`
Custom map[string]string `yaml:"custom,omitempty"`
Updates []UpdateConfig `yaml:"updates,omitempty"`
}
Config holds configuration for version metadata behavior
func ReadConfig ¶
ReadConfig reads the configuration from .versionator.yaml file
type DirtyConfig ¶ added in v0.3.0
type DirtyConfig struct {
// IgnoreUntracked leaves untracked files out, so a tree is dirty only for
// staged or unstaged changes to tracked files (as `git describe --dirty`).
// Default: false (untracked files count). The --ignore-untracked flag
// overrides it. The release command's clean-tree check follows it too:
// untracked-only trees can release, tracked changes still refuse.
IgnoreUntracked bool `yaml:"ignoreUntracked"`
}
DirtyConfig holds what counts as a dirty working tree for the dirty-derived template variables ({{Dirty}}, {{UncommittedChanges}}, {{DateTimeDirty}}) and the ci DIRTY variable.
type GitConfig ¶
type GitConfig struct {
HashLength int `yaml:"hashLength"`
}
GitConfig holds git-specific configuration
type LoggingConfig ¶
type LoggingConfig struct {
Output string `yaml:"output"` // console, json, development
}
LoggingConfig holds logging-specific configuration
type MetadataConfig ¶
type MetadataConfig struct {
Template string `yaml:"template"` // Mustache template with DOTS as separators: "{{BuildDateTimeCompact}}.{{ShortHash}}" → "20241211.abc1234"
Stable bool `yaml:"stable"` // If true, value is written to VERSION file; if false, generated at output time
Git GitConfig `yaml:"git"`
}
MetadataConfig holds build metadata configuration Metadata follows SemVer 2.0.0: appended with + (plus)
IMPORTANT: The Template is a Mustache template string. Use DOTS (.) to separate metadata identifiers per SemVer 2.0.0. Example: "{{BuildDateTimeCompact}}.{{ShortHash}}" → "20241211103045.abc1234"
The leading plus (+) is automatically prepended when using {{MetadataWithPlus}} Do NOT include the leading plus in your template.
Stability controls where the metadata value lives:
- Stable=true: Value is written to VERSION file
- Stable=false: Value is generated from template at output time (default)
type PreReleaseConfig ¶
type PreReleaseConfig struct {
Template string `yaml:"template"` // Mustache template with DASHES as separators: "alpha-{{CommitsSinceTag}}" → "alpha-5"
Stable bool `yaml:"stable"` // If true, value is written to VERSION file; if false, generated at output time
}
PreReleaseConfig holds pre-release identifier configuration Pre-release follows SemVer 2.0.0: appended with - (dash)
IMPORTANT: The Template is a Mustache template string. Use DASHES (-) to separate pre-release identifiers per SemVer 2.0.0. Example: "alpha-{{CommitsSinceTag}}" → "alpha-5"
The leading dash (-) is automatically prepended when using {{PreReleaseWithDash}} Do NOT include the leading dash in your template.
Stability controls where the pre-release value lives:
- Stable=true: Value is written to VERSION file (traditional release workflow)
- Stable=false: Value is generated from template at output time (default, CD workflow)
type ReleaseConfig ¶ added in v0.0.12
type ReleaseConfig struct {
// CreateBranch controls whether a release branch is created when tagging
// Default: true
CreateBranch bool `yaml:"createBranch"`
// BranchPrefix is prepended to the tag name to form the branch name
// Default: "release/" (e.g., tag "v1.2.3" -> branch "release/v1.2.3")
// Available to BranchTemplate as {{BranchPrefix}}.
BranchPrefix string `yaml:"branchPrefix"`
// TagTemplate is a Mustache template for the tag name.
// Default: DefaultTagTemplate.
//
// Beyond the usual template variables, {{ModulePath}} renders the VERSION
// file's directory relative to the repository root with a trailing slash
// (empty at the root), and {{ModuleName}} renders that directory's bare
// name. {{ModulePath}} is what Go's module system requires of a submodule
// tag:
//
// tagTemplate: "{{ModulePath}}{{Prefix}}{{MajorMinorPatch}}"
// -> internal/tools/v1.2.3 in internal/tools, v1.2.3 at the root
//
// A literal path works equally well when the layout is fixed:
//
// tagTemplate: "internal/tools/{{Prefix}}{{MajorMinorPatch}}"
TagTemplate string `yaml:"tagTemplate"`
// BranchTemplate is a Mustache template for the release branch name.
// Default: DefaultBranchTemplate. In addition to the usual variables,
// {{Tag}} holds the already-rendered tag name and {{BranchPrefix}} holds
// the BranchPrefix setting.
BranchTemplate string `yaml:"branchTemplate"`
// MessageTemplate is a Mustache template for the annotated tag message.
// Default: DefaultMessageTemplate. {{Tag}} is available here too.
// The --message flag overrides this for a single invocation.
MessageTemplate string `yaml:"messageTemplate"`
}
ReleaseConfig holds release-related configuration
type UpdateConfig ¶ added in v0.1.0
type UpdateConfig struct {
// File is the path to the file to update (relative to repo root)
File string `yaml:"file"`
// Path is the dasel selector for the value to update (e.g., "package.version")
Path string `yaml:"path"`
// Template is a Mustache template for the new value (e.g., "{{MajorMinorPatch}}")
Template string `yaml:"template"`
// Format explicitly sets the file format (json, yaml, toml). Auto-detected from extension if empty.
Format string `yaml:"format,omitempty"`
}
UpdateConfig holds configuration for a single structured file update Updates are applied during release to keep manifest files in sync with VERSION