diff --git a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/catalog.go b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/catalog.go index 1d935875..5ff5f0bd 100644 --- a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/catalog.go +++ b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/catalog.go @@ -101,9 +101,7 @@ func (c *catalogHalf) Changed(ctx context.Context) func(branch, module string, e } origin := build.Origin{Branch: branch, First: first} if cat, ok := c.branches.Catalog(branch); ok { - if half, ok := cat.View(); ok { - origin.Source = half.Revision.Source - } + origin = pictureOrigin(origin, cat.View) } var e meshcatalog.CatalogEntry if err := json.Unmarshal(entry, &e); err != nil || e.Module != module { @@ -132,6 +130,16 @@ func (c *catalogHalf) Changed(ctx context.Context) func(branch, module string, e } } +// pictureOrigin is the origin of an entry the picture takes in: the source revision and the catalog revision number of the +// half the view holds, one revision for both (design 47 G §371, H-A-218, H-A-220), so a build the picture starts before any +// step ask reserves a version that names its revision; none while the view holds no half. +func pictureOrigin(o build.Origin, view func() (meshcatalogclient.Half, bool)) build.Origin { + if half, ok := view(); ok { + o.Source, o.Revision = half.Revision.Source, half.Revision.Revision + } + return o +} + // picture is build.Builder.Picture: the source revision the view of branch holds (design 47 H H-A-155), false while the branch // is not followed or its view holds none. func (c *catalogHalf) picture(branch string) (int64, bool) { diff --git a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/catalog_test.go b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/catalog_test.go index 8d9c45b1..26bdeabd 100644 --- a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/catalog_test.go +++ b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/catalog_test.go @@ -4,7 +4,9 @@ import ( "context" "testing" + "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" + "mesh-delivery-builder/internal/build" ) // TestTheManifestOfAnEntryIsReadByItsDigest: the builder reads a manifest from the entry that holds it, by the entry's manifest @@ -25,3 +27,18 @@ func TestTheManifestOfAnEntryIsReadByItsDigest(t *testing.T) { t.Errorf("an entry with no manifest kept one: %v, %v", err, m.byFp) } } + +// H-A-220: an entry the picture takes in has the source revision and the catalog revision number of the half its view holds, +// one revision for both; a view holding no half names neither. +func TestAnEntryThePictureTakesInNamesItsHalfsRevision(t *testing.T) { + o := build.Origin{Branch: "main", First: true} + got := pictureOrigin(o, func() (meshcatalogclient.Half, bool) { + return meshcatalogclient.Half{Revision: meshcatalog.CatalogRevision{Revision: 47, Source: 45}}, true + }) + if got != (build.Origin{Branch: "main", First: true, Source: 45, Revision: 47}) { + t.Errorf("origin = %+v, want source 45 at revision 47", got) + } + if got := pictureOrigin(o, func() (meshcatalogclient.Half, bool) { return meshcatalogclient.Half{}, false }); got != o { + t.Errorf("origin with no half = %+v, want %+v", got, o) + } +} diff --git a/modules/mesh-delivery-builder/internal/build/numbers.go b/modules/mesh-delivery-builder/internal/build/numbers.go index 2aeefc0e..867a24e6 100644 --- a/modules/mesh-delivery-builder/internal/build/numbers.go +++ b/modules/mesh-delivery-builder/internal/build/numbers.go @@ -194,7 +194,7 @@ func (b *Builder) reserve(ctx context.Context, module string, m meshcatalog.Modu for _, t := range plan.Tasks { refs = append(refs, module+":"+t.Artifact) } - src := versions.Source{Repository: m.Repository, Commit: m.Commit, Fingerprint: m.Fp2, Branch: o.Branch, Revision: o.Source, Rebuild: rebuild} + src := versions.Source{Repository: m.Repository, Commit: m.Commit, Fingerprint: m.Fp2, Branch: o.Branch, Revision: o.Source, CatalogRevision: o.Revision, Rebuild: rebuild} for _, t := range plan.Tasks { src.GoPackage = src.GoPackage || (t.Kind == catalogue.ArtifactPackage && t.Language == "go") } diff --git a/modules/mesh-delivery-builder/internal/build/revisionwait.go b/modules/mesh-delivery-builder/internal/build/revisionwait.go index 274ec20c..0c4ec3d4 100644 --- a/modules/mesh-delivery-builder/internal/build/revisionwait.go +++ b/modules/mesh-delivery-builder/internal/build/revisionwait.go @@ -103,7 +103,7 @@ func (b *Builder) keptRevisionHolds(ctx context.Context, run meshbuilds.StepRun, } first := b.FirstBranch == nil || b.FirstBranch(run.Branch, e.Module) b.trunkFP[key] = true - b.origin[key] = Origin{Branch: run.Branch, Source: run.Source, First: first} + b.origin[key] = Origin{Branch: run.Branch, Source: run.Source, Revision: run.Revision, First: first} } b.mu.Unlock() b.logf("%s: %s; the catalog keeps revision %d with its entries: the build goes on", run.Pipeline, below, run.Revision) diff --git a/modules/mesh-delivery-builder/internal/build/run.go b/modules/mesh-delivery-builder/internal/build/run.go index b87cfd1a..f4662d49 100644 --- a/modules/mesh-delivery-builder/internal/build/run.go +++ b/modules/mesh-delivery-builder/internal/build/run.go @@ -237,7 +237,9 @@ func (b *Builder) Module(ctx context.Context, key string, value []byte) { type Origin struct { Branch string Source int64 - First bool + // Revision is the catalog revision number a step ask of the build named (design 47 H H-A-218), 0 until one did. + Revision int64 + First bool } // Entry takes the catalog graph entry of one module on one watched branch in (design 47 G §348, §614) and builds its diff --git a/modules/mesh-delivery-builder/internal/build/step.go b/modules/mesh-delivery-builder/internal/build/step.go index 09687285..b19cbb25 100644 --- a/modules/mesh-delivery-builder/internal/build/step.go +++ b/modules/mesh-delivery-builder/internal/build/step.go @@ -39,6 +39,7 @@ func (b *Builder) BuildStep(ctx context.Context, run meshbuilds.StepRun) meshbui if outcome, said := b.awaitRevision(ctx, run); outcome != "" { return finish(outcome, said) } + b.askedRevision(run) var failed []string for _, e := range run.Entries { outcome, said := b.buildEntry(ctx, e) @@ -55,6 +56,27 @@ func (b *Builder) BuildStep(ctx context.Context, run meshbuilds.StepRun) meshbui return finish(meshbuilds.StepEndedOutcomePassed, "") } +// askedRevision records on the origin of each entry of run the catalog revision the ask names (design 47 H H-A-218), where +// the origin is of the ask's branch and source revision: the version reserved for its build names it, and so does its +// package-published, so the runner finds the publishing pipeline by branch and revision. +func (b *Builder) askedRevision(run meshbuilds.StepRun) { + if run.Revision <= 0 { + return + } + b.mu.Lock() + defer b.mu.Unlock() + for _, e := range run.Entries { + key, err := builds.BuilderBuildKey(e.Module, e.Fingerprint) + if err != nil { + continue + } + if o, ok := b.origin[key]; ok && o.Branch == run.Branch && o.Source == run.Source { + o.Revision = run.Revision + b.origin[key] = o + } + } +} + // buildEntry builds one entry at its fingerprint and waits for its end. func (b *Builder) buildEntry(ctx context.Context, e meshbuilds.BuildEntry) (outcome, said string) { entry, err := b.StepEntry(ctx, e.Fingerprint) diff --git a/modules/mesh-delivery-builder/internal/build/step_test.go b/modules/mesh-delivery-builder/internal/build/step_test.go index 2a0e23dd..ef35acf7 100644 --- a/modules/mesh-delivery-builder/internal/build/step_test.go +++ b/modules/mesh-delivery-builder/internal/build/step_test.go @@ -362,6 +362,7 @@ func aStepAskWaitsForItsRevision(t *testing.T) { if end.Outcome != meshbuilds.StepEndedOutcomePassed || len(res.sources) != 1 || res.sources[0].Revision != 41 || keptReads.Load() != 0 { t.Errorf("end = %+v, reserved from %+v, kept revisions read %d; want passed with one version reserved from revision 41, none read", end, res.sources, keptReads.Load()) } + } // H-A-205: two pipelines of consecutive revisions run at once; the picture holds source revision 46, whose entry of m moved @@ -378,16 +379,17 @@ func anOlderKeptRevisionIsReadByNumber(t *testing.T) { read = append(read, fmt.Sprintf("%s %d", branch, revision)) return 45, map[string]string{"m": fp1}, nil } - run := meshbuilds.StepRun{Pipeline: "main.45.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Revision: 45, Source: 45, + run := meshbuilds.StepRun{Pipeline: "main.47.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Revision: 47, Source: 45, Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}} end := r.b.BuildStep(t.Context(), run) r.b.Wait() - if end.Outcome != meshbuilds.StepEndedOutcomePassed || !slices.Equal(read, []string{"main 45"}) { - t.Errorf("end = %+v, kept revisions read %v; want passed, revision 45 of main read once", end, read) + if end.Outcome != meshbuilds.StepEndedOutcomePassed || !slices.Equal(read, []string{"main 47"}) { + t.Errorf("end = %+v, kept revisions read %v; want passed, revision 47 of main read once", end, read) } // Its fingerprint is recorded as the branch's: its build reserves its version from source revision 45 (H-A-155). - if len(res.sources) != 1 || res.sources[0].Revision != 45 { - t.Errorf("reserved from %+v; want one version reserved from revision 45", res.sources) + // The version reserved names the catalog revision the ask named, which its package-published says (H-A-218). + if len(res.sources) != 1 || res.sources[0].Revision != 45 || res.sources[0].CatalogRevision != 47 { + t.Errorf("reserved from %+v; want one version reserved from source revision 45 at catalog revision 47 (H-A-218)", res.sources) } r2, _, _ := revisionRig(t, &held, make(chan struct{}, 1)) r2.b.RevisionWait = time.Nanosecond diff --git a/modules/mesh-delivery-builder/internal/versions/reserve.go b/modules/mesh-delivery-builder/internal/versions/reserve.go index 0bd46450..635805af 100644 --- a/modules/mesh-delivery-builder/internal/versions/reserve.go +++ b/modules/mesh-delivery-builder/internal/versions/reserve.go @@ -65,6 +65,9 @@ type ReservedVersion struct { // (design 47 G §371, A-57): what `package-published` says of the publication. Branch string `json:"branch,omitempty"` Source int64 `json:"source,omitempty"` + // Revision is the catalog revision number the build's step ask named, the indexer's count (design 47 H H-A-218): what + // `package-published` names beside the source, so the runner finds the publishing pipeline; 0 when no step ask named one. + Revision int64 `json:"revision,omitempty"` // Dependencies are, by artifact reference, what the step's result says each artifact resolved (kind 1) and was built with // (kind 3), kept for `package-published` (design 47 G §466, §673, A-57). Dependencies map[string][]meshbuilds.Dependency `json:"dependencies,omitempty"` @@ -91,6 +94,8 @@ type Source struct { // that catalog revision (design 47 G §371, A-57), kept on the reservation for the publication. Branch string Revision int64 + // CatalogRevision is the catalog revision number the build's step ask named (H-A-218), 0 when none did. + CatalogRevision int64 // Rebuild marks a build again of a done key whose version is not released: the standing reservation of Fingerprint is replaced // and is no floor, so the number is the next above the catalog's highest alone (design 47 G A-490b). Rebuild bool @@ -177,7 +182,7 @@ func (r *Reserver) Reserve(ctx context.Context, module, series string, artifacts } } out := ReservedVersion{V: 1, Module: module, Series: series, Version: fmt.Sprintf("%s.%d", series, next+1), Artifacts: map[string]string{}, At: r.now(), - Repository: src.Repository, Commit: src.Commit, Fingerprint: src.Fingerprint, Branch: src.Branch, Source: src.Revision} + Repository: src.Repository, Commit: src.Commit, Fingerprint: src.Fingerprint, Branch: src.Branch, Source: src.Revision, Revision: src.CatalogRevision} if src.GoPackage { out.Tag = GoTagOf(out.Version) } @@ -443,11 +448,12 @@ type Marked struct { } // PackagePublished is the seat mesh-builds' package-published of one artifact the holder said published at the reservation's -// version (design 47 G §52, §334, §673, A-57): the artifact reference, the version and the digest published, the watched branch and -// the source revision the build was made from, and the dependencies its step result named. +// version (design 47 G §52, §334, §673, A-57): the artifact reference, the version and the digest published, the watched branch, +// the source revision the build was made from and the catalog revision its step ask named (H-A-218), and the dependencies its +// step result named. func (m Marked) PackagePublished(digest string, at time.Time) meshbuilds.PackagePublished { at = at.UTC() - return meshbuilds.PackagePublished{V: 1, Artifact: m.Artifact, At: &at, Branch: m.Reserved.Branch, Source: m.Reserved.Source, Module: m.Reserved.Module, + return meshbuilds.PackagePublished{V: 1, Artifact: m.Artifact, At: &at, Branch: m.Reserved.Branch, Source: m.Reserved.Source, Revision: m.Reserved.Revision, Module: m.Reserved.Module, Version: m.Reserved.Version, Digest: digest, Dependencies: m.Reserved.Dependencies[m.Artifact]} } diff --git a/modules/mesh-delivery-builder/internal/versions/reserve_test.go b/modules/mesh-delivery-builder/internal/versions/reserve_test.go index 3b68a10b..3c1bed16 100644 --- a/modules/mesh-delivery-builder/internal/versions/reserve_test.go +++ b/modules/mesh-delivery-builder/internal/versions/reserve_test.go @@ -125,7 +125,7 @@ func TestReservationIsReadAndMarkedPublished(t *testing.T) { ctx := context.Background() store := &reserveMem{mem: newMem()} r := &Reserver{Store: store, ReleasedOf: func(context.Context, string) ([]string, error) { return []string{"1.4.2"}, nil }} - v, err := r.Reserve(ctx, "m", "1.4", []string{"m:a", "m:b"}, Source{Branch: "main", Revision: 41}) + v, err := r.Reserve(ctx, "m", "1.4", []string{"m:a", "m:b"}, Source{Branch: "main", Revision: 41, CatalogRevision: 44}) if err != nil || v.Version != "1.4.3" { t.Fatalf("reserved %q (%v), want 1.4.3", v.Version, err) } @@ -154,12 +154,12 @@ func TestReservationIsReadAndMarkedPublished(t *testing.T) { if err != nil || len(marked) != 1 { t.Fatalf("a published of 1.4.3 with a built digest marked %v (%v)", marked, err) } - // Design 47 G §52, §673, A-57: the package-published of that artifact carries the digest published, the branch and the source - // revision the reservation was made for, and the dependencies its step result named. + // Design 47 G §52, §673, A-57: the package-published of that artifact carries the digest published, the branch, the source + // revision and the catalog revision (H-A-218) the reservation was made for, and the dependencies its step result named. at := time.Unix(100, 0) said := marked[0].PackagePublished("sha256:aa", at) atUTC := at.UTC() - if wantSaid := (meshbuilds.PackagePublished{V: 1, Artifact: "m:a", At: &atUTC, Branch: "main", Source: 41, Module: "m", Version: "1.4.3", Digest: "sha256:aa", Dependencies: deps}); !reflect.DeepEqual(said, wantSaid) { + if wantSaid := (meshbuilds.PackagePublished{V: 1, Artifact: "m:a", At: &atUTC, Branch: "main", Source: 41, Revision: 44, Module: "m", Version: "1.4.3", Digest: "sha256:aa", Dependencies: deps}); !reflect.DeepEqual(said, wantSaid) { t.Errorf("package-published = %+v, want %+v", said, wantSaid) } if marked, _, _ := r.Published(ctx, "m-a", "1.4.3", "sha256:other"); len(marked) != 0 { diff --git a/modules/mesh-delivery-contracts/go/seats/meshbuilds/contract.go b/modules/mesh-delivery-contracts/go/seats/meshbuilds/contract.go index 836f14e0..dc45a781 100644 --- a/modules/mesh-delivery-contracts/go/seats/meshbuilds/contract.go +++ b/modules/mesh-delivery-contracts/go/seats/meshbuilds/contract.go @@ -95,6 +95,8 @@ type PackagePublished struct { Digest string `json:"digest"` // the module Module string `json:"module"` + // the catalog revision number of that branch the build was made from, the indexer's count (design 47 H-A-218, H-A-220); absent from a reservation made before the field + Revision int64 `json:"revision,omitempty"` // the source revision of that branch the build was made from Source int64 `json:"source"` V int64 `json:"v"` diff --git a/modules/mesh-delivery-contracts/seats/mesh-builds/seat.json b/modules/mesh-delivery-contracts/seats/mesh-builds/seat.json index d10eec4f..2caddbdf 100644 --- a/modules/mesh-delivery-contracts/seats/mesh-builds/seat.json +++ b/modules/mesh-delivery-contracts/seats/mesh-builds/seat.json @@ -180,6 +180,10 @@ "type": "integer", "description": "the source revision of that branch the build was made from" }, + "revision": { + "type": "integer", + "description": "the catalog revision number of that branch the build was made from, the indexer's count (design 47 H-A-218, H-A-220); absent from a reservation made before the field" + }, "dependencies": { "type": "array", "items": { diff --git a/modules/mesh-delivery-contracts/ts/seats/meshbuilds/index.d.ts b/modules/mesh-delivery-contracts/ts/seats/meshbuilds/index.d.ts index d142d6d9..68e2c00e 100644 --- a/modules/mesh-delivery-contracts/ts/seats/meshbuilds/index.d.ts +++ b/modules/mesh-delivery-contracts/ts/seats/meshbuilds/index.d.ts @@ -69,6 +69,8 @@ export interface PackagePublished { "digest": string; /** the module */ "module": string; + /** the catalog revision number of that branch the build was made from, the indexer's count (design 47 H-A-218, H-A-220); absent from a reservation made before the field */ + "revision"?: number; /** the source revision of that branch the build was made from */ "source": number; "v": number;