Files
mesh-delivery/modules/mesh-delivery-checker/internal/check/builds.go
T

67 lines
1.7 KiB
Go

package check
import (
"context"
"sort"
"git.novox.be/novox/mesh-sdk/go/delivery"
)
// The states of a build the status line says (ADR 0484 clause 7).
const (
BuildBuilt = "built"
BuildFailed = "failed"
BuildWaiting = "waiting"
)
// BuildStates reads the builder's build of a module at a fingerprint of the new form (builds.<module>.<fingerprint>): the
// value and whether the key exists.
type BuildStates interface {
Build(ctx context.Context, module, fp2 string) (delivery.BuilderBuild, bool, error)
}
// NoteOf is the state of a build as the line says it: done is built, failed is failed, and one queued, building or not
// begun is waiting.
func NoteOf(b delivery.BuilderBuild, found bool) string {
switch {
case !found:
return BuildWaiting
case b.State == delivery.BuildDone:
return BuildBuilt
case b.State == delivery.BuildFailed:
return BuildFailed
}
return BuildWaiting
}
// buildNotes are the state of each build the case's modules carry a fingerprint of, by module, sorted. A module two pull
// requests give is said once.
func (j *Examiner) buildNotes(ctx context.Context, c *Case) []BuildNote {
if j.Builds == nil {
return nil
}
fps := map[string]string{}
for _, p := range c.Pulls {
for module, cm := range p.Fps {
if cm.FP2 != "" {
fps[module] = cm.FP2
}
}
}
modules := make([]string, 0, len(fps))
for m := range fps {
modules = append(modules, m)
}
sort.Strings(modules)
var notes []BuildNote
for _, m := range modules {
b, found, err := j.Builds.Build(ctx, m, fps[m])
if err != nil {
j.logf("the build of %s at %s cannot be read: %v", m, fps[m], err)
found = false
}
notes = append(notes, BuildNote{Module: m, State: NoteOf(b, found)})
}
return notes
}