The runner consumes mesh-catalog.version-released and writes its version into the mover of that module in the pipeline of the source revision built, on the branch the version was released for (the registration's first watched branch), by compare-and-set, so pipeline-ended names the version released. Unit tests 80 to 81. Builds: design 47 H §746 (the released version per mover); lead answers H-A-52, H-A-62 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
76 lines
2.3 KiB
Go
76 lines
2.3 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strconv"
|
|
|
|
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
|
"git.novox.be/novox/mesh-sdk/go/keys"
|
|
)
|
|
|
|
// Released writes a version-released's version into the entry of the mover it names (design 47 H §746, H-A-52): the mover of
|
|
// that module in each pipeline of the source revision built, a run's aside, so its pipeline-ended names the released version.
|
|
// branch, when not empty, is the one watched branch the version was released for (H-A-62); empty matches every branch's
|
|
// pipeline of that source. It says how many movers it wrote.
|
|
func (h *Hearer) Released(ev catalog.VersionReleasedEvent, branch string) (int, error) {
|
|
if ev.Module == "" || ev.Version == "" || ev.Source <= 0 {
|
|
return 0, fmt.Errorf("a version-released names its module, version and source revision: %+v", ev)
|
|
}
|
|
b := "*"
|
|
if branch != "" {
|
|
b = keys.EscapeName(branch)
|
|
}
|
|
source := strconv.FormatInt(ev.Source, 10)
|
|
var pkeys []string
|
|
for _, f := range []string{b + "." + source, b + "." + source + ".published.*.*"} {
|
|
k, err := h.Store.Keys(f)
|
|
if err != nil {
|
|
return 0, fmt.Errorf("the pipelines of source %s are not listed: %w", source, err)
|
|
}
|
|
pkeys = append(pkeys, k...)
|
|
}
|
|
wrote := 0
|
|
for _, key := range pkeys {
|
|
for {
|
|
p, rev, err := h.Store.Get(key)
|
|
if err != nil {
|
|
return wrote, fmt.Errorf("the pipeline %s is not read: %w", key, err)
|
|
}
|
|
i := -1
|
|
for j, m := range p.Movers {
|
|
if m.Module == ev.Module {
|
|
i = j
|
|
}
|
|
}
|
|
if i < 0 || p.Movers[i].Version == ev.Version {
|
|
break
|
|
}
|
|
p.Movers[i].Version = ev.Version
|
|
if _, err := h.Store.Update(key, p, rev); errors.Is(err, ErrChanged) {
|
|
continue
|
|
} else if err != nil {
|
|
return wrote, fmt.Errorf("the pipeline %s cannot be written: %w", key, err)
|
|
}
|
|
wrote++
|
|
break
|
|
}
|
|
}
|
|
if wrote == 0 {
|
|
h.logf("the version %s of %s at source %d names no mover of a pipeline here", ev.Version, ev.Module, ev.Source)
|
|
}
|
|
return wrote, nil
|
|
}
|
|
|
|
// ReleasedBranch is the watched branch a module's versions are released for, its registration's first (H-A-62); empty when
|
|
// the registration is not held.
|
|
func ReleasedBranch(reg func(string) (catalog.Registration, bool), module string) string {
|
|
if reg == nil {
|
|
return ""
|
|
}
|
|
if r, ok := reg(module); ok && len(r.Branches) > 0 {
|
|
return r.Branches[0]
|
|
}
|
|
return ""
|
|
}
|