Documentation
¶
Overview ¶
Package config loads and validates monorel.toml.
monorel.toml is the single source of truth for which packages exist in the repo, where their go.mod and CHANGELOG live, what scope they own in commit messages, and how their tags are prefixed. Everything else (changesets, the planner) refers to packages by the names declared here.
Index ¶
Examples ¶
Constants ¶
const ( ProviderGitHub = "github" ProviderGitea = "gitea" ProviderGitLab = "gitlab" ProviderBitbucket = "bitbucket" )
Provider names recognized by IsKnownProvider. These are the values that `provider.name` in monorel.toml can take. Adding a new provider: append to KnownProviders and wire up a provider implementation under internal/provider/<name>/.
ProviderBitbucket names a constant retained for the in-tree `internal/provider/bitbucket` implementation, which is intentionally NOT in KnownProviders: end-to-end verification against a live Bitbucket Pipelines runner has not been completed (the workspace 2FA enforcement on the maintainer's account blocks the API enable path). The constant and the provider package are kept on disk so a future re-enablement is a one-line change in KnownProviders and the factory dispatch; until then the validator rejects `name = "bitbucket"` with "is not recognized."
const DefaultProvider = ProviderGitHub
DefaultProvider is the value ResolveProvider returns for an empty input. monorel.toml's `provider.name` defaults to "github" when omitted.
Variables ¶
var ErrNoPackages = errors.New("no packages declared")
ErrNoPackages is returned when monorel.toml declares no packages. At least one package is required: monorel has nothing to release otherwise.
var KnownProviders = []string{ ProviderGitea, ProviderGitHub, ProviderGitLab, }
KnownProviders is every provider name recognized in this build, in alphabetical order. The slice is shared and read-only; callers should not mutate it.
Functions ¶
func IsKnownProvider ¶
IsKnownProvider reports whether name is a recognized provider. Empty name is rejected; resolve to the default first if you mean "accept empty as github."
func ResolveProvider ¶
ResolveProvider returns name, or DefaultProvider if name is empty. Callers reading config should pass through ResolveProvider so the empty-string default is applied uniformly.
Types ¶
type Config ¶
type Config struct {
Provider ProviderConfig `toml:"provider"`
Packages map[string]PackageConfig `toml:"packages"`
}
Config is the parsed contents of monorel.toml.
Packages is keyed by the human-friendly package name used as both the changeset frontmatter key and (combined with TagPrefix) the git tag prefix. Names are arbitrary identifiers; convention is to use the package's filesystem path for sub-modules ("transports/zerolog") and the import path for the root module ("github.com/foo/bar").
func Load ¶
Load reads the file at path, parses it as TOML, and validates the result. Returns the parsed config or a wrapped error explaining what went wrong.
Example ¶
ExampleLoad parses a monorel.toml from disk. The schema is validated at load time; unknown fields, missing required keys, and duplicate tag prefixes all return an error here rather than later in the release pipeline.
package main
import (
"fmt"
"os"
"path/filepath"
"monorel.disaresta.com/config"
)
func main() {
dir, _ := os.MkdirTemp("", "monorel-config")
defer os.RemoveAll(dir)
path := filepath.Join(dir, "monorel.toml")
_ = os.WriteFile(path, []byte(`
[provider]
name = "github"
owner = "acme"
repo = "widget"
[packages."github.com/acme/widget"]
tag_prefix = ""
path = "."
changelog = "CHANGELOG.md"
[packages."transports/zerolog"]
tag_prefix = "transports/zerolog"
path = "transports/zerolog"
changelog = "transports/zerolog/CHANGELOG.md"
`), 0o644)
cfg, err := config.Load(path)
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("provider:", cfg.Provider.Name, cfg.Provider.Owner+"/"+cfg.Provider.Repo)
for _, name := range cfg.PackageNames() {
pkg := cfg.Packages[name]
fmt.Printf("- %s → tag %sv1.2.3\n", name, pkg.FullTagPrefix())
}
}
Output: provider: github acme/widget - github.com/acme/widget → tag v1.2.3 - transports/zerolog → tag transports/zerolog/v1.2.3
func (*Config) PackageNames ¶
PackageNames returns every package name in lexicographic order. Stable iteration is convenient for tests, log output, and PR rendering.
type PackageConfig ¶
type PackageConfig struct {
// TagPrefix is prepended (with a "/" separator) to the version
// when forming the git tag. Empty means bare tags ("v1.6.2"); a
// value like "transports/foo" produces "transports/foo/v1.6.2".
//
// Bare tags are required by Go for the main module at the repo
// root; prefixed tags are required for sub-modules so go get can
// resolve them.
TagPrefix string `toml:"tag_prefix"`
// Path is the package directory relative to the repo root. The
// planner uses this to locate go.mod for v2+ major-version updates
// (Go's "/v2" import path quirk). For v1 packages it's purely
// informational.
Path string `toml:"path"`
// Changelog is the path (relative to the repo root) of the
// per-package CHANGELOG.md monorel writes new entries to.
Changelog string `toml:"changelog"`
}
PackageConfig is the per-package settings block in monorel.toml.
func (PackageConfig) FullTagPrefix ¶
func (p PackageConfig) FullTagPrefix() string
FullTagPrefix returns the prefix used to match tags for this package, including the trailing "/" separator. Empty when TagPrefix is empty (bare-tag root module).
func (PackageConfig) TagFor ¶
func (p PackageConfig) TagFor(version string) string
TagFor returns the full git tag for the given version, e.g. "transports/zerolog/v1.6.2" or "v1.6.2".
type ProviderConfig ¶ added in v0.3.0
type ProviderConfig struct {
// Name selects the provider implementation. Recognized values:
// "github" (default when empty). Future: "gitlab", "gitea",
// "bitbucket", "forgejo".
Name string `toml:"name"`
// Owner is the user or org that owns the repo. On GitLab this
// maps to the namespace; on Bitbucket to the workspace.
Owner string `toml:"owner"`
// Repo is the repository name.
Repo string `toml:"repo"`
// Host is the API host for self-hosted installations (e.g.
// "gitlab.example.com"). Empty means use the provider's default
// public host.
Host string `toml:"host"`
}
ProviderConfig identifies the version-control host monorel manages releases on (GitHub, GitLab, Gitea, etc.). The Name field selects the implementation; Owner/Repo (and Host for self-hosted installations) identify the specific repository.