Add reusable CI preparation operations

This commit is contained in:
2026-10-06 18:59:29 +00:00
parent 579daa9485
commit d970aac709
9 changed files with 511 additions and 4 deletions

View File

@@ -89,6 +89,30 @@ func New(ctx context.Context, directory string) (*Tool, error) {
return tool, nil
}
// PrepareBuildDependencies downloads module dependencies with the available
// local Go toolchain. It preserves caller module-network settings and caches,
// while disabling workspace discovery and automatic toolchain downloads.
func PrepareBuildDependencies(ctx context.Context, directory string) error {
captured := &combinedWriter{}
err := process.Run(ctx, process.Invocation{
Args: []string{"go", "mod", "download"},
Dir: directory,
Env: map[string]string{
"GOWORK": "off",
"GOTOOLCHAIN": "local",
},
Stdout: captured,
Stderr: captured,
})
if err != nil {
if output := strings.TrimSpace(string(captured.Bytes())); output != "" {
return fmt.Errorf("go mod download: %w: %s", err, output)
}
return fmt.Errorf("go mod download: %w", err)
}
return nil
}
// HostTarget reports the Go command's host operating system and architecture.
func (tool *Tool) HostTarget() Target {
return tool.host