Files
mesh-delivery/modules/mesh-delivery-pipeline/internal/pipeline/sourcecheck.go
T
jschoubben 515688cf6f R11: a source-only registration's head is run on request as its check's one step
A run whose one member is a source-only registration's key
source.<owner>.<name> runs that registration's check: one step of its
kind on the build seat it names, at the repository's root, asked on the
seat's check stream as every step, its status the registration's policy's.
Its mover is the registration's key, its repository the origin and its
fingerprint the commit's root tree hash, read through the seat git's trees
as a kept call; so its step-ended names the key, escaped into one subject
part, and the tree. A candidate's revision places nothing of it; at its
turn in the queue its step is placed from its registration. A source member
beside another, or a key with no source-only registration, is refused. The
registrations follower keys a source-only registration by its key.

Builds: design 47 H2 §815, §775; H-A-408, H-A-438
2026-11-22 01:43:20 +01:00

111 lines
4.8 KiB
Go

package pipeline
import (
"errors"
"fmt"
"strings"
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
nodebuildgo "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
)
// SourcePrefix begins the key of a source-only registration, source.<owner>.<name> (design 47 H2 §815): a run whose one
// member names such a key is that registration's check, one step on the seat its check names.
const SourcePrefix = "source."
// IsSourceKey says whether a member's module is a source-only registration's key.
func IsSourceKey(module string) bool { return strings.HasPrefix(module, SourcePrefix) }
// isSourceRun says whether p is a run on request of a source-only registration's head.
func isSourceRun(p seat.Pipeline) bool {
return p.Run != "" && len(p.Movers) == 1 && IsSourceKey(p.Movers[0].Module)
}
// sourceMover is the one mover of a source-only check (design 47 H2 §815, H-A-408): the registration's key as its module,
// its origin as the repository, and as its fingerprint the commit's root tree hash, the source's whole build input, read
// through RootTree. A key with no source-only registration, or one with no check, is refused.
func (s *Starter) sourceMover(m seat.Member) (seat.Mover, error) {
var reg = s.sourceRegistration(m.Module)
if reg == nil {
return seat.Mover{}, fmt.Errorf("%s is no source-only registration with a check: nothing was started", m.Module)
}
if s.RootTree == nil {
return seat.Mover{}, errors.New("the runner reads no commit's root tree, which a source-only check is fingerprinted by")
}
tree, err := s.RootTree(reg.Origin, m.Commit)
if err != nil {
return seat.Mover{}, fmt.Errorf("the root tree of %s at %s is not read, which its check is fingerprinted by: %w", reg.Origin, m.Commit, err)
}
if tree == "" {
return seat.Mover{}, fmt.Errorf("the seat git names no root tree of %s at %s", reg.Origin, m.Commit)
}
return seat.Mover{Module: m.Module, Commit: m.Commit, Repository: reg.Origin, Fingerprint: tree}, nil
}
func (s *Starter) sourceRegistration(key string) *sourceReg {
if s.Registration == nil {
return nil
}
reg, ok := s.Registration(key)
if !ok || reg.Check == nil || reg.Module != "" {
return nil
}
return &sourceReg{Origin: reg.Origin, Seat: reg.Check.Seat, Step: reg.Check.Step, Status: Status(reg, "", reg.Check.Step)}
}
type sourceReg struct{ Origin, Seat, Step, Status string }
// placeSourceRun places a source-only check's one step (design 47 H2 §815): its registration's check, a step kind on a build
// seat, run at the repository's root at the head's commit, asked on the seat's check stream as every step. Its status is
// the registration's policy's; the pipeline ends when the step ends. A run already placed places nothing again.
func (s *Starter) placeSourceRun(key string) error {
for {
p, rev, err := s.Store.Get(key)
if err != nil {
return fmt.Errorf("the pipeline %s is not read: %w", key, err)
}
if !isSourceRun(p) || p.Outcome != seat.PipelineOutcomeRunning || len(p.Steps) > 0 {
return nil
}
m, now := p.Movers[0], s.now()
reg := s.sourceRegistration(m.Module)
st := seat.StepResult{Module: m.Module, Outcome: seat.StepResultOutcomeCouldNotRun, Started: &now, Ended: &now}
var asks []Asked
language, lerr := "", error(nil)
if reg != nil {
st.Step, st.Status, st.Seat = reg.Step, reg.Status, reg.Seat
language, lerr = sdkstep.AskLanguageOfSeat(reg.Seat)
}
switch {
case reg == nil:
st.Step, st.Status, st.Why = seat.StepResultStepUnit, seat.StepResultStatusRequired, m.Module+" is no longer a source-only registration with a check"
case lerr != nil:
st.Why = lerr.Error()
case reg.Status == seat.StepResultStatusBypass:
st.Outcome, st.Why = seat.StepResultOutcomeBypassed, "bypassed by the registration's policy"
default:
st.Outcome, st.Ended, st.AskedAt = seat.StepResultOutcomeRunning, nil, &now
st.Ask = keptAskID(startOf(p, now), p.Pipeline, m.Module, "", st.Step, 0)
asks = append(asks, Asked{Seat: reg.Seat, ID: st.Ask, Commit: m.Commit, Ask: nodebuildgo.StepAsk{V: 1, ID: st.Ask, Asker: s.Name,
Kind: "step", Language: language, At: &now, Step: &nodebuildgo.StepRun{Branch: p.Branch, Commit: m.Commit,
Fetch: nodebuildgo.Fetch{Repository: m.Repository, Commit: m.Commit}, Fingerprint: m.Fingerprint, Module: m.Module,
Pipeline: p.Pipeline, Source: p.Source, Step: st.Step}}})
}
p.Steps = []seat.StepResult{st}
if _, err := s.Store.Update(key, p, rev); errors.Is(err, ErrChanged) {
continue
} else if err != nil {
return fmt.Errorf("the pipeline %s cannot be written: %w", key, err)
}
s.sayStartedPipeline(p, now)
if len(asks) == 0 {
return s.endedAtPlacing(p, []int{0})
}
if s.Steps != nil {
return s.askSteps(key, asks)
}
return nil
}
}