config

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config defines typed configuration for releasegen and the helpers used to load it from environment variables and CLI flags.

Index

Constants

This section is empty.

Variables

View Source
var ConfigFileNames = []string{".releasegen.yaml", ".releasegen.yml"}

ConfigFileNames lists the file names (in lookup order) that LoadFile will try when discovering a config file at a given root directory. Each entry is a bare file name; LoadFile joins it with the supplied root.

Functions

func ApplyFile added in v1.2.0

func ApplyFile(cfg *Config, fc *FileConfig) error

ApplyFile merges file-level config into cfg using the precedence rule "flags > env > file > defaults": file values are only applied where cfg is still at its zero value, i.e. neither the environment nor a flag has supplied an explicit value.

ApplyFile must be called before any flag overrides are applied, since the flag layer is meant to win unconditionally.

func DefaultBaseRef added in v1.2.0

func DefaultBaseRef() string

DefaultBaseRef returns the effective base ref for the changelog-entry check after taking ambient CI environment into account. Callers should only invoke this when cfg.BaseRef is still empty after flag/env/file resolution; the result is "origin/<GITHUB_BASE_REF>" if running under a GitHub Actions pull_request event, otherwise "origin/main".

func ParseCustomTypes

func ParseCustomTypes(raw string) (map[string]BumpType, error)

ParseCustomTypes parses a newline-separated list of "<heading>:<bump>" pairs into a canonical lower-case heading -> BumpType map.

func ParseExcludeDirs

func ParseExcludeDirs(raw string) []string

ParseExcludeDirs splits a newline- or comma-separated list of directories, trims whitespace, and normalizes each entry to end with "/".

Types

type BumpType

type BumpType uint8

BumpType is the SemVer increment classification for an unreleased section.

Values are ordered from least- to most-significant so callers can use numeric comparison ("if bump > current { current = bump }") to pick the highest-priority bump.

const (
	// BumpNone means no recognized change was detected.
	BumpNone BumpType = iota
	// BumpPatch corresponds to a SemVer patch increment.
	BumpPatch
	// BumpMinor corresponds to a SemVer minor increment.
	BumpMinor
	// BumpMajor corresponds to a SemVer major increment.
	BumpMajor
)

func ParseBumpType

func ParseBumpType(s string) (BumpType, error)

ParseBumpType parses a textual bump name (case-insensitive) into a BumpType.

func (BumpType) String

func (b BumpType) String() string

String returns the lower-case textual name of the bump type.

type Config

type Config struct {
	// Required GitHub Actions context.
	Token     string
	OwnerRepo string // "<owner>/<repo>"
	Actor     string
	Branch    string

	// Optional manual override.
	ManualVersion string
	Reason        string

	// Discovery / classification settings.
	ExcludeDirs []string
	CustomTypes map[string]BumpType // canonical lowercase heading -> bump

	// Operational flags.
	DryRun   bool // do not commit, push, tag, or publish
	Debug    bool // verbose tag/discovery diagnostics
	RepoRoot string

	// SummaryFile, if non-empty, receives a JSON summary of the run.
	SummaryFile string

	// SelfReleaseModule and SelfReleaseRepo together identify the
	// "releasegen releasing itself" case: when the module with this name is
	// released inside SelfReleaseRepo, the resulting version is printed to
	// stdout for downstream workflow steps to consume. SelfReleaseModule is
	// the module's directory path relative to the repo root; an empty value
	// means the root module (releasegen lives at the repository root). The
	// feature is active whenever SelfReleaseRepo is non-empty and matches
	// the repository being released; set SelfReleaseRepo to "" to disable.
	SelfReleaseModule string
	SelfReleaseRepo   string

	// RequireChangelogEntry, when true, makes `releasegen validate` enforce
	// that any module whose non-CHANGELOG files changed (vs BaseRef) also
	// gained new content under its `## [Unreleased]` section. This folds
	// the historical "ensure_changelog" pre-merge guard into releasegen so
	// developers can't merge code without a changelog entry. Default false
	// so the syntactic validation can be adopted independently.
	RequireChangelogEntry bool

	// BaseRef is the git revision the changelog-entry check diffs against.
	// Any revspec go-git can resolve is accepted (branch, tag, remote
	// tracking ref like "origin/main", raw hash). Empty falls back to
	// "origin/$GITHUB_BASE_REF" when running under GitHub Actions PR
	// events, else "origin/main".
	BaseRef string
}

Config is the fully resolved runtime configuration for a single releasegen invocation. All fields are populated from environment variables and/or CLI flags before the runner starts; nothing else in the codebase reads the process environment.

func FromEnv

func FromEnv() (*Config, error)

FromEnv builds a Config from process environment variables. It does not validate; callers should invoke Validate after applying any flag overrides.

func (*Config) Owner

func (c *Config) Owner() string

Owner returns the "owner" portion of OwnerRepo.

func (*Config) Repo

func (c *Config) Repo() string

Repo returns the "repo" portion of OwnerRepo.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks fields needed regardless of which command is running: repo root must be set and custom change types must be well-formed. Commands that need additional context (release vs. validate) should call the path-specific helpers below in addition to this method.

func (*Config) ValidateForRelease added in v1.2.0

func (c *Config) ValidateForRelease() error

ValidateForRelease enforces the additional fields required to perform an actual release (commit/tag/push and GitHub Release publication). Callers should invoke Validate() first so common errors aren't masked.

type FileConfig added in v1.2.0

type FileConfig struct {
	// CustomChangeTypes maps additional changelog headings to a bump level
	// ("major", "minor", or "patch"). Headings are case-insensitive.
	CustomChangeTypes map[string]string `yaml:"custom_change_types"`

	// ExcludeDirs lists directory prefixes to skip during changelog
	// discovery. Trailing slashes are optional.
	ExcludeDirs []string `yaml:"exclude_dirs"`

	// SelfReleaseModule is the module path (relative to the repo root)
	// that should be treated as "releasegen releasing itself" so that the
	// resolved version is printed to stdout. Empty means the root module.
	SelfReleaseModule *string `yaml:"self_release_module"`

	// SelfReleaseRepo is the "owner/repo" string the self-release feature
	// matches against. Empty disables the feature.
	SelfReleaseRepo *string `yaml:"self_release_repo"`

	// Validate carries options specific to the `releasegen validate`
	// subcommand. Kept as a nested block so the command can grow more
	// knobs without polluting the top-level namespace.
	Validate *ValidateFileConfig `yaml:"validate"`
}

FileConfig is the on-disk representation of a `.releasegen.yaml` / `.releasegen.yml` file. Only the fields here are considered "repo-shape" configuration; per-run values (GitHub creds, manual override, etc.) remain environment- and flag-only.

func LoadFile added in v1.2.0

func LoadFile(repoRoot string) (*FileConfig, string, error)

LoadFile looks for one of ConfigFileNames in repoRoot and returns a parsed FileConfig along with the absolute path it loaded from. If no file is present, (nil, "", nil) is returned. Errors are returned for unreadable or malformed files.

type ValidateFileConfig added in v1.2.0

type ValidateFileConfig struct {
	// RequireChangelogEntry, when true, makes `validate` enforce that any
	// module whose non-CHANGELOG files changed (vs BaseRef) also gained
	// new content under its `## [Unreleased]` section.
	RequireChangelogEntry *bool `yaml:"require_changelog_entry"`

	// BaseRef overrides the git revision the changelog-entry check diffs
	// against. Falls back to the env-aware default in DefaultBaseRef when
	// neither this nor the flag/env is set.
	BaseRef *string `yaml:"base_ref"`
}

ValidateFileConfig is the on-disk representation of the `validate:` block. All fields are pointers so we can distinguish "not specified" from "explicitly false / empty string": flags and env vars layer on top, and we must know whether a missing key should defer to those defaults.

Jump to

Keyboard shortcuts

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