Documentation
¶
Overview ¶
Package app is the wiring layer: it reads the config and builds the resolvers, generators, platforms and pipelines the commands run. It is the only package that constructs concrete implementations.
Index ¶
- Constants
- Variables
- func AllowedCommitTypes(cfg *config.Config) []string
- func BuildChangelogPipeline(runner port.Runner, cfg *config.Config, resolver versioning.Resolver, ...) (*pipeline.ChangelogPipeline, error)
- func BuildPipeline(runner port.Runner, cfg *config.Config, resolver versioning.Resolver, ...) (*pipeline.Pipeline, error)
- func ChangelogHookPoints() []string
- func CheckBranch(runner port.Runner, cfg *config.Config, env string, force bool) error
- func CheckFullHistory(runner port.Runner) error
- func CheckHasCommits(runner port.Runner) error
- func CheckReleaseBranch(runner port.Runner, cfg *config.Config, force bool) error
- func CurrentTag(runner port.Runner, cfg *config.Config, env string, includePreRelease bool) (string, error)
- func CurrentVersion(runner port.Runner, cfg *config.Config, env string, includePreRelease bool) (string, error)
- func HasResolvablePublishTarget(runner port.Runner, cfg *config.Config, env string) bool
- func IsBranchMismatch(err error) bool
- func IsBuildIDRequired(err error) bool
- func IsEnvSelection(err error) bool
- func IsMajorNotConfirmed(err error) bool
- func IsNothingToRelease(err error) bool
- func IsPromotionGuard(err error) bool
- func IsUnusableCheckout(err error) bool
- func NewMemoizingRunner(r port.Runner) port.Runner
- func NewResolver(cfg *config.Config, env string, force bool, versionOverride, buildID string, ...) (versioning.Resolver, error)
- func PreflightCheck(runner port.Runner) error
- func PromotionGuardID(err error) string
- func PublishesReleases(cfg *config.Config, env string) bool
- func ReadGPGSign(runner port.Runner) bool
- func ReleaseHookPoints() []string
- func ResolveEnv(env string, cfg *config.Config, runner port.Runner) (string, error)
- func ResolveFromLatestTag(runner port.Runner, cfg *config.Config, env string) (string, bool, error)
- func RuntimeCheck(ctx context.Context, runner port.Runner, cfg *config.Config, env string, ...)
- func ShallowCloneWarning(runner port.Runner) string
- func ValidateBuildID(build string) error
- func ValidateSkipHooks(values, allowed []string) ([]string, error)
- func ValidateVersionOverride(version string) error
- type CheckoutError
- type CommitCheckResult
- type CommitSummary
- type NotesOpts
- type NotesResult
- type PipelineOpts
- type PlanStep
- type ReleasePlan
- type ResolverOption
- type RuntimeCheckItem
- type TicketCheckResult
Constants ¶
const NoReleaseBlockNotice = "publishing is off: the config has no release: block, so no forge release is created (add release: {} to publish)"
HasResolvablePublishTarget reports whether cfg has at least one publish destination for env: a non-empty effective release.targets list, or — when that list is empty — a forge that resolves to a type with a publish driver, from cfg/CI env/git origin (the same zero-config synthesis buildTargetPlatforms performs, via synthesizeDefaultTarget — T221 taught both to treat a driver-less resolved forge, e.g. azure_devops, as equivalent to no forge resolved at all, so this preflight and the pipeline's own behavior can never disagree). This is heraut release's pre-flight gate: with release.platforms gone, "no entry in release.targets and nothing auto-detects to a publishable forge" is the only shape left that must hard-fail before the pipeline runs (see buildTargetPlatforms — resolving zero forges is not itself an error, since a changelog-only flow legitimately needs no publish target at all).
An *explicit* release.targets entry naming a driver-less forge is deliberately not caught here — that is a user-authored reference, and buildPlatform's own "unsupported platform" error is already specific and actionable when the pipeline actually tries to build it (T221).
A forge-resolution error here (e.g. an ambiguous multi-token machine) is deliberately treated as "not resolvable" rather than propagated: BuildPipeline performs the same resolution again and surfaces that error with full context, so this pre-flight only needs a yes/no answer. NoReleaseBlockNotice is the warning heraut release gives when the config has no release: block.
Variables ¶
var ( ErrUnlistedBranch = branch.ErrUnlistedBranch ErrAmbiguousBranch = branch.ErrAmbiguousBranch ErrUnderivableRange = branch.ErrUnderivableRange )
The branch rules live in internal/versioning/branch; cmd reaches them through app.
var DefaultCommitTypes = commitTypeNames(config.EffectiveTypes(nil))
DefaultCommitTypes is the type allow-list applied when commits.types adds no overrides: the names of the built-in default type set (config.EffectiveTypes(nil)).
var ErrNotesFormat = errors.New("invalid --format")
ErrNotesFormat marks an unsupported --format value.
var ErrNotesNotReleaseTag = errors.New("not a release tag")
ErrNotesNotReleaseTag marks a requested tag that is not a release tag of the active strategy and environment (another environment's tag, a build marker).
var ErrNotesRange = errors.New("invalid notes range")
ErrNotesRange marks a --from tag outside the history of the requested tag.
var ErrNotesTagNotFound = errors.New("tag not found")
ErrNotesTagNotFound marks a tag (or --from tag) that does not exist.
Functions ¶
func AllowedCommitTypes ¶ added in v0.44.0
AllowedCommitTypes returns the effective commit-type allow-list: the names of config.EffectiveTypes(commits.types) — the built-in defaults with the user's commits.types merged over them. Single source of truth shared by VerifyCommit and the commit wizard.
func BuildChangelogPipeline ¶ added in v0.6.0
func BuildChangelogPipeline(runner port.Runner, cfg *config.Config, resolver versioning.Resolver, opts PipelineOpts) (*pipeline.ChangelogPipeline, error)
BuildChangelogPipeline constructs a ChangelogPipeline from config.
func BuildPipeline ¶
func BuildPipeline(runner port.Runner, cfg *config.Config, resolver versioning.Resolver, opts PipelineOpts) (*pipeline.Pipeline, error)
BuildPipeline constructs a release Pipeline from config. All generator and platform instances are created here — none are created in internal/cmd/.
func ChangelogHookPoints ¶ added in v0.69.0
func ChangelogHookPoints() []string
ChangelogHookPoints returns the hook points `heraut changelog` runs — the release list minus pre_release/post_release, since the changelog-only pipeline never publishes.
func CheckBranch ¶ added in v0.20.0
CheckBranch enforces the per-environment branch guard (see branch.CheckBranch).
func CheckFullHistory ¶ added in v1.0.1
CheckFullHistory refuses a shallow clone. A cut history can hide the last release tag or part of the commit range, so the version and the changelog would be wrong. When git cannot answer, it returns nil: the other git calls of the run report a broken repository.
func CheckHasCommits ¶ added in v1.0.1
CheckHasCommits refuses a repository whose branch has no commit yet: there is nothing to version, tag or describe. HEAD then names a branch that does not resolve. When git cannot answer either question (not a repository at all), it returns nil: the run's other git calls report it.
func CheckReleaseBranch ¶ added in v0.75.0
CheckReleaseBranch enforces versioning.branches for a release (see branch.CheckReleaseBranch).
func CurrentTag ¶ added in v0.4.0
func CurrentTag(runner port.Runner, cfg *config.Config, env string, includePreRelease bool) (string, error)
CurrentTag returns the latest existing git tag for the given strategy and environment. For SemVer strategies it is the highest SemVer §11 release, or — with includePreRelease — the highest tag including pre-releases (ADR-0064). CalVer strategies ignore includePreRelease and keep git's version:refname order. For single-env strategies, env is ignored; for per-env strategies, env is required. Under semver with versioning.branches, a maintenance branch reports its own line's tag (currentMaintenanceTag) and a version branch the tag of its version (currentVersionBranchTag); without the block no branch detection runs.
func CurrentVersion ¶ added in v0.19.0
func CurrentVersion(runner port.Runner, cfg *config.Config, env string, includePreRelease bool) (string, error)
CurrentVersion returns the bare semantic version of the latest tag (the tag with any prefix / env / build components stripped). For per-env strategies the version is parsed via the effective tag_format; for single-env strategies the tag prefix is stripped. includePreRelease is passed through to CurrentTag unchanged.
func HasResolvablePublishTarget ¶ added in v0.57.0
func IsBranchMismatch ¶ added in v0.76.0
IsBranchMismatch reports whether err is the per-env branch guard refusing to operate an environment from the wrong branch. It is distinct from a failure to read the current branch.
func IsBuildIDRequired ¶ added in v0.69.0
IsBuildIDRequired reports whether err is a tag-format render failure because the template has a {build} token but no build ID was supplied. The cmd layer uses this to map such failures to the configuration exit code without importing the tagfmt package directly.
func IsEnvSelection ¶ added in v0.76.0
IsEnvSelection reports whether err is a missing or unknown --env on a per-env strategy. The cmd layer maps it to the configuration exit code (T359): which environments exist is defined by .heraut.yml, so a name outside it is a configuration problem, not a runtime failure.
func IsMajorNotConfirmed ¶ added in v0.83.0
IsMajorNotConfirmed reports whether err is the refusal of an automatic major bump that versioning.bump.confirm_major asks --allow-major for (ADR-0078). The cmd layer maps it to the configuration exit code: a project rule stopped the run.
func IsNothingToRelease ¶ added in v1.0.1
IsNothingToRelease reports whether err says there is nothing to release (ADR-0082): no commits since the last release, no releasable commits, or no release tag yet.
func IsPromotionGuard ¶ added in v0.8.0
IsPromotionGuard reports whether err is one of the per-env promotion guards (E001/E002/E003 from ADR-0007). The cmd layer uses this to map such failures to exit code 4 without importing the perenv package directly.
func IsUnusableCheckout ¶ added in v1.0.1
IsUnusableCheckout reports whether err, or an error it wraps, is a CheckoutError.
func NewMemoizingRunner ¶ added in v0.57.0
NewMemoizingRunner wraps r so repeated identical Run calls are served from cache.
func NewResolver ¶
func NewResolver(cfg *config.Config, env string, force bool, versionOverride, buildID string, runner port.Runner, opts ...ResolverOption) (versioning.Resolver, error)
NewResolver builds the appropriate versioning.Resolver from config. env is the active environment name (empty for non-per-env strategies). force is the --force flag value. versionOverride is set when --set-version X.Y.Z is passed; when non-empty a StaticResolver is returned for all strategies, bypassing git calls to resolve it (it still runs a tag-collision probe — see guardSetVersion). buildID is set when --set-build-id <id> is passed; requires versionOverride to be set. opts tune resolution without changing the positional signature — see WithAllowMajor.
func PreflightCheck ¶ added in v0.6.0
PreflightCheck verifies git binary availability and git user name/email. Called automatically before heraut release and heraut changelog.
func PromotionGuardID ¶ added in v0.80.0
PromotionGuardID returns the guard identifier ("E001", "E002" or "E003") err wraps, or "" when err is not a promotion guard. Machine-readable output uses it as the error code.
func PublishesReleases ¶ added in v1.0.1
PublishesReleases reports whether cfg asks heraut release to publish for env: a release: block at the root or on the environment. Without one, heraut release tags only.
func ReadGPGSign ¶ added in v0.12.0
ReadGPGSign reads tag.gpgSign from git config and returns true when it is set to "true". Any error (key absent, git not available) is treated as false — non-signing is the safe default. Callers should pass a non-dry-run runner so the config is always read regardless of --dry-run.
func ReleaseHookPoints ¶ added in v0.69.0
func ReleaseHookPoints() []string
ReleaseHookPoints returns every hook point `heraut release` runs, in pipeline order (ADR-0053).
func ResolveEnv ¶ added in v0.34.0
ResolveEnv resolves the --env flag value before any pipeline work. When env is "auto", it reads the current branch (on a detached checkout, the CI job's) and matches it against configured environments' branch fields. All other values (including "") are returned as-is without calling git.
func ResolveFromLatestTag ¶ added in v0.45.0
ResolveFromLatestTag returns a rev-range string of the form "<tag>..HEAD". With cfg it delegates to CurrentTag (strategy-aware); without cfg it falls back to git describe --tags --abbrev=0. Returns ("", true, nil) when no tags exist — the caller should warn and check full history. Returns ("", false, err) on unexpected git failures.
func RuntimeCheck ¶ added in v0.6.0
func RuntimeCheck( ctx context.Context, runner port.Runner, cfg *config.Config, env string, header func(title string), dispatch func(name string, run func() RuntimeCheckItem), )
RuntimeCheck verifies all runtime dependencies, grouped into two sections: Git and Platforms. header is called once per section before its items. dispatch is called once per item with the label shown while the check runs; the run function performs the check and returns the result. ctx is the command's context: Ctrl-C stops a platform's API call.
env selects the active environment for the Platforms section: when non-empty and cfg.Environments[env].Release.Targets is non-empty, it replaces the root release.targets list entirely (same semantics as the release pipeline's effective-targets resolution). An empty env, or an env with no target override, checks the root list.
Check order:
Git: git binary → user.name → user.email → working tree → history
Platforms: one row per effective release.targets entry (resolved against
forges:/CI env/git origin, same as `heraut release`), or an
advisory "publish" row when nothing resolves
func ShallowCloneWarning ¶ added in v1.0.1
ShallowCloneWarning is the warning a read-only command prints in a shallow clone, or "" when the history is complete.
func ValidateBuildID ¶ added in v0.19.0
ValidateBuildID reports whether a --set-build-id value is usable as a tag component. Delegates to tagfmt so cmd does not import the versioning layer directly.
func ValidateSkipHooks ¶ added in v0.69.0
ValidateSkipHooks normalizes a --skip-hook / HERAUT_SKIP_HOOKS list (trims whitespace, drops blank entries, removes duplicates while keeping first-seen order) and checks every entry against allowed, the hook points the invoking command runs. A point that exists but that this command never runs is reported differently from a typo, since the fix is different.
func ValidateVersionOverride ¶ added in v0.32.0
ValidateVersionOverride reports whether a --set-version value is usable as a tag/version override. Delegates to tagfmt so cmd does not import the versioning layer directly.
Types ¶
type CheckoutError ¶ added in v1.0.1
type CheckoutError struct {
// contains filtered or unexported fields
}
CheckoutError reports a checkout heraut cannot release from: a shallow clone, a branch with no commit yet, or a detached HEAD with no branch to push the changelog commit to. Commands map it to the Runtime exit code.
func (*CheckoutError) Error ¶ added in v1.0.1
func (e *CheckoutError) Error() string
type CommitCheckResult ¶ added in v0.43.0
type CommitCheckResult struct {
SHA string // git's abbreviated hash (%h) — length varies with repo size/core.abbrev
Subject string // first line of the message
Err error // nil = valid (or skipped merge/fixup)
}
CommitCheckResult records the outcome of validating one commit in a range.
func CheckCommitRange ¶ added in v0.43.0
func CheckCommitRange(runner port.Runner, cfg *config.Config, revRange string) ([]CommitCheckResult, error)
CheckCommitRange validates every commit in revRange (or the full history reachable from HEAD when revRange is "") against the same grammar and type allow-list VerifyCommit applies to a single message. Every commit is evaluated — an invalid commit does not stop the scan. Merge and fixup commits are skipped via VerifyCommit's existing, unconditional skip — no separate handling needed here.
type CommitSummary ¶ added in v0.59.0
type CommitSummary struct {
Type string
Scope string
Breaking bool
Description string
Tickets []native.TicketMatch
}
CommitSummary is a verified commit's structural breakdown plus any detected commits.tickets references, for `heraut commit verify`'s recap output (T242).
func VerifyCommit ¶ added in v0.40.0
func VerifyCommit(cfg *config.Config, message string) (*CommitSummary, error)
VerifyCommit validates message against the conventional-commit grammar and the configured (or default) type allow-list. Merge and fixup commits are always skipped, unconditionally — nil, nil in that case, since there is no commit to summarize. cfg may be nil (no .heraut.yml present) — the default type list applies and no tickets are configured to match against.
type NotesOpts ¶ added in v0.79.0
type NotesOpts struct {
Tag string
From string
Env string
TemplateFile string
Format string // "markdown" (default) or "text"
}
NotesOpts selects what GenerateNotes renders.
type NotesResult ¶ added in v0.79.0
NotesResult is the rendered text and any run notices to show next to it.
func GenerateNotes ¶ added in v0.79.0
func GenerateNotes(ctx context.Context, runner port.Runner, cfg *config.Config, opts NotesOpts) (NotesResult, error)
GenerateNotes renders the release notes of opts.Tag (heraut notes): the groups and commit lines of the range from the tag's previous release, or opts.From, to the tag. It reads git, and the forge for pull-request details unless enrichment is off; ctx is the command's context, which Ctrl-C cancels.
type PipelineOpts ¶
type PipelineOpts struct {
DryRun bool
VersionOverride string
Env string
Out io.Writer
// Commit and Tag are used by the changelog pipeline only.
Commit bool
Tag bool
// NoPush is used by the changelog pipeline only: when true, the commit and tag
// are created locally but not pushed.
NoPush bool
// SignTags mirrors git config tag.gpgSign — when true the pipeline creates
// signed tags (-s) instead of annotated ones. Set by the caller via ReadGPGSign.
SignTags bool
// HerautVersion is the running heraut binary's version, propagated to the native generator
// so templates can render .Heraut.Version. Empty for dev builds.
HerautVersion string
// ReadRunner performs read-only operations (currently: forge git-origin detection) with a
// real, non-dry-run runner so `--dry-run` never changes what is resolved — only what is
// executed. Mirrors the readRunner already threaded into ResolveEnv/NewResolver/ReadGPGSign
// in internal/cmd. Falls back to the pipeline runner passed to BuildPipeline /
// BuildChangelogPipeline when nil (that runner is a real runner outside dry-run anyway).
ReadRunner port.Runner
// RegenerateChangelog forces the native changelog generator to rebuild + re-enrich the whole
// file instead of incrementally splicing the new section. Native only.
RegenerateChangelog bool
// Logger receives operator-debug diagnostics (nil discards them). See forge ADR-0011.
Logger *slog.Logger
// InteractiveRunner runs commands that may need a real terminal — a GPG pinentry prompt during
// `git commit`/a signed tag (T260) — connecting stdin/stdout/stderr directly instead of
// capturing them (forge v0.19.0's CmdRunner.Interactive). Nil falls back to the pipeline
// runner, which behaves exactly as before this option existed.
InteractiveRunner port.Runner
// NoHooks skips every configured hook for this run (--no-hooks), without touching config
// (ADR-0053).
NoHooks bool
// SkipHooks names individual hook points to skip for this run (--skip-hook /
// HERAUT_SKIP_HOOKS, ADR-0062). Callers validate it with ValidateSkipHooks first.
SkipHooks []string
// PreReleaseLabel is the --pre-release label of a release run; empty for a final release.
PreReleaseLabel string
}
PipelineOpts carries runtime options for building a pipeline.
type PlanStep ¶ added in v0.80.0
ReleasePlan and PlanStep expose the pipeline's dry-run plan to the cmd layer, which may not import internal/pipeline.
type ReleasePlan ¶ added in v0.80.0
ReleasePlan and PlanStep expose the pipeline's dry-run plan to the cmd layer, which may not import internal/pipeline.
type ResolverOption ¶ added in v0.69.0
type ResolverOption func(*resolverOptions)
ResolverOption tunes NewResolver without changing its positional signature.
func WithAllowMajor ¶ added in v0.69.0
func WithAllowMajor(allow bool) ResolverOption
WithAllowMajor lifts versioning.bump.stay_at_v0's hold-back for this resolution (--allow-major).
func WithBranchesOnlyCollisionGuard ¶ added in v0.81.0
func WithBranchesOnlyCollisionGuard() ResolverOption
WithBranchesOnlyCollisionGuard keeps the --set-version tag probe to semver repos that declare versioning.branches (ADR-0065). It is for `version next`, which only prints the tag and is sometimes run where there is no repository to probe; every command that tags probes always.
func WithPreRelease ¶ added in v0.74.0
func WithPreRelease(label string) ResolverOption
WithPreRelease asks the plain semver resolver to mint a <core>-<label>.<N> pre-release (--pre-release). An empty label leaves the final-release path untouched.
func WithoutCollisionGuard ¶ added in v0.76.0
func WithoutCollisionGuard() ResolverOption
WithoutCollisionGuard skips the --set-version tag-collision probe (ADR-0065) for runs that never create the tag, such as re-rendering the changelog of an already-released version.
type RuntimeCheckItem ¶ added in v0.6.0
type RuntimeCheckItem struct {
Name string
Value string // resolved value (e.g. version string, identity, "clean")
Err error
IsWarn bool // advisory only — shown with ! but does not fail the overall check
}
RuntimeCheckItem records the outcome of one runtime check.
type TicketCheckResult ¶ added in v0.59.0
type TicketCheckResult struct {
SHA string
Subject string
Matches []native.TicketMatch
}
TicketCheckResult is one commit's ticket-pattern matches for `heraut commit tickets`.
func CheckTicketsInRange ¶ added in v0.59.0
func CheckTicketsInRange(runner port.Runner, cfg *config.Config, revRange string) ([]TicketCheckResult, error)
CheckTicketsInRange walks every commit in revRange (or the full history reachable from HEAD when revRange is "") and matches each against cfg.Tickets() (commits.tickets) using native.MatchTickets — the exact same matching applied when rendering changelog/ release-notes ticket links, against the same text (subject, then body on its own line when non-empty). A nil cfg or unconfigured commits.tickets yields zero matches per commit, not an error — callers decide whether "nothing configured" is worth failing on.