Dagger
Search

go

Provides common pipeline stages that any Go project can consume.

Installation

dagger install github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4

Entrypoint

Return Type
Go !
Arguments
NameTypeDefault ValueDescription
sourceDirectory -Project source directory. Ignore patterns (e.g. .git, dist) belong in the consuming project's root dagger.json customizations, not here.
goModDirectory -Go module files (go.mod and go.sum only). Synced separately from source so that the go mod download layer is cached independently of source code changes.
versionString -Go version for base images. Defaults to the version pinned in this module.
lintVersionString -golangci-lint version for the lint base image. Defaults to the version pinned in this module.
moduleCacheCacheVolume -Cache volume for Go module downloads (GOMODCACHE). Defaults to a namespaced volume named "<cacheNamespace>:modules".
buildCacheCacheVolume -Cache volume for Go build artifacts (GOCACHE). Defaults to a namespaced volume named "<cacheNamespace>:build".
baseContainer -Custom base container with Go installed. When provided, the default golang:<version> image is not used.
aptPackages[String ! ] -Additional Debian/Ubuntu packages to install in the default base container. Installed via apt-get before the Go module cache layer so subsequent operations see them on PATH. Ignored when a custom base is provided; in that case the caller owns the container. Applies to the build/test base only. The lint base (see golangci-lint container) uses a separate image and does not consume this parameter. The name leaks the apt-get install path: an Alpine custom base would silently ignore this parameter.
ldflags[String ! ] -Arguments passed to go build -ldflags.
values[String ! ] -String value definitions of the form importpath.name=value, added to -ldflags as -X entries.
cgoBoolean -Enable CGO.
raceBoolean -Enable the race detector. Implies cgo=true.
injectGitHeadBoolean -Inject a synthetic .git/HEAD into the build environment so bare go build / VCS stamping can locate a repository root. When false, source is mounted clean and Build uses -buildvcs=false.
cacheNamespaceString -Namespace prefix for cache volume names. Defaults to this module's canonical path. Override when consuming this module from another project to avoid cache volume collisions between projects.
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
func (m *MyModule) Example() *dagger.Go  {
	return dag.
			Go()
}
@function
def example() -> dagger.Go:
	return (
		dag.go()
	)
@func()
example(): Go {
	return dag
		.go()
}

Types

Go 🔗

Go provides reusable Go CI functions for testing, linting, and formatting. Create instances with [New].

version() 🔗

Go version used for base images.

Return Type
String !
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 version
func (m *MyModule) Example(ctx context.Context) string  {
	return dag.
			Go().
			Version(ctx)
}
@function
async def example() -> str:
	return await (
		dag.go()
		.version()
	)
@func()
async example(): Promise<string> {
	return dag
		.go()
		.version()
}

lintVersion() 🔗

LintVersion is the golangci-lint version used for the lint base image.

Return Type
String !
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 lint-version
func (m *MyModule) Example(ctx context.Context) string  {
	return dag.
			Go().
			LintVersion(ctx)
}
@function
async def example() -> str:
	return await (
		dag.go()
		.lint_version()
	)
@func()
async example(): Promise<string> {
	return dag
		.go()
		.lintVersion()
}

source() 🔗

Project source directory.

Return Type
Directory !
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 source
func (m *MyModule) Example() *dagger.Directory  {
	return dag.
			Go().
			Source()
}
@function
def example() -> dagger.Directory:
	return (
		dag.go()
		.source()
	)
@func()
example(): Directory {
	return dag
		.go()
		.source()
}

moduleCache() 🔗

Cache volume for Go module downloads (GOMODCACHE).

Return Type
CacheVolume !
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 module-cache
func (m *MyModule) Example() *dagger.CacheVolume  {
	return dag.
			Go().
			ModuleCache()
}
@function
def example() -> dagger.CacheVolume:
	return (
		dag.go()
		.module_cache()
	)
@func()
example(): CacheVolume {
	return dag
		.go()
		.moduleCache()
}

buildCache() 🔗

Cache volume for Go build artifacts (GOCACHE).

Return Type
CacheVolume !
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 build-cache
func (m *MyModule) Example() *dagger.CacheVolume  {
	return dag.
			Go().
			BuildCache()
}
@function
def example() -> dagger.CacheVolume:
	return (
		dag.go()
		.build_cache()
	)
@func()
example(): CacheVolume {
	return dag
		.go()
		.buildCache()
}

base() 🔗

Base container with Go installed and caches mounted. When nil in the constructor, a default container is built from the official golang: image.

Return Type
Container !
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 base
func (m *MyModule) Example() *dagger.Container  {
	return dag.
			Go().
			Base()
}
@function
def example() -> dagger.Container:
	return (
		dag.go()
		.base()
	)
@func()
example(): Container {
	return dag
		.go()
		.base()
}

ldflags() 🔗

Arguments passed to go build -ldflags.

Return Type
[String ! ] !
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 ldflags
func (m *MyModule) Example(ctx context.Context) []string  {
	return dag.
			Go().
			Ldflags(ctx)
}
@function
async def example() -> List[str]:
	return await (
		dag.go()
		.ldflags()
	)
@func()
async example(): Promise<string[]> {
	return dag
		.go()
		.ldflags()
}

values() 🔗

String value definitions of the form importpath.name=value, added to -ldflags as -X entries.

Return Type
[String ! ] !
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 values
func (m *MyModule) Example(ctx context.Context) []string  {
	return dag.
			Go().
			Values(ctx)
}
@function
async def example() -> List[str]:
	return await (
		dag.go()
		.values()
	)
@func()
async example(): Promise<string[]> {
	return dag
		.go()
		.values()
}

cgo() 🔗

Enable CGO.

Return Type
Boolean !
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 cgo
func (m *MyModule) Example(ctx context.Context) bool  {
	return dag.
			Go().
			Cgo(ctx)
}
@function
async def example() -> bool:
	return await (
		dag.go()
		.cgo()
	)
@func()
async example(): Promise<boolean> {
	return dag
		.go()
		.cgo()
}

race() 🔗

Enable the race detector. Implies [Go.Cgo].

Return Type
Boolean !
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 race
func (m *MyModule) Example(ctx context.Context) bool  {
	return dag.
			Go().
			Race(ctx)
}
@function
async def example() -> bool:
	return await (
		dag.go()
		.race()
	)
@func()
async example(): Promise<boolean> {
	return dag
		.go()
		.race()
}

injectGitHead() 🔗

InjectGitHead causes [Go.Env] to write a synthetic .git/HEAD file so that bare go build and VCS stamping can locate a repository root. When false, source is mounted without any .git state and [Go.Build] relies on -buildvcs=false. Prefer [Go.EnsureGitInit] or [Go.EnsureGitRepo] for tools that need a real repository.

Return Type
Boolean !
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 inject-git-head
func (m *MyModule) Example(ctx context.Context) bool  {
	return dag.
			Go().
			InjectGitHead(ctx)
}
@function
async def example() -> bool:
	return await (
		dag.go()
		.inject_git_head()
	)
@func()
async example(): Promise<boolean> {
	return dag
		.go()
		.injectGitHead()
}

benchmarkSummary() 🔗

BenchmarkSummary measures the wall-clock time of key pipeline stages and returns a human-readable table. When parallel is true, stages run concurrently to measure the real-world wall-clock time of the full pipeline; the total row then shows overall elapsed time rather than the sum of individual stages.

Return Type
String !
Arguments
NameTypeDefault ValueDescription
parallelBoolean !falseRun stages concurrently to measure full-pipeline wall-clock time.
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 benchmark-summary --parallel boolean
func (m *MyModule) Example(ctx context.Context, parallel bool) string  {
	return dag.
			Go().
			BenchmarkSummary(ctx, parallel)
}
@function
async def example(parallel: bool) -> str:
	return await (
		dag.go()
		.benchmark_summary(parallel)
	)
@func()
async example(parallel: boolean): Promise<string> {
	return dag
		.go()
		.benchmarkSummary(parallel)
}

binary() 🔗

Binary compiles a single main package and returns the binary file.

Return Type
File !
Arguments
NameTypeDefault ValueDescription
pkgString !-Package to build.
noSymbolsBoolean -Disable symbol table.
noDwarfBoolean -Disable DWARF generation.
platformScalar -Target build platform.
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 binary --pkg string
func (m *MyModule) Example(pkg string) *dagger.File  {
	return dag.
			Go().
			Binary(pkg)
}
@function
def example(pkg: str) -> dagger.File:
	return (
		dag.go()
		.binary(pkg)
	)
@func()
example(pkg: string): File {
	return dag
		.go()
		.binary(pkg)
}

build() 🔗

Build compiles the given main packages and returns the output directory.

Return Type
Directory !
Arguments
NameTypeDefault ValueDescription
pkgs[String ! ] ["./..."]Packages to build.
noSymbolsBoolean -Disable symbol table.
noDwarfBoolean -Disable DWARF generation.
platformScalar -Target build platform.
outDirString "./bin/"Output directory path inside the container.
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 build
func (m *MyModule) Example() *dagger.Directory  {
	return dag.
			Go().
			Build()
}
@function
def example() -> dagger.Directory:
	return (
		dag.go()
		.build()
	)
@func()
example(): Directory {
	return dag
		.go()
		.build()
}

cacheBust() 🔗

CacheBust returns a container with a unique cache-busting environment variable that forces Dagger to re-evaluate the pipeline instead of returning cached results. Apply it to a stage’s base before its work so the work re-runs each benchmark.

Return Type
Container !
Arguments
NameTypeDefault ValueDescription
ctrContainer !-Container to bust the cache for.
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 cache-bust --ctr IMAGE:TAG
func (m *MyModule) Example(ctr *dagger.Container) *dagger.Container  {
	return dag.
			Go().
			CacheBust(ctr)
}
@function
def example(ctr: dagger.Container) -> dagger.Container:
	return (
		dag.go()
		.cache_bust(ctr)
	)
@func()
example(ctr: Container): Container {
	return dag
		.go()
		.cacheBust(ctr)
}

checkTidy() 🔗

CheckTidy verifies that go.mod and go.sum are tidy across all discovered Go modules by running go mod tidy per module and checking for differences.

Return Type
Void !
Arguments
NameTypeDefault ValueDescription
include[String ! ] -Include only modules whose directory matches one of these globs.
exclude[String ! ] -Exclude modules whose directory matches any of these globs.
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 check-tidy
func (m *MyModule) Example(ctx context.Context)   {
	return dag.
			Go().
			CheckTidy(ctx)
}
@function
async def example() -> None:
	return await (
		dag.go()
		.check_tidy()
	)
@func()
async example(): Promise<void> {
	return dag
		.go()
		.checkTidy()
}

download() 🔗

Download runs go mod download using only go.mod and go.sum, warming the module cache for subsequent operations.

Return Type
Go !
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 download
func (m *MyModule) Example() *dagger.Go  {
	return dag.
			Go().
			Download()
}
@function
def example() -> dagger.Go:
	return (
		dag.go()
		.download()
	)
@func()
example(): Go {
	return dag
		.go()
		.download()
}

ensureGitInit() 🔗

EnsureGitInit ensures the container has a minimal .git directory at its working directory. This is sufficient for tools that only need to locate the repository root but do not inspect commit history or the index. Prefer [Go.EnsureGitRepo] when the tool requires committed files.

Return Type
Container !
Arguments
NameTypeDefault ValueDescription
ctrContainer !-Container to initialize.
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 ensure-git-init --ctr IMAGE:TAG
func (m *MyModule) Example(ctr *dagger.Container) *dagger.Container  {
	return dag.
			Go().
			EnsureGitInit(ctr)
}
@function
def example(ctr: dagger.Container) -> dagger.Container:
	return (
		dag.go()
		.ensure_git_init(ctr)
	)
@func()
example(ctr: Container): Container {
	return dag
		.go()
		.ensureGitInit(ctr)
}

ensureGitRepo() 🔗

EnsureGitRepo ensures the container has a valid git repository at its working directory with all files staged and committed. When running from a git worktree, the .git file references a host path that doesn’t exist in the container. In that case, a full git repository is initialized so that tools like GoReleaser that depend on committed files, dirty-tree detection, and version derivation continue to work.

Return Type
Container !
Arguments
NameTypeDefault ValueDescription
ctrContainer !-Container to initialize.
remoteUrlString -Remote URL to add as origin. When empty, no remote is configured.
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 ensure-git-repo --ctr IMAGE:TAG
func (m *MyModule) Example(ctr *dagger.Container) *dagger.Container  {
	return dag.
			Go().
			EnsureGitRepo(ctr)
}
@function
def example(ctr: dagger.Container) -> dagger.Container:
	return (
		dag.go()
		.ensure_git_repo(ctr)
	)
@func()
example(ctr: Container): Container {
	return dag
		.go()
		.ensureGitRepo(ctr)
}

env() 🔗

Env returns a Go build environment container with CGO configured, platform env vars set, and source mounted. This is the primary entry point for running Go commands against the project source.

VCS stamping is disabled by mounting source without any .git state. Callers that need a real repository (e.g. goreleaser) must initialize one themselves via [Go.EnsureGitInit] or [Go.EnsureGitRepo], or set [Go.InjectGitHead] for a synthetic .git/HEAD.

Return Type
Container !
Arguments
NameTypeDefault ValueDescription
platformScalar -Target platform (e.g. "linux/amd64"). When empty, uses the host platform.
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 env
func (m *MyModule) Example() *dagger.Container  {
	return dag.
			Go().
			Env()
}
@function
def example() -> dagger.Container:
	return (
		dag.go()
		.env()
	)
@func()
example(): Container {
	return dag
		.go()
		.env()
}

formatGo() 🔗

FormatGo runs golangci-lint –fix across all discovered Go modules and returns the merged changeset of Go source file changes.

Return Type
Changeset !
Arguments
NameTypeDefault ValueDescription
include[String ! ] -Include only modules whose directory matches one of these globs.
exclude[String ! ] -Exclude modules whose directory matches any of these globs.
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 format-go
func (m *MyModule) Example() *dagger.Changeset  {
	return dag.
			Go().
			FormatGo()
}
@function
def example() -> dagger.Changeset:
	return (
		dag.go()
		.format_go()
	)
@func()
example(): Changeset {
	return dag
		.go()
		.formatGo()
}

formatGoModule() 🔗

FormatGoModule runs golangci-lint –fix on a single module directory and returns the changeset.

Return Type
Changeset !
Arguments
NameTypeDefault ValueDescription
modString !-Module directory relative to the source root.
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 format-go-module --mod string
func (m *MyModule) Example(mod string) *dagger.Changeset  {
	return dag.
			Go().
			FormatGoModule(mod)
}
@function
def example(mod: str) -> dagger.Changeset:
	return (
		dag.go()
		.format_go_module(mod)
	)
@func()
example(mod: string): Changeset {
	return dag
		.go()
		.formatGoModule(mod)
}

generate() 🔗

Generate runs go generate and returns the changeset of generated files against the original source.

Return Type
Changeset !
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 generate
func (m *MyModule) Example() *dagger.Changeset  {
	return dag.
			Go().
			Generate()
}
@function
def example() -> dagger.Changeset:
	return (
		dag.go()
		.generate()
	)
@func()
example(): Changeset {
	return dag
		.go()
		.generate()
}

lint() 🔗

Lint runs golangci-lint on all discovered Go modules. Modules are linted in parallel with bounded concurrency.

Return Type
Void !
Arguments
NameTypeDefault ValueDescription
include[String ! ] -Include only modules whose directory matches one of these globs.
exclude[String ! ] -Exclude modules whose directory matches any of these globs.
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 lint
func (m *MyModule) Example(ctx context.Context)   {
	return dag.
			Go().
			Lint(ctx)
}
@function
async def example() -> None:
	return await (
		dag.go()
		.lint()
	)
@func()
async example(): Promise<void> {
	return dag
		.go()
		.lint()
}

lintBase() 🔗

LintBase returns a golangci-lint container with source and caches mounted, ready to run golangci-lint run. The Debian-based image is used (not Alpine) because it includes kernel headers needed by CGO transitive dependencies. The golangci-lint cache volume includes the linter version so that version bumps start fresh.

It is exposed so consumers can build a lint stage (e.g. for benchmarks) on the same base and cache this toolchain uses, instead of reconstructing it.

When mod is non-empty and not “.”, the container’s working directory is set to the module subdirectory so golangci-lint operates on that module.

Return Type
Container !
Arguments
NameTypeDefault ValueDescription
modString -Module directory relative to the source root.
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 lint-base
func (m *MyModule) Example() *dagger.Container  {
	return dag.
			Go().
			LintBase()
}
@function
def example() -> dagger.Container:
	return (
		dag.go()
		.lint_base()
	)
@func()
example(): Container {
	return dag
		.go()
		.lintBase()
}

lintDeadcode() 🔗

LintDeadcode reports unreachable functions using the golang.org/x/tools deadcode analyzer. The analyzer is installed at call time into the Go build environment and run against pkgs. It scans only the root module, like the deadcode tool itself.

This is an advisory lint: it is intentionally not annotated +check, so it does not run under dagger check. Invoke it explicitly (dagger call go lint-deadcode) or wrap it in a consuming module.

Return Type
Void !
Arguments
NameTypeDefault ValueDescription
pkgs[String ! ] ["./..."]Packages to analyze.
versionString -deadcode analyzer version (golang.org/x/tools). Defaults to the version pinned in this module.
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 lint-deadcode
func (m *MyModule) Example(ctx context.Context)   {
	return dag.
			Go().
			LintDeadcode(ctx)
}
@function
async def example() -> None:
	return await (
		dag.go()
		.lint_deadcode()
	)
@func()
async example(): Promise<void> {
	return dag
		.go()
		.lintDeadcode()
}

lintModule() 🔗

LintModule runs golangci-lint on a single module directory.

Return Type
Void !
Arguments
NameTypeDefault ValueDescription
modString !-Module directory relative to the source root.
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 lint-module --mod string
func (m *MyModule) Example(ctx context.Context, mod string)   {
	return dag.
			Go().
			LintModule(ctx, mod)
}
@function
async def example(mod: str) -> None:
	return await (
		dag.go()
		.lint_module(mod)
	)
@func()
async example(mod: string): Promise<void> {
	return dag
		.go()
		.lintModule(mod)
}

modules() 🔗

Modules returns the list of Go module directories discovered in the source tree. Each entry is a relative directory path (e.g. “.” for the root module, “toolchains/go” for a nested one). Results are filtered by the optional include and exclude glob patterns.

Return Type
[String ! ] !
Arguments
NameTypeDefault ValueDescription
include[String ! ] -Include only modules whose directory matches one of these globs. An empty list matches all modules.
exclude[String ! ] -Exclude modules whose directory matches any of these globs. Checked before include.
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 modules
func (m *MyModule) Example(ctx context.Context) []string  {
	return dag.
			Go().
			Modules(ctx)
}
@function
async def example() -> List[str]:
	return await (
		dag.go()
		.modules()
	)
@func()
async example(): Promise<string[]> {
	return dag
		.go()
		.modules()
}

test() 🔗

Test runs the Go test suite. Uses only cacheable flags so that Go’s internal test result cache (GOCACHE) can skip unchanged packages across runs via the persistent go-build cache volume.

Return Type
Void !
Arguments
NameTypeDefault ValueDescription
runString -Only run tests matching this regex.
skipString -Skip tests matching this regex.
failfastBoolean -Abort test run on first failure.
parallelInteger 0How many tests to run in parallel. Defaults to the number of CPUs.
timeoutString "30m"How long before timing out the test run.
countInteger 0Number of times to run each test. Zero uses Go's default (enables test result caching).
pkgs[String ! ] ["./..."]Packages to test.
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 test
func (m *MyModule) Example(ctx context.Context)   {
	return dag.
			Go().
			Test(ctx)
}
@function
async def example() -> None:
	return await (
		dag.go()
		.test()
	)
@func()
async example(): Promise<void> {
	return dag
		.go()
		.test()
}

testCoverage() 🔗

TestCoverage runs Go tests with coverage profiling and returns the profile file. Runs independently of [Go.Test] because -coverprofile disables Go’s internal test result caching. Dagger’s layer caching still shares the base container layers (image, module download) with [Go.Test].

Return Type
File !
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 test-coverage
func (m *MyModule) Example() *dagger.File  {
	return dag.
			Go().
			TestCoverage()
}
@function
def example() -> dagger.File:
	return (
		dag.go()
		.test_coverage()
	)
@func()
example(): File {
	return dag
		.go()
		.testCoverage()
}

testIntegration() 🔗

TestIntegration runs only integration tests by selecting tests whose names match common integration test naming patterns. Uses -run to include only tests matching the pattern. If run is provided, it overrides the default pattern. Delegates to [Go.Test].

Return Type
Void !
Arguments
NameTypeDefault ValueDescription
runString -Only run tests matching this regex. Overrides the default integration test pattern when provided.
skipString -Skip tests matching this regex.
failfastBoolean -Abort test run on first failure.
parallelInteger 0How many tests to run in parallel. Defaults to the number of CPUs.
timeoutString "30m"How long before timing out the test run.
countInteger 0Number of times to run each test. Zero uses Go's default (enables test result caching).
pkgs[String ! ] ["./..."]Packages to test.
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 test-integration
func (m *MyModule) Example(ctx context.Context)   {
	return dag.
			Go().
			TestIntegration(ctx)
}
@function
async def example() -> None:
	return await (
		dag.go()
		.test_integration()
	)
@func()
async example(): Promise<void> {
	return dag
		.go()
		.testIntegration()
}

testUnit() 🔗

TestUnit runs only unit tests by skipping tests that match common integration test naming patterns. Uses -skip to exclude tests whose names match the pattern. If skip is provided, it overrides the default pattern. Delegates to [Go.Test].

Not annotated +check: project-specific base containers may need extra packages (see aptPackages in [Go.New]). Consuming projects should wrap this in their own +check function that constructs [Go] with the right base.

Return Type
Void !
Arguments
NameTypeDefault ValueDescription
skipString -Skip tests matching this regex. Overrides the default integration test pattern when provided.
runString -Only run tests matching this regex.
failfastBoolean -Abort test run on first failure.
parallelInteger 0How many tests to run in parallel. Defaults to the number of CPUs.
timeoutString "30m"How long before timing out the test run.
countInteger 0Number of times to run each test. Zero uses Go's default (enables test result caching).
pkgs[String ! ] ["./..."]Packages to test.
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 test-unit
func (m *MyModule) Example(ctx context.Context)   {
	return dag.
			Go().
			TestUnit(ctx)
}
@function
async def example() -> None:
	return await (
		dag.go()
		.test_unit()
	)
@func()
async example(): Promise<void> {
	return dag
		.go()
		.testUnit()
}

tidy() 🔗

Tidy runs go mod tidy across all discovered Go modules and returns the merged changeset.

Return Type
Changeset !
Arguments
NameTypeDefault ValueDescription
include[String ! ] -Include only modules whose directory matches one of these globs.
exclude[String ! ] -Exclude modules whose directory matches any of these globs.
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 tidy
func (m *MyModule) Example() *dagger.Changeset  {
	return dag.
			Go().
			Tidy()
}
@function
def example() -> dagger.Changeset:
	return (
		dag.go()
		.tidy()
	)
@func()
example(): Changeset {
	return dag
		.go()
		.tidy()
}

tidyModule() 🔗

TidyModule runs go mod tidy for a single module directory and returns the changeset of go.mod/go.sum changes. The mod parameter is a relative directory path (e.g. “.” for root, “toolchains/go” for nested).

Modules without external dependencies do not emit a go.sum. The returned changeset reflects whatever go mod tidy produced on disk: include the go.sum when it exists, remove it when tidy dropped it from a source that previously had one, and otherwise emit only go.mod.

Return Type
Changeset !
Arguments
NameTypeDefault ValueDescription
modString !-Module directory relative to the source root.
Example
dagger -m github.com/MacroPower/x/toolchains/go@3f4ef26289cf6c0690d4ce596cd8832b729b8ad4 call \
 tidy-module --mod string
func (m *MyModule) Example(mod string) *dagger.Changeset  {
	return dag.
			Go().
			TidyModule(mod)
}
@function
def example(mod: str) -> dagger.Changeset:
	return (
		dag.go()
		.tidy_module(mod)
	)
@func()
example(mod: string): Changeset {
	return dag
		.go()
		.tidyModule(mod)
}