Join: merge A3 (wip/registry-a3)
Conflicts, both sides kept: artifact-store-tools' invokes (the assigner's and indexer's read tools, followed through views, beside the registry seats' hold, release and remove), its main (the views reader and the seat asker), its manifest row; gitea's invokes (the indexer's read tool, the hand act and the builder's versions) and its consumes of the indexer's views. gitea's account test takes the packages account's names; repoCheckFacts, removed on main, is not imported. No catalogue module reads the indexer's state. Claude-Session: https://claude.ai/code/session_01JG73KJNrH5EgFXMKKYSrig
This commit is contained in:
@@ -98,9 +98,8 @@ func (m *Module) installDev(ctx context.Context, root, dir, rel string) error {
|
||||
return writeShims(filepath.Join(dir, "node_modules"), shimDir(root, rel))
|
||||
}
|
||||
|
||||
// npmrcIn writes the npm configuration for the mesh's registry, with its credential, for one command of this process;
|
||||
// the caller removes it. It lies in this process's temporary directory, never in a workspace: a run step is given the
|
||||
// workspace and a /tmp of its own, so no step's mounts hold the credential (ADR 0498 §5, ADR 0500 §4).
|
||||
// npmrcIn writes the npm configuration for the mesh's registry, read anonymously, for one command of this process; the
|
||||
// caller removes it. It lies in this process's temporary directory, never in a workspace (ADR 0498 §5, ADR 0500 §4).
|
||||
func (m *Module) npmrcIn(root string) (string, error) {
|
||||
if m.Toolchain == nil || m.Toolchain.Registry == nil {
|
||||
return "", fmt.Errorf("the module has no package registry")
|
||||
@@ -189,7 +188,14 @@ func writeShims(nm, into string) error {
|
||||
// buildAndPack builds the package in dir with its own build script, if it has one, and packs it with npm pack, both
|
||||
// shut off (write: a trunk build's, which alone writes the shared cache). The packed file is read and removed: it never
|
||||
// stays on the node.
|
||||
func (m *Module) buildAndPack(ctx context.Context, root, dir, rel string, write bool) (packed, error) {
|
||||
func (m *Module) buildAndPack(ctx context.Context, root, dir, rel string, write bool, version string) (packed, error) {
|
||||
if version != "" {
|
||||
restore, err := setPackageVersion(dir, version)
|
||||
if err != nil {
|
||||
return packed{}, err
|
||||
}
|
||||
defer restore()
|
||||
}
|
||||
p, err := readPackageJSON(dir)
|
||||
if err != nil {
|
||||
return packed{}, err
|
||||
@@ -281,7 +287,7 @@ func (m *Module) packGroup(ctx context.Context, root string, run forgekey.Runner
|
||||
if err := m.installDev(ctx, root, dir, "package"); err != nil {
|
||||
return packed{}, err
|
||||
}
|
||||
return m.buildAndPack(ctx, root, dir, "package", false)
|
||||
return m.buildAndPack(ctx, root, dir, "package", false, "")
|
||||
}
|
||||
|
||||
// sdkLocked is what a module's lock names of the SDK: its version, its integrity and where it was resolved from; ok is
|
||||
@@ -412,7 +418,6 @@ func (m *Module) registryVersion(ctx context.Context, name, version string) (tar
|
||||
if err != nil {
|
||||
return "", "", false, err
|
||||
}
|
||||
reg.authorize(req)
|
||||
resp, err := m.httpClient().Do(req)
|
||||
if err != nil {
|
||||
return "", "", false, fmt.Errorf("asking the registry for %s: %w", name, err)
|
||||
@@ -442,15 +447,10 @@ func (m *Module) registryPackage(ctx context.Context, name, version string) ([]b
|
||||
if err != nil || !held {
|
||||
return nil, held, err
|
||||
}
|
||||
reg, err := m.Toolchain.Registry()
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, tarball, nil)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
reg.authorize(req)
|
||||
resp, err := m.httpClient().Do(req)
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("downloading %s@%s: %w", name, version, err)
|
||||
@@ -521,63 +521,60 @@ func fetchCommit(ctx context.Context, run forgekey.Runner, dir, remote, commit,
|
||||
return buildstep.FetchCommit(ctx, run, dir, remote, commit, ref, m.FetchOptions...)
|
||||
}
|
||||
|
||||
// buildPackage builds and packs a package artifact (ADR 0498 §5): its digest is the packed file's. Only a trunk build
|
||||
// (publish) publishes it, from this module's own process with the registry's write credential, which no run step is
|
||||
// given: a version the registry lacks is published; the same packed file already there is done without a publish;
|
||||
// another packed file under that version fails `version taken:`. The reference is <name>@<version>, answered only when
|
||||
// the registry holds this build's file; a candidate answers its digest alone.
|
||||
func (m *Module) buildPackage(ctx context.Context, workspace, module, root, dir string, a artifact, publish bool) (any, error) {
|
||||
// buildPackage builds and packs a package artifact (ADR 0498 §5): its digest is the packed file's. A trunk build
|
||||
// (publish) the builder gave a version packs it under that version and publishes it through npm-package-registry
|
||||
// (design 51 *Publishing*, CAT-BN3), from this module's own process, which holds no write credential: the holder asks
|
||||
// the builder, answers held for the same file and refuses another under that version. The reference is
|
||||
// <name>@<version>, answered only when the holder took it; a candidate, or a trunk build not numbered, answers its
|
||||
// digest alone.
|
||||
func (m *Module) buildPackage(ctx context.Context, workspace, module, root, dir string, a artifact, publish bool, version, seat string) (any, error) {
|
||||
rel := module
|
||||
if rel == "" {
|
||||
rel = "."
|
||||
}
|
||||
p, err := m.buildAndPack(ctx, root, dir, rel, publish)
|
||||
if !publish {
|
||||
version = ""
|
||||
}
|
||||
if seat == "" {
|
||||
seat = buildstep.NpmSeat
|
||||
}
|
||||
if version != "" && seat != buildstep.NpmSeat {
|
||||
return nil, fmt.Errorf("the package %s is published through %s, not %s: this module publishes npm packages", a.Name, buildstep.NpmSeat, seat)
|
||||
}
|
||||
p, err := m.buildAndPack(ctx, root, dir, rel, publish, version)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res := BuildResult{Workspace: workspace, Module: module, Artifact: a.Name, Digest: p.Digest, Bytes: len(p.tgz)}
|
||||
if publish {
|
||||
if res.Reference, err = m.publish(ctx, root, p); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if version == "" {
|
||||
return res, nil
|
||||
}
|
||||
if err := m.publishOn(ctx, seat, p.Name, "package", p.Version, p.Digest, p.tgz); err != nil {
|
||||
return nil, fmt.Errorf("%s%s: %v", delivery.NotStored, a.Name, err)
|
||||
}
|
||||
res.Reference = p.Name + "@" + p.Version
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// publish puts a packed package into the registry unless it holds that version, and answers <name>@<version>.
|
||||
func (m *Module) publish(ctx context.Context, root string, p packed) (string, error) {
|
||||
ref := p.Name + "@" + p.Version
|
||||
_, integrity, held, err := m.registryVersion(ctx, p.Name, p.Version)
|
||||
// setPackageVersion writes version as dir's package.json `version` (the builder's, design 51 *The versions*), so npm
|
||||
// packs the package under it; restore puts the file back as it was.
|
||||
func setPackageVersion(dir, version string) (restore func(), err error) {
|
||||
path := filepath.Join(dir, "package.json")
|
||||
raw, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, fmt.Errorf("the package's package.json: %w", err)
|
||||
}
|
||||
if held {
|
||||
if integrity == p.Integrity {
|
||||
return ref, nil // this very file, published before: done without a publish
|
||||
}
|
||||
return "", fmt.Errorf("%s%s: the registry holds it as %s, and this build packs %s", delivery.VersionTaken, ref, integrity, p.Integrity)
|
||||
var doc map[string]json.RawMessage
|
||||
if err := json.Unmarshal(raw, &doc); err != nil {
|
||||
return nil, fmt.Errorf("the package's package.json does not parse: %w", err)
|
||||
}
|
||||
file, err := os.CreateTemp(root, "publish-*.tgz")
|
||||
doc["version"], _ = json.Marshal(version)
|
||||
out, err := json.MarshalIndent(doc, "", " ")
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
defer os.Remove(file.Name()) // the packed file leaves the node once its publish answered
|
||||
if _, err := file.Write(p.tgz); err != nil {
|
||||
file.Close()
|
||||
return "", err
|
||||
if err := os.WriteFile(path, append(out, '\n'), 0o644); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := file.Close(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
npmrc, err := m.npmrcIn(root)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer os.Remove(npmrc)
|
||||
env := append(m.baseEnv(), "npm_config_cache="+m.npmCache())
|
||||
r := m.Run(ctx, env, "npm", "publish", file.Name(), "--ignore-scripts", "--userconfig", npmrc)
|
||||
if why := ranFailed(r); why != "" {
|
||||
return "", fmt.Errorf("publishing %s: %s", ref, why)
|
||||
}
|
||||
return ref, nil
|
||||
return func() { _ = os.WriteFile(path, raw, 0o644) }, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user