Documentation
¶
Overview ¶
ENGMODEL-OWNER-UNIT: FU-CLI-ORCHESTRATION
ENGMODEL-OWNER-UNIT: FU-CLI-ORCHESTRATION
ENGMODEL-OWNER-UNIT: FU-CLI-ORCHESTRATION
ENGMODEL-OWNER-UNIT: FU-CLI-ORCHESTRATION
ENGMODEL-OWNER-UNIT: FU-CLI-ORCHESTRATION
Package engws is the multi-repository workspace helper behind cmd/engws. It scans the model checkouts under a workspace root, decides which ones must resolve locally, and writes the root-level engmod.work.yml and go.work.
ENGMODEL-OWNER-UNIT: FU-CLI-ORCHESTRATION
ENGMODEL-OWNER-UNIT: FU-CLI-ORCHESTRATION
Index ¶
- Constants
- Variables
- func CheckAllDrift(plan Plan) string
- func FindRoot(start string) (string, error)
- func GoVersion() (string, error)
- func LoadPins(root string) (map[string]bool, error)
- func Main(ctx context.Context, args []string, stdout, stderr io.Writer, ...) int
- func SavePins(root string, pins map[string]bool) error
- func ServeStaging(ctx context.Context, result StageResult, addr string, ready func(host string)) error
- func StageEnv(result StageResult, host string, current map[string]string) []string
- func ToolGoWork(repoDir string) string
- func WorkFileDrift(plan Plan) string
- type BumpResult
- type CheckOptions
- type CheckResult
- type CheckTarget
- type Checkout
- type Entry
- type Plan
- type Publication
- type Registry
- type Skew
- type StageResult
- type StagedModule
- type SyncResult
Constants ¶
const ( StateNoGit = "nogit" StateDirty = "dirty" StateUntagged = "untagged" StateUnpublished = "unpublished" StatePinned = "pinned" StatePublished = "published" StateUnknown = "unknown" )
Checkout states, in the order changed detection applies them.
const ( // StateFileName holds the workspace pins; it lives at the root only. StateFileName = ".engws.yml" // GoWorkFileName is the Go workspace written next to engmod.work.yml. GoWorkFileName = "go.work" )
const ( // StagingDir is the staging area under the root, owned by engws stage. StagingDir = ".engmod/staging" // VersionFromManifest stages module.version from engmod.yml (default). VersionFromManifest = "manifest" // VersionFromTag additionally requires HEAD at tag v<module.version>. VersionFromTag = "tag" )
const Usage = `` /* 5673-byte string literal not displayed */
Usage is the engws command help.
Variables ¶
var ErrHandWritten = errors.New("not generated by engws")
ErrHandWritten is returned when a work file exists without the engws header.
Functions ¶
func CheckAllDrift ¶
CheckAllDrift is WorkFileDrift for check --all, whose plan marks every checkout local on purpose: it warns only when a changed or pinned checkout is missing from engmod.work.yml, never about the unchanged ones --all adds or about extra replacements. TRLC-LINKS: REQ-EMG-068 ENGMODEL-LINKS: FU-CLI-ORCHESTRATION
func FindRoot ¶
FindRoot returns the nearest directory at or above start that contains engmod.work.yml or .engws.yml, or start itself when none does. The search stops below $HOME: $HOME and its ancestors are never returned, so a stray marker there cannot make sync write $HOME/go.work. A world-writable root is refused; give it explicitly with --root. TRLC-LINKS: REQ-EMG-068 ENGMODEL-LINKS: FU-CLI-ORCHESTRATION, FU-SYSTEM-COMPOSITION
func GoVersion ¶
GoVersion returns the local toolchain as the go.work go directive value (go1.27.3 -> 1.27.3; pre-release suffixes dropped). TRLC-LINKS: REQ-EMG-068
func LoadPins ¶
LoadPins reads the pinned checkout names from root/.engws.yml. TRLC-LINKS: REQ-EMG-068 ENGMODEL-LINKS: FU-CLI-ORCHESTRATION
func Main ¶
Main runs engws with args (without the program name) and returns the exit code. TRLC-LINKS: REQ-EMG-068 ENGMODEL-LINKS: FU-CLI-ORCHESTRATION, FU-SYSTEM-COMPOSITION
func SavePins ¶
SavePins writes root/.engws.yml with the pins sorted. TRLC-LINKS: REQ-EMG-068 ENGMODEL-LINKS: FU-CLI-ORCHESTRATION
func ServeStaging ¶ added in v0.6.0
func ServeStaging(ctx context.Context, result StageResult, addr string, ready func(host string)) error
ServeStaging loads every staged OCI layout into an in-memory read-only registry and serves it on addr (loopback only) until ctx is done. ready is called with the listening host:port before serving. TRLC-LINKS: REQ-EMG-080 ENGMODEL-LINKS: FU-CLI-ORCHESTRATION, REF-CUE-OCI-MODULE-REGISTRY
func StageEnv ¶ added in v0.6.0
func StageEnv(result StageResult, host string, current map[string]string) []string
StageEnv returns the environment to run the gate against the staging area: CUE_REGISTRY routes every staged module to host (merged with the current CUE_REGISTRY, replacing routes for the same prefix; omitted when host is empty), GOPROXY is the file proxy with no fallback, GONOPROXY=none makes private patterns use it, GONOSUMDB names the staged Go modules plus the current GONOSUMDB or GOPRIVATE, and ENGMOD_WORK=off with GOWORK=off make every dependency resolve from staging instead of the checkouts. TRLC-LINKS: REQ-EMG-080 ENGMODEL-LINKS: FU-CLI-ORCHESTRATION, REF-CUE-OCI-MODULE-REGISTRY
func ToolGoWork ¶
ToolGoWork is the GOWORK value for running a repository's own .github/engmod-check: its go.work when the repository deliberately builds the check against a local engine, else "off". The workspace root go.work lists the checkouts, not the tool module, and is never inherited. TRLC-LINKS: REQ-EMG-068 ENGMODEL-LINKS: FU-CLI-ORCHESTRATION
func WorkFileDrift ¶
WorkFileDrift reports how root/engmod.work.yml differs from the plan's local set, so check can warn that sync was not run. TRLC-LINKS: REQ-EMG-068 ENGMODEL-LINKS: FU-CLI-ORCHESTRATION, FU-SYSTEM-COMPOSITION
Types ¶
type BumpResult ¶
type BumpResult struct {
Module string // dependency model module path
From, To string
GoModule string // Go module required, empty when not changed
LockWritten bool
Diagnostics []validate.Diagnostic
}
BumpResult describes what bump changed.
func Bump ¶
func Bump(root, repo, alias, version string) (BumpResult, error)
Bump sets the version of dependency alias in root/<repo>/engmod.yml by editing only that YAML line, updates the go.mod require and go.sum of the Go module of the same repository family (go get with GOWORK=off) when the dependency's checkout has go.mod, and regenerates engmod.lock.yml with the workspace off and the module cache refreshed. Any failure restores engmod.yml, go.mod and go.sum. TRLC-LINKS: REQ-EMG-068 ENGMODEL-LINKS: FU-CLI-ORCHESTRATION, FU-SYSTEM-COMPOSITION
type CheckOptions ¶
type CheckOptions struct {
// InProcess forces the library check even when a repo pins its own.
InProcess bool
// Jobs bounds the concurrent exec checks; 0 means GOMAXPROCS.
Jobs int
// Refresh re-fetches every registry dependency instead of reusing the
// module cache (ENGMOD_MODULE_CACHE=refresh), so a moved tag is seen.
Refresh bool
}
CheckOptions configures RunChecks.
type CheckResult ¶
type CheckResult struct {
Target CheckTarget
Method string // exec: the repo's pinned .github/engmod-check; library: in-process
Errors int
Warnings int
Lines []string // error lines and other failure output
Failed bool
}
CheckResult is the outcome of the model check in one checkout.
func RunChecks ¶
func RunChecks(ctx context.Context, root string, targets []CheckTarget, opts CheckOptions) []CheckResult
RunChecks runs the model check in every target. A repository that ships .github/engmod-check with --workspace-root support is checked with its own pinned engine (go run with GOWORK from ToolGoWork, so the root go.work never captures the check module); otherwise the library in this binary checks it in-process. Exec checks run concurrently; in-process checks run one at a time because they share process state (environment, caches). TRLC-LINKS: REQ-EMG-068 ENGMODEL-LINKS: FU-CLI-ORCHESTRATION, FU-SYSTEM-COMPOSITION
func (CheckResult) Line ¶
func (r CheckResult) Line() string
Line is the one-line summary: ok|FAIL repo (n errors, m warnings). TRLC-LINKS: REQ-EMG-068
type CheckTarget ¶
CheckTarget is a checkout selected for the model check and why.
func SelectCheckTargets ¶
func SelectCheckTargets(plan Plan) []CheckTarget
SelectCheckTargets returns the checkouts affected by the local set: the local checkouts, every checkout that depends on one of them directly or transitively inside the workspace, and the top systems (checkouts no other checkout depends on). The result is sorted by checkout name. TRLC-LINKS: REQ-EMG-068 ENGMODEL-LINKS: FU-CLI-ORCHESTRATION, FU-SYSTEM-COMPOSITION
type Checkout ¶
type Checkout struct {
Name string // directory name under the root
Dir string // absolute directory
Manifest model.ManifestDocument
GoModule string // module path from go.mod, empty without go.mod
// GoRequires maps each module path required in go.mod to its version.
GoRequires map[string]string
}
Checkout is one direct child directory of the root holding an engmod.yml.
func Scan ¶
Scan lists the direct children of root that hold an engmod.yml, sorted by name. Dot directories are skipped. A manifest that cannot be read is an error naming the checkout, since every later decision depends on it. TRLC-LINKS: REQ-EMG-068 ENGMODEL-LINKS: FU-CLI-ORCHESTRATION, FU-SYSTEM-COMPOSITION
func ScanWithWarnings ¶
ScanWithWarnings is Scan that also returns one warning per skipped checkout: a directory name outside [A-Za-z0-9._-] or a module.path that is not a valid CUE module path (host/path@vN). Neither is written into the work files. TRLC-LINKS: REQ-EMG-068 ENGMODEL-LINKS: FU-CLI-ORCHESTRATION
type Entry ¶
type Entry struct {
Checkout
Pinned bool
Reasons []string // why the checkout is changed, in detection order
State string
Local bool // listed as a replacement
Note string
}
Entry is one checkout with its changed-detection result.
type Plan ¶
type Plan struct {
Root string
Entries []Entry
Notes []string
// Warnings name the checkouts Scan skipped as unsafe.
Warnings []string
}
Plan is the workspace decision for every checkout under Root.
func BuildPlan ¶
BuildPlan classifies every checkout under root. A checkout is local when it is pinned, changed, or all is set; registry problems are notes, never changes, so an offline developer is not forced into local mode. TRLC-LINKS: REQ-EMG-068 ENGMODEL-LINKS: FU-CLI-ORCHESTRATION, FU-SYSTEM-COMPOSITION
func (Plan) Skews ¶
Skews lists every dependency pin of a checkout whose module is local at a different version (the replacement overrides every pin of its module), and every go.mod require of a workspace checkout's Go module at another version than that checkout's version tag (go.work uses every Go checkout). TRLC-LINKS: REQ-EMG-068 ENGMODEL-LINKS: FU-CLI-ORCHESTRATION, FU-SYSTEM-COMPOSITION
type Publication ¶
type Publication int
Publication is the registry answer for one module version.
const ( // PublicationUnknown means the registry could not be asked (offline, // unconfigured or failing); it never marks a checkout changed. PublicationUnknown Publication = iota PublicationPublished PublicationMissing )
type Registry ¶
type Registry interface {
// Published reports the publication of modulePath (with @vN) at version
// and, for PublicationUnknown, why.
Published(ctx context.Context, modulePath, version string) (Publication, string)
}
Registry answers whether a module version is published.
func NewCUERegistry ¶
func NewCUERegistry() Registry
NewCUERegistry returns the registry configured by CUE_REGISTRY. An unset CUE_REGISTRY is reported as unknown instead of falling back to CUE's public default registry, so engws never contacts a registry the project did not configure. TRLC-LINKS: REQ-EMG-068 ENGMODEL-LINKS: FU-CLI-ORCHESTRATION, FU-SYSTEM-COMPOSITION
type Skew ¶
type Skew struct {
Consumer, Alias, Module, Pinned, LocalCheckout, LocalVersion string
}
Skew is a consumer pin that a local replacement overrides with another version.
type StageResult ¶ added in v0.6.0
type StageResult struct {
Root string
RegistryDir string
GoProxyDir string
Modules []StagedModule // in dependency order
Warnings []string
// Failures name the checkouts that cannot be staged; when any exist
// nothing is written.
Failures []string
}
StageResult is the outcome of Stage.
func Stage ¶ added in v0.6.0
func Stage(ctx context.Context, root, versionFrom string) (StageResult, error)
Stage publishes every checkout under root, in dependency order, into root/.engmod/staging: the CUE module as cue mod publish would (an OCI image layout per module under registry/<module path>, source kind git zips committed files only, kind self the directory) and, for a checkout with go.mod at its top, the Go module in GOPROXY file layout under goproxy/<module>/@v/<version>.{info,mod,zip} with list. It refuses a checkout cue mod publish would refuse (dirty tree, no source, module path mismatch) and, with versionFrom tag, one whose HEAD lacks tag v<module.version>; then nothing is written. It never writes inside a checkout. TRLC-LINKS: REQ-EMG-080 ENGMODEL-LINKS: FU-CLI-ORCHESTRATION, FU-SYSTEM-COMPOSITION, REF-CUE-OCI-MODULE-REGISTRY
type StagedModule ¶ added in v0.6.0
type StagedModule struct {
Name string // checkout directory name
ModulePath string // CUE module path with major version
Version string
CUEFiles int
LayoutDir string // OCI image layout of the CUE module
GoModule string // staged Go module path, empty without go.mod
Notes []string
}
StagedModule is one checkout published into the staging area.
type SyncResult ¶
type SyncResult struct {
WorkFile string
GoWork string // written go.work, empty when none
GoWorkRemoved bool
}
SyncResult names the files sync wrote or removed.
func Sync ¶
func Sync(plan Plan, goVersion string, force bool) (SyncResult, error)
Sync writes root/engmod.work.yml with every local checkout and root/go.work with every checkout that has go.mod, removing go.work when none do. A non-local checkout is at its published tag, so its code equals the version a consumer pins at that tag; another pinned version is reported by Skews. Listing every Go checkout lets go test and go run work in each of them. It writes nothing inside a checkout. A work file that engws did not generate is kept unless force is set. TRLC-LINKS: REQ-EMG-068 ENGMODEL-LINKS: FU-CLI-ORCHESTRATION, FU-SYSTEM-COMPOSITION