Documentation
¶
Overview ¶
Package branch matches the current branch against versioning.branches and enforces the branch guards: the per-environment branch and the unlisted-branch refusal (ADR-0065).
Index ¶
- Variables
- func CIBranch() (branch string, ok bool)
- func CheckBranch(runner port.Runner, cfg *config.Config, env string, force bool) error
- func CheckReleaseBranch(runner port.Runner, cfg *config.Config, force bool) error
- func CurrentBranch(runner port.Runner) (branch string, ok bool, err error)
- type BranchKind
- type BranchMatch
- type BranchMismatchError
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func CIBranch ¶ added in v1.0.1
CIBranch reads the branch a CI job runs for from the providers' variables. GitHub's ref name and Azure's source ref only count when the ref is a branch, since a tag-triggered run exposes the tag there. ok is false outside CI or on a tag build.
func CheckBranch ¶
CheckBranch enforces the per-environment branch guard: when the active environment declares a branch, the current git branch must match it. This prevents operating on an environment (e.g. releasing prod) from the wrong branch. It is a no-op when env is empty or the environment has no branch set. force bypasses the check entirely. On a detached checkout the branch is the one the CI job runs for (CurrentBranch).
func CheckReleaseBranch ¶
CheckReleaseBranch refuses publishing from an unlisted/unknown branch when cfg.Versioning.Branches is set. No-op when the block is absent or force is true.
func CurrentBranch ¶
CurrentBranch reads the checked-out branch. A detached HEAD (the norm in CI checkouts) falls back to the CI providers' branch variables (CIBranch). ok is false when no source yields a branch; err is set only when git itself fails.
Types ¶
type BranchKind ¶
type BranchKind int
const ( BranchRelease BranchKind = iota // exact name, no range: today's behaviour BranchMaintenance // has a Range BranchUnlisted // no entry matches, or the branch is unknown BranchVersion // the branch name is the version (Version) )
type BranchMatch ¶
type BranchMatch struct {
Branch string // "" when unknown
Kind BranchKind
Range config.BranchRange // set when Kind == BranchMaintenance
Version string // bare N.N.N, set when Kind == BranchVersion
Rule int // index into cfg.Versioning.Branches; -1 when unlisted
}
func MatchBranchRule ¶
MatchBranchRule matches branch against cfg.Versioning.Branches. A glob match whose name ends in N.N.N is a BranchVersion and needs no range. needRange == false skips ErrUnderivableRange (the --set-version path) for names carrying neither: the match is then BranchMaintenance with a zero Range, which callers on that path never read.
type BranchMismatchError ¶
type BranchMismatchError struct {
Env, Want, Current string
}
BranchMismatchError is returned by CheckBranch when the current branch is not the one the environment is linked to.
func (*BranchMismatchError) Error ¶
func (e *BranchMismatchError) Error() string