feat(runs,events,ui): identify workflows by immutable UUID (#2125)
This commit is contained in:
46 files changed
+1284
-512
No files matched your search
@@ -90,8 +90,8 @@ type Groups interface {
|
||||
|
||||
// Workflows installs workflow documents, starts runs and manages dry runs.
|
||||
type Workflows interface {
|
||||
Install(ctx context.Context, orgID, name, body, by string) (int, error)
|
||||
Has(ctx context.Context, orgID, name string) (bool, error)
|
||||
Install(ctx context.Context, orgID, name, body, by string) (uuid.UUID, int, error)
|
||||
WorkflowNamed(ctx context.Context, orgID, name string) (uuid.UUID, error)
|
||||
Start(ctx context.Context, req runs.StartRequest) (uuid.UUID, error)
|
||||
StartDry(ctx context.Context, req runs.DryRequest) (uuid.UUID, error)
|
||||
DryReport(ctx context.Context, orgID string, id uuid.UUID) (runs.DryReport, bool, error)
|
||||
@@ -405,11 +405,11 @@ func (m *Module) readyToApprove(ctx context.Context, p store.Proposal, actions [
|
||||
if err := m.check(ctx, c.Name, c.Workflow, c.PolicyKind, c.Policy); err != nil {
|
||||
return err
|
||||
}
|
||||
taken, err := m.workflows.Has(ctx, m.orgID, c.Name)
|
||||
if err != nil {
|
||||
switch _, err := m.workflows.WorkflowNamed(ctx, m.orgID, c.Name); {
|
||||
case errors.Is(err, runs.ErrNoWorkflow):
|
||||
case err != nil:
|
||||
return fmt.Errorf("check the workflow name: %w", err)
|
||||
}
|
||||
if taken {
|
||||
default:
|
||||
return fmt.Errorf("%w: a workflow named %s already exists; rename the proposal", ErrTaken, c.Name)
|
||||
}
|
||||
}
|
||||
@@ -521,7 +521,7 @@ func (m *Module) apply(ctx context.Context, p store.Proposal) error {
|
||||
}
|
||||
if len(actions) > 0 {
|
||||
runID, err := m.workflows.Start(workloadContext(ctx), runs.StartRequest{
|
||||
OrgID: m.orgID, Workflow: runs.ProposalWorkflow, Key: "proposal:" + p.ID.String(),
|
||||
OrgID: m.orgID, WorkflowID: runs.ShippedID(m.orgID, runs.ProposalWorkflow), Key: "proposal:" + p.ID.String(),
|
||||
Input: jsontext.Value(`{"proposal_id":"` + p.ID.String() + `"}`),
|
||||
})
|
||||
if err != nil {
|
||||
@@ -543,7 +543,7 @@ func (m *Module) publishWorkflow(ctx context.Context, p store.Proposal) error {
|
||||
if err := json.Unmarshal(p.Change, &c); err != nil {
|
||||
return fmt.Errorf("read the workflow change: %w", err)
|
||||
}
|
||||
if _, err := m.workflows.Install(ctx, m.orgID, c.Name, c.Workflow, p.AnsweredByID.String); err != nil {
|
||||
if _, _, err := m.workflows.Install(ctx, m.orgID, c.Name, c.Workflow, p.AnsweredByID.String); err != nil {
|
||||
return fmt.Errorf("install the workflow: %w", err)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -252,7 +252,7 @@ func (m *Module) dryRun(ctx context.Context, p store.Proposal, eventID uuid.UUID
|
||||
return errNoEvent
|
||||
}
|
||||
runID, err := m.workflows.StartDry(ctx, runs.DryRequest{
|
||||
OrgID: m.orgID, Workflow: c.Name, Document: c.Workflow, PolicyKind: c.PolicyKind, Policy: c.Policy, Input: event.Input,
|
||||
OrgID: m.orgID, Name: c.Name, Document: c.Workflow, PolicyKind: c.PolicyKind, Policy: c.Policy, Input: event.Input,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("start the dry run: %w", err)
|
||||
@@ -280,7 +280,7 @@ func (m *Module) publishTrigger(ctx context.Context, p store.Proposal) error {
|
||||
return fmt.Errorf("add the policy: %w", err)
|
||||
}
|
||||
}
|
||||
version, err := m.workflows.Install(ctx, m.orgID, c.Name, c.Workflow, by)
|
||||
workflow, version, err := m.workflows.Install(ctx, m.orgID, c.Name, c.Workflow, by)
|
||||
if err != nil {
|
||||
return fmt.Errorf("install the workflow: %w", err)
|
||||
}
|
||||
@@ -288,16 +288,16 @@ func (m *Module) publishTrigger(ctx context.Context, p store.Proposal) error {
|
||||
return err
|
||||
}
|
||||
if err := m.groups.SaveTrigger(ctx, events.TriggerSpec{
|
||||
Name: c.Name, SourceID: c.SourceID, EventType: c.EventType, Filter: c.Filter, Workflow: c.Name,
|
||||
Name: c.Name, SourceID: c.SourceID, EventType: c.EventType, Filter: c.Filter, WorkflowID: workflow,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("save the trigger: %w", err)
|
||||
}
|
||||
return m.runPrompting(ctx, p, c)
|
||||
return m.runPrompting(ctx, p, c, workflow)
|
||||
}
|
||||
|
||||
// runPrompting starts the new trigger's workflow for each stored event that
|
||||
// prompted the proposal, keyed so a retry starts none twice.
|
||||
func (m *Module) runPrompting(ctx context.Context, p store.Proposal, c triggerChange) error {
|
||||
func (m *Module) runPrompting(ctx context.Context, p store.Proposal, c triggerChange, workflow uuid.UUID) error {
|
||||
var prompted []uuid.UUID
|
||||
if err := json.Unmarshal(p.PromptedBy, &prompted); err != nil {
|
||||
return fmt.Errorf("read the prompting events: %w", err)
|
||||
@@ -315,7 +315,7 @@ func (m *Module) runPrompting(ctx context.Context, p store.Proposal, c triggerCh
|
||||
continue
|
||||
}
|
||||
runID, err := m.workflows.Start(ctx, runs.StartRequest{
|
||||
OrgID: m.orgID, Workflow: c.Name, Key: "proposal:" + p.ID.String() + ":" + e.ID.String(), Input: e.Input,
|
||||
OrgID: m.orgID, WorkflowID: workflow, Key: "proposal:" + p.ID.String() + ":" + e.ID.String(), Input: e.Input,
|
||||
})
|
||||
switch {
|
||||
case err == nil:
|
||||
|
||||
Reference in new issue
Block a user