Documentation
¶
Overview ¶
Package dagbump finds the dependency DAG across a set of local git clones (Go modules and npm packages), works out which projects need a release when one of them changes, and runs the dependency updates and releases in order.
Index ¶
- Constants
- func Apply(m *Manifest, pf *PlanFile, opts ApplyOptions) error
- func CompactPath(p string) string
- func DefaultManifestPath() string
- func ExpandPath(p string) string
- func FillNotes(pf *PlanFile, opts NotesOptions) error
- func ManifestPathSource() (string, string)
- func NextVersion(v, bump string) (string, error)
- func PlanPath(arg string) string
- func Preflight(p *Project, pull bool) error
- func RemoteID(url string) string
- func RemoteOwner(id string) string
- func TagName(prefix, v string) string
- type ApplyOptions
- type Candidate
- type Clone
- type Commit
- type Context
- type Edge
- type GoModule
- type Graph
- func (g *Graph) Context(u *Unit) (*Context, error)
- func (g *Graph) DependsOn(u *Unit) []string
- func (g *Graph) FetchTags(u *Unit)
- func (g *Graph) Get(name string) (*Unit, error)
- func (g *Graph) LaggingDeps(u *Unit, propagatingOnly bool) []*Edge
- func (g *Graph) NewPlanFile(plan *Plan, seeds []string, changed bool) (*PlanFile, error)
- func (g *Graph) Plan(opts PlanOptions) (*Plan, error)
- func (g *Graph) Project(name string) *Project
- func (g *Graph) Release(u *Unit, r *Runner, opts ReleaseOptions) (*ReleasePlan, error)
- func (g *Graph) SeedsFor(name string) ([]*Unit, error)
- func (g *Graph) Update(u *Unit, r *Runner, opts UpdateOptions) (string, error)
- func (g *Graph) Waves(set map[*Unit]bool) ([][]*Unit, error)
- type HooksConfig
- type Manifest
- type NotesConfig
- type NotesOptions
- type NpmDep
- type NpmPackage
- type PathList
- type Plan
- type PlanFile
- type PlanNode
- type PlanOptions
- type PlanUnit
- type Project
- type ProjectSpec
- type PublishConfig
- type ReleaseOptions
- type ReleasePlan
- type RepoConfig
- type Runner
- type ToolsConfig
- type Unit
- type UnitConfig
- type UpdateOptions
Constants ¶
const DefaultPlanFile = "dagbump.plan"
DefaultPlanFile is where plan --write saves and apply reads.
const RepoConfigFile = ".dagbump.yaml"
RepoConfigFile is the per-repo release config, at the repo root.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
func Apply(m *Manifest, pf *PlanFile, opts ApplyOptions) error
Apply runs the plan file unit by unit in wave order: dependency updates, then the release. It reloads the graph before each unit, so each one sees the tags the earlier ones pushed, and it saves progress to the plan file after each unit, so a rerun picks up where a failure stopped.
func CompactPath ¶
CompactPath replaces the home folder prefix with ~.
func DefaultManifestPath ¶
func DefaultManifestPath() string
DefaultManifestPath is $DAGBUMP_MANIFEST, else ~/.config/dagbump/dagbump.yml.
func ExpandPath ¶
ExpandPath expands a leading ~ and cleans the path.
func FillNotes ¶
func FillNotes(pf *PlanFile, opts NotesOptions) error
FillNotes runs the agent once per release unit that has no notes, wave by wave, up to Jobs at a time within a wave. The agent gets the prompt on stdin and DAGBUMP_CONTEXT pointing at the same JSON. Its reply may start with front matter (bump: / version:), and the rest is the notes.
func ManifestPathSource ¶
ManifestPathSource returns the default manifest path and where it came from: "$DAGBUMP_MANIFEST" or "default".
func NextVersion ¶
NextVersion bumps v by patch, minor or major. A pre-release patch bump drops the suffix (v0.2.11-rc1 -> v0.2.11).
func Preflight ¶
Preflight checks that p can be changed: a clean tree on the default branch. With pull set it fetches and fast-forwards when the clone is behind.
func RemoteID ¶
RemoteID normalizes a git remote URL to host/owner/name in lower case, so ssh and https clones of one repo compare equal.
func RemoteOwner ¶
RemoteOwner returns the owner segment of a RemoteID.
Types ¶
type ApplyOptions ¶
ApplyOptions controls Apply.
type Candidate ¶
type Candidate struct {
Name string
Remote string
Chosen *Clone
Others []*Clone
// InManifest is the existing manifest entry for this remote, if any.
InManifest *ProjectSpec
}
Candidate groups the clones of one remote and names the one picked.
type Clone ¶
type Clone struct {
Dir string
Remote string
Branch string
OnDefault bool
Clean bool
CommitTime int64
TopLevel bool // sits directly under a root, not in a worktree group
}
Clone is one git checkout found under a root.
type Context ¶
type Context struct {
Unit string `json:"unit"`
Path string `json:"path"`
Remote string `json:"remote"`
Version string `json:"version"`
Kind string `json:"kind"`
Versioning string `json:"versioning"`
Commits []Commit `json:"commits"`
Merges []string `json:"merges"`
DiffStat string `json:"diffstat"`
ChangedDirs []string `json:"changed_dirs"`
Modules []string `json:"tagged_modules"`
Npm []string `json:"npm_packages"`
Pending []string `json:"pending_dep_updates"`
Warnings []string `json:"warnings"`
}
Context is what a release-notes writer needs about a unit.
type Edge ¶
type Edge struct {
From, To *Unit
Kind string // go | npm | manual
// Module is the dependency's module path or npm package name.
Module string
// FromDir is the folder of the requiring go.mod or package.json in From's project.
FromDir string
Required string
Latest string
Lagging bool
// Propagates is true when a release of To forces a release of From: the
// requiring module is one From tags, or a public package's runtime dep.
Propagates bool
// LocalReplace is set when the requiring go.mod replaces the dependency
// with a local folder.
LocalReplace string
// ReplaceVersion is set when that replace names a version on its left
// side, so it only applies while the requirement stays at that version.
ReplaceVersion string
}
Edge says unit From depends on unit To.
func (*Edge) ResolvesLocally ¶ added in v0.1.4
ResolvesLocally reports whether a local replace still covers the edge once its requirement moves to Latest. A replace that names a version covers only that version.
type GoModule ¶
type GoModule struct {
Path string // module path
Dir string // folder relative to the project root, "" for the root
// TagPrefix is the tag prefix Go expects for this module: Dir, minus a
// trailing major-version folder (v2, v3...) that the module path also ends in.
TagPrefix string
Requires map[string]string // module path -> required version
// LocalReplaces maps a replaced module path to the local folder it points at.
LocalReplaces map[string]string
// ReplaceVersions holds the version a local replace names on its left
// side (replace M v1 => dir), which is the only version it applies to.
ReplaceVersions map[string]string
// Published is true when the module has at least one tag of its own.
Published bool
}
GoModule is one tracked go.mod in a project.
type Graph ¶
type Graph struct {
Manifest *Manifest
Projects []*Project
Units []*Unit
Edges []*Edge
Deps map[*Unit][]*Edge // edges out of a unit (its dependencies)
Users map[*Unit][]*Edge // edges into a unit (its dependents)
// contains filtered or unexported fields
}
Graph is the loaded DAG. Its nodes are units.
func BuildGraph ¶
BuildGraph loads every non-skipped project in the manifest and derives the edges.
func (*Graph) FetchTags ¶
FetchTags fetches tags for u's dependencies, so lag is measured against releases made from other clones or by CI.
func (*Graph) LaggingDeps ¶
LaggingDeps returns the edges out of u whose required version is behind the dependency's latest tag.
func (*Graph) NewPlanFile ¶
NewPlanFile builds a plan file from a computed plan.
func (*Graph) Plan ¶
func (g *Graph) Plan(opts PlanOptions) (*Plan, error)
Plan works out which units need a release because of the seeds: the seeds plus everything downstream of them, in dependency order. It reads live state, so running it again mid-cascade shows what is left.
func (*Graph) Release ¶
func (g *Graph) Release(u *Unit, r *Runner, opts ReleaseOptions) (*ReleasePlan, error)
Release tags u at the next version and publishes it. With a .dagbump.yaml it runs the steps itself; without one it drives the repo's make targets (bump-root / bump-siblings / tag) when they exist.
func (*Graph) SeedsFor ¶
SeedsFor resolves a name to units: a unit name gives that unit, a project name gives all of the project's units.
type HooksConfig ¶
type HooksConfig struct {
PreTag []string `yaml:"pre_tag,omitempty"`
PostTag []string `yaml:"post_tag,omitempty"`
PostRelease []string `yaml:"post_release,omitempty"`
}
HooksConfig are shell commands run in the repo root with V and NOTES set.
type Manifest ¶
type Manifest struct {
// Owners limits discovery to remotes owned by these GitHub users/orgs.
Owners []string `yaml:"owners,omitempty"`
// Roots are the folders that discover scans (each child, and each
// grandchild, that is a git clone).
Roots []string `yaml:"roots,omitempty"`
// IgnoreCommits are regexes on commit subjects that do not count as
// unreleased changes (for example the restore commit some repos make
// right after tagging).
IgnoreCommits []string `yaml:"ignore_commits,omitempty"`
// Tools sets the default per-ecosystem tool and whether to enforce it.
Tools ToolsConfig `yaml:"tools,omitempty"`
Projects []*ProjectSpec `yaml:"projects"`
// contains filtered or unexported fields
}
Manifest lists the projects in the DAG. Edges are not stored here: they are read from each project's go.mod and package.json files every run, plus any manual DependsOn entries.
func LoadManifest ¶
LoadManifest reads the manifest at path. A missing file gives an empty manifest with Exists() false.
func (*Manifest) Find ¶
func (m *Manifest) Find(name string) *ProjectSpec
Find returns the spec whose name matches, or whose path resolves to the same folder as name.
type NotesConfig ¶
type NotesConfig struct {
Changelog string `yaml:"changelog,omitempty"`
File string `yaml:"file,omitempty"`
}
NotesConfig says where release notes land in the repo. Empty fields are auto: CHANGELOG.md when the repo has one, docs/releases/{V}.md when the repo has a docs/releases folder. "none" turns a target off.
type NotesOptions ¶
type NotesOptions struct {
Agent string // shell command; reads the prompt on stdin, prints front matter + notes
Jobs int
Force bool // redo units that already have notes
Out io.Writer
}
NotesOptions controls FillNotes.
type NpmDep ¶
type NpmDep struct {
Spec string
Section string // dependencies | devDependencies | peerDependencies
Locked string // version from package-lock.json, if any
}
NpmDep is one entry from package.json's dependency sections.
type NpmPackage ¶
type NpmPackage struct {
Dir string // "" for the root
Name string
Version string
Private bool
Deps map[string]NpmDep
// Manager is the tool dagbump runs for this package: npm, pnpm or yarn.
Manager string
// ManagerFrom says where Manager came from: .dagbump.yaml,
// packageManager, lockfile, manifest or default.
ManagerFrom string
// LockDir is the absolute folder of the nearest lockfile ("" when there is none).
LockDir string
// PolicyErr is set when the manifest enforces another tool.
PolicyErr string
}
NpmPackage is one tracked package.json.
type PathList ¶
type PathList []string
PathList is a list of folder globs where an empty list ([]) means "none" and a missing one means "the default".
type Plan ¶
type Plan struct {
Nodes []*PlanNode // in wave order
}
Plan is the ordered set of releases.
type PlanFile ¶
type PlanFile struct {
Format int `yaml:"dagbump_plan"`
Created string `yaml:"created"`
Manifest string `yaml:"manifest"`
Seeds []string `yaml:"seeds,omitempty"`
Changed bool `yaml:"changed,omitempty"`
Units []*PlanUnit `yaml:"units"`
// contains filtered or unexported fields
}
PlanFile is the hand-off between dagbump plan, whoever writes the notes, and dagbump apply.
func LoadPlanFile ¶
LoadPlanFile reads a plan file.
type PlanNode ¶
type PlanNode struct {
Unit *Unit
Wave int
Seed bool
// Action is release (tag a new version), update (dependency bump only,
// for apps) or none.
Action string
Reasons []string
// Updates are the dependency edges to move to their latest versions.
Updates []*Edge
}
PlanNode is one unit in a plan.
type PlanOptions ¶
type PlanOptions struct {
Seeds []*Unit
Changed bool // add every lib with unreleased commits or lagging deps as a seed
Exclude map[string]bool
}
PlanOptions picks the seeds of a plan.
type PlanUnit ¶
type PlanUnit struct {
Unit string `yaml:"unit"`
Wave int `yaml:"wave"`
Action string `yaml:"action"`
Path string `yaml:"path"`
Head string `yaml:"head"`
Current string `yaml:"current,omitempty"`
Versioning string `yaml:"versioning"`
HasConfig bool `yaml:"has_config"`
WaitsFor []string `yaml:"waits_for,omitempty"`
Reasons []string `yaml:"reasons,omitempty"`
Updates []string `yaml:"updates,omitempty"`
Commits []string `yaml:"commits,omitempty"`
Changed []string `yaml:"changed_dirs,omitempty"`
DiffStat string `yaml:"diffstat,omitempty"`
Warnings []string `yaml:"warnings,omitempty"`
Bump string `yaml:"bump"`
Version string `yaml:"version"`
Only []string `yaml:"only,omitempty"`
Skip bool `yaml:"skip,omitempty"`
Notes string `yaml:"notes"`
Status string `yaml:"status"`
Released string `yaml:"released,omitempty"`
Tags []string `yaml:"tags,omitempty"`
Error string `yaml:"error,omitempty"`
}
PlanUnit is one unit's entry. dagbump plan fills the context fields; the agent or person fills bump/version, notes, and optionally only and skip; dagbump apply fills status, released, tags and error.
type Project ¶
type Project struct {
Spec *ProjectSpec
Name string
Dir string
Remote string
Branch string
DefaultBranch string
Dirty bool
Modules []*GoModule
Npm []*NpmPackage
// Config is the repo's .dagbump.yaml, or one inferred from its tags.
Config *RepoConfig
// HasConfig is true when Config came from a .dagbump.yaml.
HasConfig bool
Units []*Unit
Warnings []string
LoadErr error
// contains filtered or unexported fields
}
Project is a manifest entry loaded from its clone.
func LoadProject ¶
func LoadProject(spec *ProjectSpec, ignore []*regexp.Regexp, tools ToolsConfig) *Project
LoadProject reads a project's clone: git state, tags, go.mod and package.json files, and its .dagbump.yaml. Errors are kept on the project so one broken clone does not stop the rest of the graph from loading.
func (*Project) LatestFor ¶
LatestFor returns the highest stable version tagged with prefix, or the highest pre-release when no stable one exists.
func (*Project) ModuleChanged ¶
ModuleChanged reports whether m has commits since its own latest tag, not counting folders of other modules nested inside it. A module that was never tagged counts as changed.
func (*Project) RootModule ¶
type ProjectSpec ¶
type ProjectSpec struct {
Name string `yaml:"name"`
Path string `yaml:"path"`
Remote string `yaml:"remote,omitempty"`
// Kind is "lib" (tagged releases) or "app" (dependency updates only).
// Empty means auto: lib when the repo has a semver tag.
Kind string `yaml:"kind,omitempty"`
DependsOn []string `yaml:"depends_on,omitempty"`
Skip bool `yaml:"skip,omitempty"`
}
ProjectSpec is one project's entry in the manifest. Only Name and Path are required. How the repo releases lives in its own .dagbump.yaml.
func NewSpec ¶
func NewSpec(dir, name string) (*ProjectSpec, error)
NewSpec builds a manifest entry for a single clone.
type PublishConfig ¶
type PublishConfig struct {
// Npm is direct (dagbump runs npm publish), ci (a workflow publishes on
// the tag; dependents wait for npm to show it) or none.
Npm string `yaml:"npm,omitempty"`
GitHubRelease *bool `yaml:"github_release,omitempty"`
}
PublishConfig says how releases reach their registries.
type ReleaseOptions ¶
type ReleaseOptions struct {
Bump string
Version string
Notes string // path to a release-notes file
// Only tags just these modules (folders or module paths) and the
// unit's modules that require them, whatever the unit's versioning.
Only []string
NoPush bool
AllowLagging bool
Force bool
}
ReleaseOptions controls Release.
type ReleasePlan ¶
type ReleasePlan struct {
Version string
Tags []string // primary first when present
Modules []*GoModule
Npm []*NpmPackage
}
ReleasePlan is what Release will tag.
type RepoConfig ¶
type RepoConfig struct {
UnitConfig `yaml:",inline"`
// Kind is lib or app for the whole repo; empty means auto.
Kind string `yaml:"kind,omitempty"`
// Tools names this repo's tools, overriding detection and the manifest.
Tools ToolsConfig `yaml:"tools,omitempty"`
IgnoreCommits []string `yaml:"ignore_commits,omitempty"`
Units []*UnitConfig `yaml:"units,omitempty"`
}
RepoConfig describes how one repo releases. A repo with one version line puts the unit fields at the top level; a repo with several lists them under units. The first unit is the main unit: it carries the root tag and takes every module and package no other unit claims.
func InferConfig ¶
func InferConfig(p *Project, owners []string) (*RepoConfig, []string)
InferConfig proposes a .dagbump.yaml from the repo's tags and files. The main unit holds the modules tagged at the latest release. A module tagged on its own older line gets its own unit. Each public package.json is checked on npm: one not published under an owner is left out, and one whose version differs from the repo's gets its own unit.
func LoadRepoConfig ¶
func LoadRepoConfig(dir string) (*RepoConfig, error)
LoadRepoConfig reads dir/.dagbump.yaml. It returns nil, nil when there is none.
func (*RepoConfig) AllUnits ¶
func (c *RepoConfig) AllUnits() []*UnitConfig
AllUnits returns the units, the top-level one when units is empty.
func (*RepoConfig) Marshal ¶
func (c *RepoConfig) Marshal() ([]byte, error)
Marshal renders the config as YAML.
type Runner ¶
type Runner struct {
DryRun bool
Out io.Writer
Env []string
// Base is the project folder; steps in a sub-folder print it as a prefix.
Base string
}
Runner executes the mutating steps of update and release. In dry-run mode it only prints them.
type ToolsConfig ¶
type ToolsConfig struct {
Npm string `yaml:"npm,omitempty"` // npm | pnpm | yarn
Enforce bool `yaml:"enforce,omitempty"`
}
ToolsConfig picks the tool per ecosystem. In the manifest it is the default for repos that declare nothing; with Enforce, dagbump refuses to run any other tool in a repo whose .dagbump.yaml does not name its own. In a .dagbump.yaml it is that repo's choice, and Enforce is ignored.
type Unit ¶
type Unit struct {
Project *Project
Config *UnitConfig
// Name is the project name for the main unit, project/unit otherwise.
Name string
Main bool
Modules []*GoModule // tagged with the unit
Follow []*GoModule // untagged; their pins move with the unit
Npm []*NpmPackage // public ones are versioned with the unit; private ones only consume
// Version is the latest release of the unit ("" when there is none).
Version string
Unreleased []Commit
}
Unit is one version line inside a project.
func (*Unit) NpmLatest ¶
func (u *Unit) NpmLatest(n *NpmPackage) string
NpmLatest is the version consumers of a package should depend on.
func (*Unit) Pathspec ¶
Pathspec returns git pathspecs for the unit's files: its folders, minus folders nested inside them that belong to another unit.
func (*Unit) PrimaryPrefix ¶
PrimaryPrefix is the tag prefix of the unit's release marker tag: "" for the main unit, else its first module's prefix or first package folder.
func (*Unit) PublicNpm ¶
func (u *Unit) PublicNpm() []*NpmPackage
PublicNpm returns the unit's packages that get its version.
type UnitConfig ¶
type UnitConfig struct {
Name string `yaml:"name,omitempty"`
// Versioning is lockstep (every module tagged at every release) or
// changed (one version counter, only changed modules and their in-unit
// dependents tagged).
Versioning string `yaml:"versioning,omitempty"`
// Modules are the go.mod folders tagged with the unit ("." is the root).
// Globs: * matches one path segment, ** any number. Default: every
// module that has a tag of its own.
Modules PathList `yaml:"modules,omitempty"`
// Follow are untagged go.mod folders (examples, docs sites) whose pins
// on the unit's modules move with each release. Default for the main
// unit: every module nobody else claims.
Follow []string `yaml:"follow,omitempty"`
// PinFollowers says which pins a follower moves at a release: root
// (default; only its require of the root module), all (every module
// being tagged) or none. Requires at the v0.0.0 placeholder never move.
PinFollowers string `yaml:"pin_followers,omitempty"`
// Npm are package.json folders whose version is the unit's version.
// Default for the main unit: every non-private package.json; [] for none.
Npm PathList `yaml:"npm,omitempty"`
// VersionFiles hold the bare version string. Default: VERSION if tracked.
VersionFiles []string `yaml:"version_files,omitempty"`
// StripReplaces drops in-repo replace directives from the tagged
// modules in the tagged commit, and restores them in the next commit,
// so `go install pkg@V` works.
StripReplaces bool `yaml:"strip_replaces,omitempty"`
Publish PublishConfig `yaml:"publish,omitempty"`
Notes NotesConfig `yaml:"notes,omitempty"`
Hooks HooksConfig `yaml:"hooks,omitempty"`
// Check runs after a dependency update instead of `go build ./...`.
Check string `yaml:"check,omitempty"`
}
UnitConfig is one version line: the modules and packages tagged together.