@@ -11,6 +11,8 @@ import (
1111 "github.com/pluralsh/plural/pkg/utils"
1212 "github.com/pluralsh/plural/pkg/utils/git"
1313 "github.com/pluralsh/plural/pkg/utils/pathing"
14+ "github.com/pluralsh/polly/algorithms"
15+ "github.com/pluralsh/polly/containers"
1416 "github.com/rodaine/hclencoder"
1517)
1618
@@ -93,41 +95,8 @@ func (e *Diff) IgnoreFile(root string) ([]string, error) {
9395}
9496
9597func DefaultDiff (path string , prev * Diff ) (e * Diff ) {
96- byName := make (map [string ]* executor.Step )
97- steps := []* executor.Step {
98- {
99- Name : "terraform-init" ,
100- Wkdir : pathing .SanitizeFilepath (filepath .Join (path , "terraform" )),
101- Target : pathing .SanitizeFilepath (filepath .Join (path , "terraform" )),
102- Command : "terraform" ,
103- Args : []string {"init" },
104- Sha : "" ,
105- },
106- {
107- Name : "terraform" ,
108- Wkdir : pathing .SanitizeFilepath (filepath .Join (path , "terraform" )),
109- Target : pathing .SanitizeFilepath (filepath .Join (path , "terraform" )),
110- Command : "plural" ,
111- Args : []string {"wkspace" , "terraform-diff" , path },
112- Sha : "" ,
113- },
114- {
115- Name : "kube-init" ,
116- Wkdir : path ,
117- Target : pluralfile (path , "NONCE" ),
118- Command : "plural" ,
119- Args : []string {"wkspace" , "kube-init" , path },
120- Sha : "" ,
121- },
122- {
123- Name : "helm" ,
124- Wkdir : pathing .SanitizeFilepath (filepath .Join (path , "helm" )),
125- Target : pathing .SanitizeFilepath (filepath .Join (path , "helm" )),
126- Command : "plural" ,
127- Args : []string {"wkspace" , "helm-diff" , path },
128- Sha : "" ,
129- },
130- }
98+ byName := map [string ]* executor.Step {}
99+ steps := defaultDiff (path )
131100
132101 for _ , step := range prev .Steps {
133102 byName [step .Name ] = step
@@ -142,11 +111,7 @@ func DefaultDiff(path string, prev *Diff) (e *Diff) {
142111 }
143112
144113 // set up a topsort between the two orders of operations
145- graph := utils .Graph (len (byName ))
146- for k := range byName {
147- graph .AddNode (k )
148- }
149-
114+ graph := containers .NewGraph [string ]()
150115 for i := 0 ; i < len (steps )- 1 ; i ++ {
151116 graph .AddEdge (steps [i ].Name , steps [i + 1 ].Name )
152117 }
@@ -155,17 +120,8 @@ func DefaultDiff(path string, prev *Diff) (e *Diff) {
155120 graph .AddEdge (steps [i ].Name , steps [i + 1 ].Name )
156121 }
157122
158- finalizedSteps := []* executor.Step {}
159- sorted , ok := graph .Topsort ()
160- if ! ok {
161- panic ("deployfile cycle detected" )
162- }
163-
164- // dump the topsort to a list and use that from now on
165- for _ , name := range sorted {
166- finalizedSteps = append (finalizedSteps , byName [name ])
167- }
168-
123+ sorted , _ := algorithms .TopsortGraph (graph )
124+ finalizedSteps := algorithms .Map (sorted , func (s string ) * executor.Step { return byName [s ] })
169125 return & Diff {
170126 Metadata : Metadata {Path : path , Name : "diff" },
171127 Steps : finalizedSteps ,
0 commit comments