go
Provides common pipeline stages that any Go project can consume.Installation
dagger install github.com/MacroPower/x/toolchains/go@483dc69c30e485db85d928723096efa22c3603c6Entrypoint
Return Type
Go !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| source | Directory | - | Project source directory. Ignore patterns (e.g. .git, dist) belong in the consuming project's root dagger.json customizations, not here. |
| goMod | Directory | - | 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. |
| version | String | - | Go version for base images. Defaults to the version pinned in this module. |
| lintVersion | String | - | golangci-lint version for the lint base image. Defaults to the version pinned in this module. |
| moduleCache | CacheVolume | - | Cache volume for Go module downloads (GOMODCACHE). Defaults to a namespaced volume named "<cacheNamespace>:modules". |
| buildCache | CacheVolume | - | Cache volume for Go build artifacts (GOCACHE). Defaults to a namespaced volume named "<cacheNamespace>:build". |
| base | Container | - | 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. |
| cgo | Boolean | - | Enable CGO. |
| race | Boolean | - | Enable the race detector. Implies cgo=true. |
| injectGitHead | Boolean | - | 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. |
| cacheNamespace | String | - | 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@483dc69c30e485db85d928723096efa22c3603c6 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@483dc69c30e485db85d928723096efa22c3603c6 call \
versionfunc (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@483dc69c30e485db85d928723096efa22c3603c6 call \
lint-versionfunc (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@483dc69c30e485db85d928723096efa22c3603c6 call \
sourcefunc (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@483dc69c30e485db85d928723096efa22c3603c6 call \
module-cachefunc (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@483dc69c30e485db85d928723096efa22c3603c6 call \
build-cachefunc (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@483dc69c30e485db85d928723096efa22c3603c6 call \
basefunc (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@483dc69c30e485db85d928723096efa22c3603c6 call \
ldflagsfunc (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@483dc69c30e485db85d928723096efa22c3603c6 call \
valuesfunc (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@483dc69c30e485db85d928723096efa22c3603c6 call \
cgofunc (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@483dc69c30e485db85d928723096efa22c3603c6 call \
racefunc (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@483dc69c30e485db85d928723096efa22c3603c6 call \
inject-git-headfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| parallel | Boolean ! | false | Run stages concurrently to measure full-pipeline wall-clock time. |
Example
dagger -m github.com/MacroPower/x/toolchains/go@483dc69c30e485db85d928723096efa22c3603c6 call \
benchmark-summary --parallel booleanfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| pkg | String ! | - | Package to build. |
| noSymbols | Boolean | - | Disable symbol table. |
| noDwarf | Boolean | - | Disable DWARF generation. |
| platform | Scalar | - | Target build platform. |
Example
dagger -m github.com/MacroPower/x/toolchains/go@483dc69c30e485db85d928723096efa22c3603c6 call \
binary --pkg stringfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| pkgs | [String ! ] | ["./..."] | Packages to build. |
| noSymbols | Boolean | - | Disable symbol table. |
| noDwarf | Boolean | - | Disable DWARF generation. |
| platform | Scalar | - | Target build platform. |
| outDir | String | "./bin/" | Output directory path inside the container. |
Example
dagger -m github.com/MacroPower/x/toolchains/go@483dc69c30e485db85d928723096efa22c3603c6 call \
buildfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| ctr | Container ! | - | Container to bust the cache for. |
Example
dagger -m github.com/MacroPower/x/toolchains/go@483dc69c30e485db85d928723096efa22c3603c6 call \
cache-bust --ctr IMAGE:TAGfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| 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@483dc69c30e485db85d928723096efa22c3603c6 call \
check-tidyfunc (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@483dc69c30e485db85d928723096efa22c3603c6 call \
downloadfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| ctr | Container ! | - | Container to initialize. |
Example
dagger -m github.com/MacroPower/x/toolchains/go@483dc69c30e485db85d928723096efa22c3603c6 call \
ensure-git-init --ctr IMAGE:TAGfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| ctr | Container ! | - | Container to initialize. |
| remoteUrl | String | - | Remote URL to add as origin. When empty, no remote is configured. |
Example
dagger -m github.com/MacroPower/x/toolchains/go@483dc69c30e485db85d928723096efa22c3603c6 call \
ensure-git-repo --ctr IMAGE:TAGfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| platform | Scalar | - | Target platform (e.g. "linux/amd64"). When empty, uses the host platform. |
Example
dagger -m github.com/MacroPower/x/toolchains/go@483dc69c30e485db85d928723096efa22c3603c6 call \
envfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| 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@483dc69c30e485db85d928723096efa22c3603c6 call \
format-gofunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| mod | String ! | - | Module directory relative to the source root. |
Example
dagger -m github.com/MacroPower/x/toolchains/go@483dc69c30e485db85d928723096efa22c3603c6 call \
format-go-module --mod stringfunc (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@483dc69c30e485db85d928723096efa22c3603c6 call \
generatefunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| 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@483dc69c30e485db85d928723096efa22c3603c6 call \
lintfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| mod | String | - | Module directory relative to the source root. |
Example
dagger -m github.com/MacroPower/x/toolchains/go@483dc69c30e485db85d928723096efa22c3603c6 call \
lint-basefunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| pkgs | [String ! ] | ["./..."] | Packages to analyze. |
| version | String | - | deadcode analyzer version (golang.org/x/tools). Defaults to the version pinned in this module. |
Example
dagger -m github.com/MacroPower/x/toolchains/go@483dc69c30e485db85d928723096efa22c3603c6 call \
lint-deadcodefunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| mod | String ! | - | Module directory relative to the source root. |
Example
dagger -m github.com/MacroPower/x/toolchains/go@483dc69c30e485db85d928723096efa22c3603c6 call \
lint-module --mod stringfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| 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@483dc69c30e485db85d928723096efa22c3603c6 call \
modulesfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| run | String | - | Only run tests matching this regex. |
| skip | String | - | Skip tests matching this regex. |
| failfast | Boolean | - | Abort test run on first failure. |
| parallel | Integer | 0 | How many tests to run in parallel. Defaults to the number of CPUs. |
| timeout | String | "30m" | How long before timing out the test run. |
| count | Integer | 0 | Number 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@483dc69c30e485db85d928723096efa22c3603c6 call \
testfunc (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@483dc69c30e485db85d928723096efa22c3603c6 call \
test-coveragefunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| run | String | - | Only run tests matching this regex. Overrides the default integration test pattern when provided. |
| skip | String | - | Skip tests matching this regex. |
| failfast | Boolean | - | Abort test run on first failure. |
| parallel | Integer | 0 | How many tests to run in parallel. Defaults to the number of CPUs. |
| timeout | String | "30m" | How long before timing out the test run. |
| count | Integer | 0 | Number 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@483dc69c30e485db85d928723096efa22c3603c6 call \
test-integrationfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| skip | String | - | Skip tests matching this regex. Overrides the default integration test pattern when provided. |
| run | String | - | Only run tests matching this regex. |
| failfast | Boolean | - | Abort test run on first failure. |
| parallel | Integer | 0 | How many tests to run in parallel. Defaults to the number of CPUs. |
| timeout | String | "30m" | How long before timing out the test run. |
| count | Integer | 0 | Number 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@483dc69c30e485db85d928723096efa22c3603c6 call \
test-unitfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| 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@483dc69c30e485db85d928723096efa22c3603c6 call \
tidyfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| mod | String ! | - | Module directory relative to the source root. |
Example
dagger -m github.com/MacroPower/x/toolchains/go@483dc69c30e485db85d928723096efa22c3603c6 call \
tidy-module --mod stringfunc (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)
}