BG7, BN7: a fetch naming builds reads each package member from the artifact store
Each member's build is read at /v2/<module>/<artifact>/blobs/<digest> through the required provision artifact-store (bound to a file), checked against its digest and laid as the package it names: a Go module zip replaced in the temporary modfile, an npm tarball in node_modules. A mismatch or a store that does not answer fails the step naming the member. Builds: design 47 G §465, §373, §466 (lead answer A-151) Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package main
|
||||
|
||||
// **A group run's package members, laid from their builds** (design 47 G §465, §373): a fetch naming `builds` reads each
|
||||
// member's build (the npm package's packed tarball, package.go's packed) from the artifact store by its digest, checks
|
||||
// it and places it as the local package it names in each TypeScript module's node_modules: nothing is fetched by a
|
||||
// version, and none is reserved. A member that does not match its digest, or a store that does not answer, fails the
|
||||
// step naming the member.
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"git.novox.be/novox/mesh-catalog/modules/mesh-build-go/buildstep"
|
||||
sdkstep "git.novox.be/novox/mesh-delivery/sdk/buildstep"
|
||||
)
|
||||
|
||||
// storedBuild is one member's build, read and checked.
|
||||
type storedBuild struct {
|
||||
member sdkstep.FetchBuild
|
||||
tgz []byte
|
||||
}
|
||||
|
||||
// readBuilds reads every member of builds from the artifact store.
|
||||
func (m *Module) readBuilds(ctx context.Context, builds []sdkstep.FetchBuild) ([]storedBuild, error) {
|
||||
if len(builds) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
base, err := buildstep.StoreURL(m.ArtifactStoreFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("a group run's members are read from the artifact store: %w", err)
|
||||
}
|
||||
var out []storedBuild
|
||||
for _, b := range builds {
|
||||
data, err := buildstep.ReadStoredBuild(ctx, m.httpClient(), base, b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, storedBuild{b, data})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// names says whether a member of the builds is the package pkg.
|
||||
func namesPackage(builds []storedBuild, pkg string) bool {
|
||||
for _, b := range builds {
|
||||
if b.member.Package == pkg {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// layBuilds places each member in dir's node_modules as the package it names, in place of any other.
|
||||
func (m *Module) layBuilds(dir string, builds []storedBuild) error {
|
||||
for _, b := range builds {
|
||||
into := filepath.Join(dir, "node_modules", filepath.FromSlash(b.member.Package))
|
||||
if err := os.RemoveAll(into); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := unpackPackage(b.tgz, into); err != nil {
|
||||
return fmt.Errorf("the build of %s (%s %s at %s): %w", b.member.Package, b.member.Module, b.member.Artifact, b.member.Digest, err)
|
||||
}
|
||||
if m.Say != nil {
|
||||
m.Say("laid %s from its build %s (%s %s)", b.member.Package, b.member.Digest, b.member.Module, b.member.Artifact)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user