Help us shape the future of Go! Take the 2026 Go Developer Survey

buildscope

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package buildscope is the registry of the project's release components and the engine that computes each one's build closure: the module-local packages and files that compile into its entry-point binary.

It answers two questions that must agree, for two callers that must agree:

  • change detection — which components a set of changed files affects (Affected), so CI builds and validates only what a change touched;
  • scoped validation — which packages a component comprises (ClosurePackages), so `go vet` / `go test` run against just those.

walle (locally) and the changed-scope action (in CI) both import this package, so the answers cannot drift. The closure comes from `go list -deps`, not path globbing, because components share packages under internal/: a path prefix cannot say which binary an internal package compiles into, but the import graph can.

Index

Constants

This section is empty.

Variables

View Source
var Components = []Component{
	{Name: "example", EntryPkg: "./cmd/example"},
	{Name: "walle", EntryPkg: "./cmd/walle"},
}

Components is the ordered set of release components. Order is the canonical order for reports and outputs. To add a component, add its cmd/<name> package and an entry here; walle, the changed-scope action and the build action all pick it up.

walle is a component so that a change to the tooling itself is in CI's scope: its closure covers every internal/ engine, so a PR touching only buildscope or buildrun still runs their vet and tests rather than being scoped to nothing.

Functions

func Affected

func Affected(ctx context.Context, changed []string) (map[string]bool, error)

Affected reports, for every component, whether any changed file (module-relative) is in its closure.

func AffectedIn

func AffectedIn(changed []string, closures map[string][]string) map[string]bool

AffectedIn is Affected with the closures supplied, so the decision is testable without the toolchain. Every component appears in the result; one missing from closures is reported unaffected.

func AffectedNames

func AffectedNames(affected map[string]bool) []string

AffectedNames returns the affected component names in canonical order.

func ClosurePackages

func ClosurePackages(ctx context.Context, names ...string) ([]string, error)

ClosurePackages returns the sorted union of the named components' module-local packages — the argument list for `go vet` / `go test` to validate exactly those components. No names means every component.

func Closures

func Closures(ctx context.Context, names ...string) (map[string]Closure, error)

Closures resolves the closures of the named components (all components when names is empty) concurrently. Each `go list -deps` costs roughly half a second to a second on a real module; they are independent and read-only, so running them in parallel makes Affected cost about one call instead of one per component.

func GitChanged

func GitChanged(ctx context.Context, base string) ([]string, error)

GitChanged returns the module-relative paths changed between the merge base of base and HEAD, and HEAD — what a pull request changed, computed from the checkout rather than the GitHub API (no token, no pagination, no 3000-file API cap). The checkout needs enough history to find the merge base: actions/checkout with fetch-depth: 0.

git reports paths relative to the repository root; they match module-relative paths when the module is the repository root, which is this template's layout.

func ImportPath

func ImportPath(ctx context.Context, c Component) (string, error)

ImportPath returns a component's entry-point import path.

func Names

func Names() []string

Names returns the component names in canonical order — the source for CLI enums and help text, so they cannot go stale.

Types

type Closure

type Closure struct {
	Packages []string // module-local import paths, sorted
	Files    []string // module-relative, forward-slashed paths, sorted; always includes go.mod and go.sum
}

Closure is a component's build closure within this module.

func ClosureOf

func ClosureOf(ctx context.Context, name string) (Closure, error)

ClosureOf resolves one component's closure with a single `go list -deps` call.

No -e: a package that fails to load (a broken import) fails the call rather than silently dropping out of the closure, which would make a broken change look like it touched nothing.

type Component

type Component struct {
	Name      string
	EntryPkg  string
	BuildTags []string
}

Component is a releasable binary and the entry point whose build closure defines it. BuildTags are the tags it ships with; the closure is computed under the same tags so it matches the files that actually compile in.

func Lookup

func Lookup(name string) (Component, bool)

Lookup returns the component with the given name.

Jump to

Keyboard shortcuts

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