feat(controlplane): serve the step vocabulary in the workflow-definitions schema; the editor checks step types against it
This commit is contained in:
1 parent
c885eb5bec
commit
a5279bb187
8 files changed
+98
-28
No files matched your search
@@ -28,10 +28,13 @@ type Definition struct {
|
||||
// Defaults is the factory value clients offer as "restore shipped". Only
|
||||
// resources that ship with content set it.
|
||||
Defaults func() any
|
||||
// SchemaExtensions are merged into the derived schema's top level, for
|
||||
// vocabulary the document type alone cannot express.
|
||||
SchemaExtensions map[string]any
|
||||
}
|
||||
|
||||
func (d Definition) Descriptor() *pb.ResourceDescriptor {
|
||||
descriptor := &pb.ResourceDescriptor{Kind: d.Kind, Title: d.Title, SchemaJson: schemaJSON(d.Document), Commands: []string{"replace"}, ApplyMode: d.ApplyMode}
|
||||
descriptor := &pb.ResourceDescriptor{Kind: d.Kind, Title: d.Title, SchemaJson: schemaJSON(d.Document, d.SchemaExtensions), Commands: []string{"replace"}, ApplyMode: d.ApplyMode}
|
||||
if d.Defaults != nil {
|
||||
if defaults, err := json.Marshal(d.Defaults()); err == nil {
|
||||
descriptor.DefaultsJson = string(defaults)
|
||||
|
||||
@@ -31,11 +31,13 @@ func durationLike(t reflect.Type) bool {
|
||||
|
||||
// schemaJSON derives a resource's JSON Schema from its document type: keys,
|
||||
// types and tag annotations. It never emits required.
|
||||
func schemaJSON(document any) string {
|
||||
func schemaJSON(document any, extensions map[string]any) string {
|
||||
if document == nil {
|
||||
return bareObjectSchema
|
||||
}
|
||||
encoded, err := json.Marshal(schemaOf(reflect.TypeOf(document)))
|
||||
schema := schemaOf(reflect.TypeOf(document))
|
||||
maps.Copy(schema, extensions)
|
||||
encoded, err := json.Marshal(schema)
|
||||
if err != nil {
|
||||
// Unreachable: the tree below holds only strings, maps, slices and
|
||||
// booleans. A boot must not fail over documentation, so degrade to the
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"slices"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
@@ -35,9 +37,20 @@ func workflowDefinitionsDefinition(steps workflow.StepRegistry) Definition {
|
||||
_, err := workflow.DecodeDefinitionCollection(input, steps)
|
||||
return err
|
||||
},
|
||||
SchemaExtensions: map[string]any{"x-step-types": stepTypeVocabulary(steps)},
|
||||
}
|
||||
}
|
||||
|
||||
// stepTypeVocabulary is the registered step types as the dashboard editor
|
||||
// checks them: each name and whether it needs a repository.
|
||||
func stepTypeVocabulary(steps workflow.StepRegistry) []map[string]any {
|
||||
vocabulary := make([]map[string]any, 0, len(steps))
|
||||
for _, name := range slices.Sorted(maps.Keys(steps)) {
|
||||
vocabulary = append(vocabulary, map[string]any{"name": name, "needs_repository": workflow.NeedsRepository(name)})
|
||||
}
|
||||
return vocabulary
|
||||
}
|
||||
|
||||
func encodeWorkflowDefinitions(collection workflow.WorkflowDefinitionCollection, steps workflow.StepRegistry) ([]byte, error) {
|
||||
if err := workflow.ValidateDefinitionCollection(collection, steps); err != nil {
|
||||
return nil, fmt.Errorf("%w: %w", ErrValidation, err)
|
||||
|
||||
@@ -29,6 +29,9 @@ type YAMLDefinition struct {
|
||||
// the callee's own repository mode decides whether its run clones.
|
||||
var repoFreeStepTypes = map[string]bool{AgentRunStepName: true, WorkflowCallStepName: true}
|
||||
|
||||
// NeedsRepository reports whether a step type can run only with a worktree.
|
||||
func NeedsRepository(stepType string) bool { return !repoFreeStepTypes[stepType] }
|
||||
|
||||
// StepRecord selects one registered step type and supplies its typed settings.
|
||||
type StepRecord struct {
|
||||
Type string `yaml:"type" json:"type"`
|
||||
@@ -63,7 +66,7 @@ func ParseDefinition(src string, registry StepRegistry) (YAMLDefinition, error)
|
||||
if !ok {
|
||||
return YAMLDefinition{}, fmt.Errorf("workflow %q step %d: unknown type %q", definition.ID, i+1, step.Type)
|
||||
}
|
||||
if mode != task.RepositoryRequired && !repoFreeStepTypes[step.Type] {
|
||||
if mode != task.RepositoryRequired && NeedsRepository(step.Type) {
|
||||
return YAMLDefinition{}, fmt.Errorf("workflow %q step %d: %q needs a repository, but the workflow's repository is %s", definition.ID, i+1, step.Type, mode)
|
||||
}
|
||||
if _, err := factory(step.Settings); err != nil {
|
||||
|
||||
Reference in new issue
Block a user