package builds import ( "git.novox.be/novox/mesh-sdk/go/keys" ) // The builder says each done build's end itself, as an event on its own stream (design 47 G §379, A-96): the stream // BuildsStream carries `build.ended..` (each part escaped), published where the log entry of the end is // written. A part that wants a build's parts or its keeping node hears it (the assigner consumes `mesh-delivery-builder.build.ended`). const ( // BuildsStream is the builder's stream of build ends, named by its manifest's `streams` entry. BuildsStream = "mesh-delivery-builder-builds" // BuildsStreamEvents is the pattern of the events that entry carries. BuildsStreamEvents = BuildEndedEvent + ".**" ) // BuildEnded is the body of the event build.ended: the module, the fingerprint, each artifact made with its digest, the build // node that keeps a kept build (none for one not kept) and the watched branch a build of a candidate is for (none for the trunk). type BuildEnded struct { Module string `json:"module"` Fingerprint string `json:"fingerprint"` // Outcome is done or failed (design 47 G §575, A-162): the event is said for every end that is one of these; Error is why a // failed build failed, as its key holds it (`transport fault:` included, §568), none for a done one. Outcome string `json:"outcome"` Error string `json:"error,omitempty"` // Manifest is the digest of the manifest built and Needs the reader capabilities its reference forms need (ADR 0618 §1), of a // done build: what a reader of the end asks of the builder's key otherwise. Manifest string `json:"manifest,omitempty"` Needs []string `json:"needs,omitempty"` Made map[string]string `json:"made,omitempty"` KeptOn string `json:"kept-on,omitempty"` Branch string `json:"branch,omitempty"` } // BuildEndedEventName is the event's name for a module and fingerprint: `build.ended..`, each escaped. func BuildEndedEventName(module, fp string) string { return BuildEndedEvent + "." + keys.EscapeName(module) + "." + keys.EscapeName(fp) } // BuildEndedOf is the event of a log entry of a build's end: false for any entry but the end of a done or a failed build. A done end says no // digest of any part. func BuildEndedOf(e BuildLogEntry) (BuildEnded, bool) { if e.Event != BuildEndedEvent || (e.Outcome != BuildDone && e.Outcome != BuildFailed) || e.Module == "" || e.FP == "" { return BuildEnded{}, false } made := map[string]string{} for _, a := range e.Made { made[a.Name] = a.Digest } return BuildEnded{Module: e.Module, Fingerprint: e.FP, Outcome: e.Outcome, Error: e.Error, Manifest: e.Manifest, Needs: e.Needs, Made: made, KeptOn: e.KeptOn, Branch: e.Ref}, true }