BLD11: the three build modules take the version from the ask as MESH_VERSION; version.numbered is no longer heard

The Go compile, the Node tsc/esbuild/npm and the image's buildah bud get the
build argument MESH_VERSION from the version the build ask carries. The late
publish on version.numbered goes (code, tests, the consumes of the Go and
image manifests). The image's label and tag and a program's stamp are open
(question to the lead): the design names no key or symbol.

Builds: design 47 G §349, §370, §413

Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
This commit is contained in:
2026-11-11 11:00:52 +01:00
parent 25bbd55539
commit 357967308f
18 changed files with 106 additions and 264 deletions
@@ -110,8 +110,9 @@ func (m *Module) build(ctx context.Context, args map[string]any) (any, error) {
if err != nil {
return nil, err
}
// The version the build ask carries is the build argument MESH_VERSION of every artifact (design 47 G §370).
version, _ := args["version"].(string)
if a.Kind == "package" {
version, _ := args["version"].(string)
seat, _ := args["seat"].(string)
at := a.packageDir(dir)
return m.buildPackage(ctx, workspace, module, root, filepath.Join(dir, filepath.FromSlash(at)), at, a, publish, version, seat)
@@ -145,14 +146,14 @@ func (m *Module) build(ctx context.Context, args map[string]any) (any, error) {
tsc := []string{m.tsc(), "--module", "NodeNext", "--moduleResolution", "NodeNext", "--target", "ES2022",
"--rootDir", ".", "--outDir", out}
tsc = append(tsc, sourcesFor(a.Entrypoints, out, ".ts")...)
if why := ranFailed(m.runIn(ctx, root, publish, dir, nil, "node", tsc...)); why != "" {
if why := ranFailed(m.runIn(ctx, root, publish, dir, versionEnv(version), "node", tsc...)); why != "" {
return nil, fmt.Errorf("tsc for %s: %s", a.Name, why)
}
launchers, err := writeLaunchers(filepath.Join(dir, out), a)
if err != nil {
return nil, err
}
if err := m.bundle(ctx, root, publish, dir, a, launchers); err != nil {
if err := m.bundle(ctx, root, publish, dir, a, launchers, version); err != nil {
return nil, err
}
bundleDir := filepath.Join(dir, final)
@@ -185,7 +186,7 @@ func (m *Module) build(ctx context.Context, args map[string]any) (any, error) {
// bundle makes every entrypoint and every launcher ONE file, with esbuild (builder.go:1971-2039): an entrypoint is
// bundled in place under its own name, a launcher keeps its name with the extension .mjs.
func (m *Module) bundle(ctx context.Context, root string, publish bool, dir string, a artifact, launchers map[string]string) error {
func (m *Module) bundle(ctx context.Context, root string, publish bool, dir string, a artifact, launchers map[string]string, version string) error {
out, final := Out(a.Name), Out(a.Name)+".bundled"
if err := os.RemoveAll(filepath.Join(dir, final)); err != nil {
return err
@@ -212,7 +213,7 @@ func (m *Module) bundle(ctx context.Context, root string, publish bool, dir stri
return nil
}
args := append(append(append([]string{}, entries...), common...), extra...)
if why := ranFailed(m.runIn(ctx, root, publish, dir, nil, m.esbuild(), args...)); why != "" {
if why := ranFailed(m.runIn(ctx, root, publish, dir, versionEnv(version), m.esbuild(), args...)); why != "" {
return fmt.Errorf("esbuild for %s: %s", a.Name, why)
}
return nil
@@ -319,3 +320,11 @@ func readArtifact(dir, name string) (artifact, error) {
}
return artifact{}, fmt.Errorf("module.json declares no artifact %q", name)
}
// versionEnv is the build argument MESH_VERSION for the version the build ask carries, none when it carries none.
func versionEnv(version string) []string {
if version == "" {
return nil
}
return []string{"MESH_VERSION=" + version}
}
@@ -302,3 +302,29 @@ func TestRanFailedKeepsTheError(t *testing.T) {
}
}
}
// Design 47 G §370 (BLD11): a build ask carrying a version gives the compiler and the bundler the build argument
// MESH_VERSION; one without gives none.
func TestTheBundleBuildGetsTheVersionTheAskCarriesAsMeshVersion(t *testing.T) {
for _, version := range []string{"1.4.3", ""} {
m, f, _ := builtMachine(t, "")
args := buildArgs()
if version != "" {
args["version"] = version
}
if _, err := m.build(context.Background(), args); err != nil {
t.Fatal(err)
}
for _, c := range f.calls {
got := ""
for _, e := range c.env {
if v, ok := strings.CutPrefix(e, "MESH_VERSION="); ok {
got = v
}
}
if got != version {
t.Errorf("ask version %q: %s ran with MESH_VERSION=%q", version, c.name, got)
}
}
}
}
@@ -201,6 +201,7 @@ func (m *Module) buildAndPack(ctx context.Context, root, dir, rel string, write
return packed{}, err
}
env := []string{"PATH=" + shimDir(root, rel) + ":" + pathOrDefault(), "npm_config_cache=" + m.npmCache()}
env = append(env, versionEnv(version)...)
if p.Scripts["build"] != "" {
if why := ranFailed(m.runIn(ctx, root, write, dir, env, "npm", "run", "build")); why != "" {
return packed{}, fmt.Errorf("the build of the package %s: %s", p.Name, why)