ci / ci (pull_request) Successful in 3m21s
Resolves the build half of sow-tools#60 and closes the CLI gap sow-tools#53's sweep found: PR #71 shipped #53's original surface, not the one #56, #62 and #65 settled. - `depot.KeyStore` (`ProbeKey`/`PutReader`/`GetKey`) addresses the zone by object key instead of by depot sha, reusing the existing IPv4-pinned transport, retry and tri-state probe. The sha-addressed `Backend` now rides on it; no new HTTP client. - `nwsync` gains a sink: the zone by default, a local tree with `--out DIR` as the conformance path. Blobs upload as they are produced, the index lands last, and a blob already in the zone is skipped without paying for compression. - CLI is now `emit [--as NAME] [--out DIR] <artifact-key> <file>` and `assemble --group-id N [--tlk-key KEY] [--out DIR] <artifact-key>...`. Indexes live beside their artifact with the extension replaced, derived in one place. Flags may follow positionals, which cost a run during sow-tools#59. - Fail-closed: an artifact key whose digest does not match the file is refused, and `assemble` refuses an artifact with no index rather than publishing a manifest missing a hak. Conformance re-checked through the new CLI against upstream nwn_nwsync_write 2.1.2 on sow_vfxs_01.hak: the manifest is still byte-identical. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
141 lines
4.5 KiB
Go
141 lines
4.5 KiB
Go
// Package nwsync publishes NWSync repository data: blobs and a per-artifact
|
|
// NSYM manifest at each artifact's birth (emit), and one merged manifest at
|
|
// module release (assemble).
|
|
//
|
|
// The split exists because upstream nwn_nwsync_write wants every hak, the TLK
|
|
// and the module present in one run on one disk, which our build hosts cannot
|
|
// hold. Upstream stays the conformance oracle: manifests compare byte for
|
|
// byte, blobs compare after decompression.
|
|
package nwsync
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
)
|
|
|
|
const (
|
|
exitOK = 0
|
|
exitUsage = 64
|
|
exitInternal = 70
|
|
)
|
|
|
|
// Run executes an nwsync subcommand. args[0] is the subcommand (emit|assemble);
|
|
// returns the process exit code.
|
|
func Run(args []string, stdout, stderr io.Writer) int {
|
|
if len(args) == 0 {
|
|
printRunUsage(stderr)
|
|
return exitUsage
|
|
}
|
|
switch args[0] {
|
|
case "emit":
|
|
return runEmit(args[1:], stdout, stderr)
|
|
case "assemble":
|
|
return runAssemble(args[1:], stdout, stderr)
|
|
case "-h", "--help", "help":
|
|
printRunUsage(stdout)
|
|
return exitOK
|
|
default:
|
|
fmt.Fprintf(stderr, "nwsync: unknown subcommand %q\n\n", args[0])
|
|
printRunUsage(stderr)
|
|
return exitUsage
|
|
}
|
|
}
|
|
|
|
func printRunUsage(w io.Writer) {
|
|
fmt.Fprint(w, `usage:
|
|
nwsync emit [--as NAME] [--out DIR] <artifact-key> <file>
|
|
nwsync assemble --group-id N [--tlk-key KEY] [--out DIR] <artifact-key>...
|
|
|
|
emit explodes one .hak/.erf or one loose file (the TLK) into NWSync blobs plus
|
|
a NSYM index covering only that artifact, and uploads both. assemble merges
|
|
those indexes into one manifest, reading no bulk data. Artifact keys are depot
|
|
keys; an index lives beside its artifact, with the extension replaced.
|
|
|
|
--out DIR writes to a local repository tree instead of uploading, which is the
|
|
conformance path against upstream nwn_nwsync_write. Without it, the zone comes
|
|
from NWSYNC_STORAGE_ZONE, NWSYNC_STORAGE_PASSWORD and BUNNY_STORAGE_HOST.
|
|
`)
|
|
}
|
|
|
|
// parseArgs parses flags that may appear before, after or between positionals.
|
|
// Go's flag package stops at the first non-flag argument, which turns
|
|
// `emit <key> <file> --out DIR` into a confusing arity error.
|
|
func parseArgs(fs *flag.FlagSet, args []string) ([]string, error) {
|
|
var positional []string
|
|
for {
|
|
if err := fs.Parse(args); err != nil {
|
|
return nil, err
|
|
}
|
|
rest := fs.Args()
|
|
if len(rest) == 0 {
|
|
return positional, nil
|
|
}
|
|
positional = append(positional, rest[0])
|
|
args = rest[1:]
|
|
}
|
|
}
|
|
|
|
func runEmit(args []string, stdout, stderr io.Writer) int {
|
|
fs := flag.NewFlagSet("emit", flag.ContinueOnError)
|
|
fs.SetOutput(stderr)
|
|
as := fs.String("as", "", "published name of the artifact, when it differs from the key")
|
|
out := fs.String("out", "", "write to a local repository tree instead of uploading")
|
|
positional, err := parseArgs(fs, args)
|
|
if err != nil {
|
|
return exitUsage
|
|
}
|
|
if len(positional) != 2 {
|
|
fmt.Fprintf(stderr, "nwsync emit: <artifact-key> and <file> are both required\n")
|
|
return exitUsage
|
|
}
|
|
|
|
result, err := Emit(EmitOptions{
|
|
ArtifactKey: positional[0],
|
|
ArtifactPath: positional[1],
|
|
As: *as,
|
|
OutDir: *out,
|
|
})
|
|
if err != nil {
|
|
fmt.Fprintf(stderr, "nwsync emit: %v\n", err)
|
|
return exitInternal
|
|
}
|
|
fmt.Fprintf(stdout, "emitted %s: %d resources, %d new blobs, index %s\n",
|
|
result.Name, result.Entries, result.BlobsWritten, result.ManifestPath)
|
|
return exitOK
|
|
}
|
|
|
|
func runAssemble(args []string, stdout, stderr io.Writer) int {
|
|
fs := flag.NewFlagSet("assemble", flag.ContinueOnError)
|
|
fs.SetOutput(stderr)
|
|
tlkKey := fs.String("tlk-key", "", "depot key of the TLK, which shadows nothing and merges last")
|
|
out := fs.String("out", "", "write to a local repository tree instead of uploading")
|
|
groupID := fs.Int("group-id", 0, "NWSync group id (1 = current, 2 = testing; 0 omits it)")
|
|
moduleName := fs.String("module-name", "", "module name recorded in the sidecar")
|
|
description := fs.String("description", "", "description recorded in the sidecar")
|
|
positional, err := parseArgs(fs, args)
|
|
if err != nil {
|
|
return exitUsage
|
|
}
|
|
if len(positional) == 0 {
|
|
fmt.Fprintf(stderr, "nwsync assemble: at least one artifact key is required\n")
|
|
return exitUsage
|
|
}
|
|
|
|
result, err := Assemble(AssembleOptions{
|
|
ArtifactKeys: positional,
|
|
TLKKey: *tlkKey,
|
|
OutDir: *out,
|
|
GroupID: *groupID,
|
|
ModuleName: *moduleName,
|
|
Description: *description,
|
|
})
|
|
if err != nil {
|
|
fmt.Fprintf(stderr, "nwsync assemble: %v\n", err)
|
|
return exitInternal
|
|
}
|
|
fmt.Fprintf(stdout, "assembled manifest %s: %d resources, %s\n",
|
|
result.SHA1, result.Entries, result.ManifestPath)
|
|
return exitOK
|
|
}
|