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

buildrun

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: 15 Imported by: 0

Documentation

Overview

Package buildrun compiles the project's release components and its Go GitHub Actions.

It is the single build engine behind walle (on a laptop) and the build action (in CI): both import it, so an artifact built in CI is built by the same code, with the same flags, as one built locally.

Reproducibility is load-bearing

Every artifact is a pure function of source, Go toolchain version and the injected metadata — never of the machine or the moment. Two consumers depend on that: a deploy tool that diffs asset hashes (CDK, for one) redeploys only what changed, and `walle check actions` can prove a committed action binary matches its source by rebuilding it on a different host and comparing bytes. Hence the fixed flag set in [goBuild]:

  • CGO_ENABLED=0 — a static binary, no host C toolchain in the output;
  • -trimpath — no absolute host paths;
  • -buildvcs=false — no vcs.revision / vcs.modified stamp, which would differ between a clean and a dirty tree and between commits that did not touch the component;
  • -ldflags "-s -w" — no symbol table or DWARF: roughly a third smaller, stack traces still work;
  • metadata only via -X, and never a timestamp or CI run id.

The package execs `go build` rather than linking the toolchain: there is no library API that compiles and links a binary.

Index

Constants

View Source
const (
	// BinDir receives host builds: bin/<component>, directly runnable.
	BinDir = "bin"
	// ReleaseDir receives cross-compiled release assets: bin/release/<component>-<os>-<arch>.
	ReleaseDir = "bin/release"
	// ActionsSrcDir holds one main package per Go GitHub Action: cmd/github-actions/<name>.
	ActionsSrcDir = "cmd/github-actions"
	// ActionsDir holds the action definitions: .github/actions/<name>/{action.yaml,index.js,dist/}.
	ActionsDir = ".github/actions"
)

Variables

View Source
var ActionPlatforms = []Platform{{"linux", "amd64"}, {"linux", "arm64"}}

ActionPlatforms is what `build actions` cross-compiles each action for. GitHub-hosted Linux runners are amd64 and arm64; add {"darwin", "arm64"} if you run these actions on macOS runners. The shim falls back to building from source on any platform without a binary, so a missing entry costs a compile, not a failure.

Host is the platform walle is running on.

View Source
var ReleasePlatforms = []Platform{{"linux", "amd64"}, {"linux", "arm64"}, {"darwin", "arm64"}}

ReleasePlatforms is what `build --all-platforms` cross-compiles for. Each platform is a full compile of the component's closure — cross-compilation shares no cached output across a GOOS/GOARCH boundary — so list only platforms something actually runs on.

Functions

func ActionBinary

func ActionBinary(name string, p Platform) string

ActionBinary is the committed path of an action's binary for a platform. The shim (.github/actions/_shim/shim.js) resolves the same name.

func Actions

func Actions() ([]string, error)

Actions lists the Go GitHub Actions by convention: every directory under cmd/github-actions is one, named after the directory, with its definition in .github/actions/<name>. Discovery replaces a hand-kept registry, so there is no list to forget to update.

func BuildInto

func BuildInto(ctx context.Context, component string, p Platform, out, metadata string) error

BuildInto builds a component for one platform to an explicit path. The determinism check uses it so it exercises exactly the flags the real build uses.

func Ldflags

func Ldflags(metadata string) string

Ldflags returns the linker flags for an artifact: stripped, with metadata injected into the version package when non-empty.

func Metadata

func Metadata(ctx context.Context) string

Metadata returns the build-metadata string (the semver "+build" suffix) for this invocation, in order of precedence:

  1. BUILD_METADATA, when set — an explicit override, e.g. "release.abc1234";
  2. in GitHub Actions: "pr<N>.<sha7>" for a pull request (the PR head, not the synthetic merge commit), "main.<sha7>" on main, "branch.<sha7>" otherwise;
  3. locally: "local.<sha7>", with ".dirty" for an uncommitted tree, or "local.unknown" outside git.

It is one implementation for walle and the build action. It never contains a timestamp or run id: rebuilding the same commit must produce the same bytes.

func SHA256

func SHA256(path string) (string, error)

SHA256 returns the hex digest of a file.

Types

type Platform

type Platform struct{ OS, Arch string }

Platform is a GOOS/GOARCH pair.

func (Platform) String

func (p Platform) String() string

type Result

type Result struct {
	Component string
	Platform  Platform
	Output    string
}

Result records one built artifact.

func BuildActions

func BuildActions(ctx context.Context, platforms []Platform) ([]Result, error)

BuildActions cross-compiles every action for every platform, concurrently. Action binaries carry no metadata: they are committed, and metadata would make every rebuild a diff.

func BuildAll

func BuildAll(ctx context.Context, component, metadata string, platforms []Platform) ([]Result, error)

BuildAll cross-compiles a component for every platform concurrently into bin/release/<name>-<os>-<arch>. Results come back in platform order regardless of completion order, so reports read the same on every run. The group fails fast: the first error cancels the other builds.

func BuildHost

func BuildHost(ctx context.Context, component, metadata string) (Result, error)

BuildHost builds a component for the host into bin/<name>.

type Stale

type Stale struct {
	Path   string
	Reason string
}

Stale describes a committed action binary that does not match its source.

func StaleActions

func StaleActions(ctx context.Context) (checked int, stale []Stale, err error)

StaleActions rebuilds every committed action binary into a temporary directory and compares bytes. Only binaries present in dist/ are checked, so an action that ships no binaries (source mode) is never stale.

Each rebuild uses the Go toolchain recorded in the committed binary (GOTOOLCHAIN=goX.Y.Z, which the go command downloads once if needed), so a developer on a newer patch release than CI does not produce a false positive.

Jump to

Keyboard shortcuts

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