Hand an archive artifact to the packing step (issue 1589, ADR 0478 §1)

This commit is contained in:
2026-10-21 09:12:23 +00:00
parent d369adf245
commit 640c6f9b0c
2 changed files with 23 additions and 9 deletions
@@ -40,7 +40,7 @@ type BuildResult struct {
func (m *Module) buildTool() StepTool {
return StepTool{
Name: "build_go_build",
Description: "Build one Go bundle artifact of a module of a fetched workspace with the build agent's recipe, by the " +
Description: "Build one Go bundle or archive artifact of a module of a fetched workspace with the build agent's recipe, by the " +
"installed Go and no network, and pack it. Answers a step id at once; the step ends on its key with the " +
"artifact's digest, size and the archive's path.",
Input: map[string]any{
@@ -105,8 +105,11 @@ func (m *Module) build(ctx context.Context, args map[string]any) (any, error) {
if art == nil {
return nil, fmt.Errorf("the module %s has no artifact %q (it has %s)", manifest.Module, name, strings.Join(names, ", "))
}
if art.Kind == "archive" {
return m.buildArchive(ctx, workspace, module, dir, *art)
}
if art.Kind != "bundle" || art.Language != "go" {
return nil, fmt.Errorf("the artifact %s of %s is a %s of language %q: this module builds Go bundles", name, manifest.Module, art.Kind, art.Language)
return nil, fmt.Errorf("the artifact %s of %s is a %s of language %q: this module builds Go bundles and archives", name, manifest.Module, art.Kind, art.Language)
}
if strings.TrimSpace(art.From) == "" {
return nil, fmt.Errorf("the artifact %s of %s says nothing it is built from", name, manifest.Module)
@@ -130,19 +133,30 @@ func (m *Module) build(ctx context.Context, args map[string]any) (any, error) {
if r := m.Run(ctx, m.buildEnv(dir), "go", cmd...); r.Status != 0 || r.Err != "" {
return nil, fmt.Errorf("go build of %s: %s", art.Name, causeLine(r.Err+"\n"+r.Stderr+"\n"+r.Stdout))
}
archive, digest, err := buildstep.Pack(out)
res, err := m.packInto(workspace, module, art.Name, out)
if err != nil {
return nil, fmt.Errorf("packing %s: %w", art.Name, err)
return nil, err
}
res.Binary = binary
return res, nil
}
// packInto packs a directory with mesh-sdk's Pack, as the build agent packs every artifact, and leaves the archive in
// the workspace's artifacts directory.
func (m *Module) packInto(workspace, module, artifact, root string) (BuildResult, error) {
archive, digest, err := buildstep.Pack(root)
if err != nil {
return BuildResult{}, fmt.Errorf("packing %s: %w", artifact, err)
}
artifacts := filepath.Join(m.Work, workspace, "artifacts")
if err := os.MkdirAll(artifacts, 0o700); err != nil {
return nil, err
return BuildResult{}, err
}
path := filepath.Join(artifacts, strings.ReplaceAll(module, "/", "_")+"."+art.Name+".tar.gz")
path := filepath.Join(artifacts, strings.ReplaceAll(module, "/", "_")+"."+artifact+".tar.gz")
if err := os.WriteFile(path, archive, 0o600); err != nil {
return nil, err
return BuildResult{}, err
}
return BuildResult{Artifact: art.Name, Binary: binary, Digest: digest, Size: len(archive), Path: path}, nil
return BuildResult{Artifact: artifact, Digest: digest, Size: len(archive), Path: path}, nil
}
// buildEnv is the environment of the compile: the build agent's (CGO_ENABLED=0, GOFLAGS) with the installed go
@@ -175,7 +175,7 @@ func TestTheArchiveHoldsOneExecutableAndTwoBuildsAreOneDigest(t *testing.T) {
func TestAnArtifactOfAnotherLanguageFailsTheStepNamingIt(t *testing.T) {
for artifact, want := range map[string]string{
`{"name":"tools","kind":"bundle","language":"typescript","entrypoints":["index.js"],"loads":["index.js"]}`: `language "typescript"`,
`{"name":"tools","kind":"archive","from":"files"}`: "archive",
`{"name":"tools","kind":"image","from":"files"}`: "image",
} {
m, states, calls := buildModule(t, manifestWith(artifact), "x")
_, st := runBuild(t, m, states, "tools")