Builder: a build step passes a reserving build only with a version reserved for its fingerprint (A-456)
Builds: design 47 G A-456, §369, §588, A-455
This commit is contained in:
@@ -67,7 +67,7 @@ func (b *Builder) buildEntry(ctx context.Context, e meshbuilds.BuildEntry) (outc
|
||||
defer b.dropEnd(key, ended)
|
||||
if done, failedWords, found := b.keyEnd(ctx, key); found {
|
||||
if done {
|
||||
return meshbuilds.StepEndedOutcomePassed, ""
|
||||
return b.passedWithItsVersion(ctx, entry)
|
||||
}
|
||||
return meshbuilds.StepEndedOutcomeFailed, failedWords
|
||||
}
|
||||
@@ -77,7 +77,7 @@ func (b *Builder) buildEntry(ctx context.Context, e meshbuilds.BuildEntry) (outc
|
||||
select {
|
||||
case log := <-ended:
|
||||
if log.Outcome == builds.BuildDone {
|
||||
return meshbuilds.StepEndedOutcomePassed, ""
|
||||
return b.passedWithItsVersion(ctx, entry)
|
||||
}
|
||||
return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s at %s: %s %s", log.Module, log.FP, log.Outcome, log.Error)
|
||||
case <-ctx.Done():
|
||||
@@ -85,6 +85,38 @@ func (b *Builder) buildEntry(ctx context.Context, e meshbuilds.BuildEntry) (outc
|
||||
}
|
||||
}
|
||||
|
||||
// passedWithItsVersion is the verdict of a build that ended done (design 47 G A-456): a build that reserves a version (a build
|
||||
// of the first watched branch's trunk, with a MAJOR.MINOR series and artifacts) passes only when a version is reserved for its
|
||||
// fingerprint; one that ended done with none fails loudly, naming builder_reserve_done, so no pipeline says passed for a build
|
||||
// that can never be released. A build that reserves none (a candidate's, a series of before G) passes as it did.
|
||||
func (b *Builder) passedWithItsVersion(ctx context.Context, entry meshcatalog.CatalogEntry) (outcome, said string) {
|
||||
if b.Reserved == nil {
|
||||
return meshbuilds.StepEndedOutcomePassed, ""
|
||||
}
|
||||
key, err := builds.BuilderBuildKey(entry.Module, entry.Fp)
|
||||
if err != nil {
|
||||
return meshbuilds.StepEndedOutcomeCouldNotRun, err.Error()
|
||||
}
|
||||
b.mu.Lock()
|
||||
reserving := b.trunkFP[key] && b.origin[key].First
|
||||
b.mu.Unlock()
|
||||
if !reserving {
|
||||
return meshbuilds.StepEndedOutcomePassed, ""
|
||||
}
|
||||
plan, planErr, _ := b.planOf(ctx, meshcatalog.BareManifestDigest(entry.ManifestDigest))
|
||||
if planErr != nil || len(plan.Tasks) == 0 || strings.Count(plan.Series, ".") != 1 {
|
||||
return meshbuilds.StepEndedOutcomePassed, ""
|
||||
}
|
||||
_, held, err := b.Reserved.ReservedFor(ctx, entry.Module, entry.Fp)
|
||||
switch {
|
||||
case err != nil:
|
||||
return meshbuilds.StepEndedOutcomeCouldNotRun, fmt.Sprintf("%s at %s: the reservations cannot be read: %v", entry.Module, entry.Fp, err)
|
||||
case !held:
|
||||
return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s: built at %s, but no version is reserved for it; builder_reserve_done reserves one for the done build", entry.Module, entry.Fp)
|
||||
}
|
||||
return meshbuilds.StepEndedOutcomePassed, ""
|
||||
}
|
||||
|
||||
// keyEnd reads the build key: whether it is done, and its error when it failed for good; found only for a key that has ended.
|
||||
func (b *Builder) keyEnd(ctx context.Context, key string) (done bool, failed string, found bool) {
|
||||
raw, _, ok, err := b.Claimer.Store.Get(ctx, key)
|
||||
|
||||
@@ -11,6 +11,8 @@ import (
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
|
||||
"mesh-delivery-builder/internal/versions"
|
||||
)
|
||||
|
||||
// The runner's build step ask is the builder's one entry point for a candidate (design 47 G A-97): each entry is read by its
|
||||
@@ -74,3 +76,38 @@ func TestAStepAskIsWokenByItsBuildsEnd(t *testing.T) {
|
||||
t.Errorf("waits left: %v", r.b.stepWaits)
|
||||
}
|
||||
}
|
||||
|
||||
// A build step passes a build that reserves a version only when a version is reserved for its fingerprint (design 47 G A-456):
|
||||
// a trunk build that ended done with none fails naming builder_reserve_done, and passes once one is reserved for it; a build
|
||||
// that reserves none (a manifest of before G, version "1") passes as it did.
|
||||
func TestABuildStepPassesAReservingBuildOnlyWithItsReservedVersion(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
name, version string
|
||||
reserve bool
|
||||
want, said string
|
||||
}{
|
||||
{"no version reserved", "0.1", false, meshbuilds.StepEndedOutcomeFailed, "built at " + fp1 + ", but no version is reserved for it"},
|
||||
{"a version reserved", "0.1", true, meshbuilds.StepEndedOutcomePassed, ""},
|
||||
{"a series of before G", "1", false, meshbuilds.StepEndedOutcomePassed, ""},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
r := newRig(t, goBundle)
|
||||
r.mf.byDigest[mdigest('a')] = catalogue.Manifest{Module: "m", Version: c.version, Build: &catalogue.Build{Artifacts: []catalogue.Artifact{goBundle}}}
|
||||
res := &fakeReservations{filled: true}
|
||||
if v := r.consider(t, "modules/m"); v.State != builds.BuildDone { // built while the builder reserved nothing, as the live key was
|
||||
t.Fatalf("build = %+v, want done", v)
|
||||
}
|
||||
r.b.Reserved = res
|
||||
if c.reserve {
|
||||
res.sources = append(res.sources, versions.Source{Fingerprint: fp1})
|
||||
}
|
||||
r.b.StepEntry = func(context.Context, string) (meshcatalog.CatalogEntry, error) {
|
||||
return meshcatalog.CatalogEntry{Module: "m", Repository: "novox/m", Commit: "c1", Fp: fp1, ManifestDigest: mdigest('a'), Path: "modules/m"}, nil
|
||||
}
|
||||
end := r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.1.m", Step: meshbuilds.StepRunStepBuild, Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}})
|
||||
if end.Outcome != c.want || !strings.Contains(end.Said, c.said) || (c.want == meshbuilds.StepEndedOutcomeFailed && !strings.Contains(end.Said, "builder_reserve_done")) {
|
||||
t.Errorf("end = %+v, want %s saying %q", end, c.want, c.said)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user