Skip to content

Commit

Permalink
pkg/server: add PipelienSteps
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh authored and briancain committed Jul 29, 2022
1 parent 7efcad6 commit 6623218
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pkg/server/ptypes/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import (
pb "github.com/hashicorp/waypoint/pkg/server/gen"
)

// PipelineGraph returns the graph of steps for a pipeline. The graph
// vertices are the pipeline step names.
func PipelineGraph(v *pb.Pipeline) (*graph.Graph, error) {
return pipelineGraph(v.Steps)
}

// TestPipeline returns a valid user for tests.
func TestPipeline(t testing.T, src *pb.Pipeline) *pb.Pipeline {
t.Helper()
Expand Down Expand Up @@ -152,6 +158,11 @@ func stepSingleRoot(v interface{}) error {
// builds and validates the step graph.
func stepGraph(v interface{}) error {
steps := v.(map[string]*pb.Pipeline_Step)
_, err := pipelineGraph(steps)
return err
}

func pipelineGraph(steps map[string]*pb.Pipeline_Step) (*graph.Graph, error) {
var stepGraph graph.Graph
for _, step := range steps {
// Add our job
Expand All @@ -163,15 +174,15 @@ func stepGraph(v interface{}) error {
stepGraph.AddEdge(dep, step.Name)

if _, ok := steps[dep]; !ok {
return fmt.Errorf(
return nil, fmt.Errorf(
"step %q depends on non-existent step %q", step, dep)
}
}
}
if cycles := stepGraph.Cycles(); len(cycles) > 0 {
return fmt.Errorf(
return nil, fmt.Errorf(
"step dependencies contain one or more cycles: %s", cycles)
}

return nil
return &stepGraph, nil
}

0 comments on commit 6623218

Please sign in to comment.