oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package runner
2
3import (
4 "context"
5 "path/filepath"
6 "time"
7
8 "amadan.net/oficina/equipo/internal/equipo/team"
9 "amadan.net/oficina/equipo/internal/runnerproto"
10)
11
12func (w *BugWorkflow) publish(ctx context.Context, s *Supervisor, r *attemptState, current func(context.Context) error) error {
13 var publication team.Publication
14 if err := s.api.Call(ctx, "publication_ready", r.request("publication-ready"), &publication); err != nil {
15 return err
16 }
17 q := r.request("publish-intent")
18 q.Intent = &team.IntentSpec{Key: q.RequestID, Operation: team.OpForgePublish, Payload: marshal(publication)}
19 var action team.ActionID
20 if err := s.api.Call(ctx, "intend", q, &action); err != nil {
21 return err
22 }
23 q = r.request("publish-admit")
24 q.ActionID = action
25 dir := filepath.Join(w.cfg.StateDir, "admissions")
26 if err := runnerproto.JournalAdmission(dir, q); err != nil {
27 return err
28 }
29 var auth runnerproto.PublicationAuthorization
30 if err := s.api.Call(ctx, "publication_authorize", q, &auth); err != nil {
31 return err
32 }
33 if err := current(ctx); err != nil {
34 return err
35 }
36 if err := runnerproto.ConsumeTicket(dir, q.RequestID, auth.Ticket, time.Now().UTC(), auth.Ticket.Incarnation); err != nil {
37 return err
38 }
39 if err := w.cfg.Witness.record(ctx, "publication", runnerproto.EventHash(auth.Ticket.Dispatch), auth); err != nil {
40 return err
41 }
42 publisher := w.cfg.Publisher
43 if w.cfg.PublisherFor != nil {
44 var err error
45 publisher, err = w.cfg.PublisherFor(ctx, auth)
46 if err != nil {
47 return err
48 }
49 }
50 receipt, err := publisher.Execute(ctx, auth.Ticket.Dispatch)
51 if err != nil {
52 return err
53 }
54 key := runnerproto.EventHash([]any{r.Claim.Scope, r.Claim.Handle.Attempt, r.Claim.Handle.Fence, action})
55 if err = w.cfg.Witness.record(ctx, "receipt", key, receipt); err != nil {
56 return err
57 }
58 q = r.request("publish-receipt")
59 q.ActionID = action
60 q.Receipt = &receipt
61 return s.api.Call(ctx, "receipts", q, nil)
62}
63