Skip to content

Commit 0f90b9d

Browse files
committed
Improve handling of ValidationState
1 parent f613ae9 commit 0f90b9d

5 files changed

Lines changed: 20 additions & 18 deletions

File tree

cmd/cmd_validate.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ func validateGraph(filePath string) error {
116116
hasErrors = true
117117
}
118118

119-
vs := &core.ValidationState{}
120119
opts := core.RunOpts{
120+
VS: &core.ValidationState{},
121121
OverrideSecrets: make(map[string]string),
122122
}
123123
if ghToken := u.GetGhTokenFromEnv(); ghToken != "" {
124124
opts.OverrideSecrets["GITHUB_TOKEN"] = ghToken
125125
}
126-
_, errs := core.LoadGraph(graphYaml, nil, "", vs, opts)
126+
_, errs := core.LoadGraph(graphYaml, nil, "", opts)
127127

128128
if len(errs) > 0 {
129129
fmt.Printf("\n❌ Graph validation failed with %d error(s):\n", len(errs))
@@ -139,9 +139,9 @@ func validateGraph(filePath string) error {
139139
hasErrors = true
140140
}
141141

142-
if len(vs.Warnings) > 0 {
143-
fmt.Printf("\n⚠️ %d warning(s):\n", len(vs.Warnings))
144-
for i, w := range vs.Warnings {
142+
if len(opts.VS.Warnings) > 0 {
143+
fmt.Printf("\n⚠️ %d warning(s):\n", len(opts.VS.Warnings))
144+
for i, w := range opts.VS.Warnings {
145145
fmt.Printf(" %d. %s\n", i+1, w)
146146
}
147147
}

core/graph.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ func RunGraph(ctx context.Context, graphName string, graphContent []byte, opts R
319319
os.Unsetenv("INPUT_GITHUB_TOKEN")
320320
os.Unsetenv("INPUT_TOKEN")
321321

322-
ag, errs := LoadGraph(graphYaml, nil, "", nil, opts)
322+
ag, errs := LoadGraph(graphYaml, nil, "", opts)
323323
if len(errs) > 0 {
324324
return CreateErr(nil, errs[0], "failed to load graph")
325325
}
@@ -580,9 +580,9 @@ func RunGraph(ctx context.Context, graphName string, graphContent []byte, opts R
580580
return mainErr
581581
}
582582

583-
func LoadGraph(graphYaml map[string]any, parent NodeBaseInterface, parentId string, vs *ValidationState, opts RunOpts) (ActionGraph, []error) {
583+
func LoadGraph(graphYaml map[string]any, parent NodeBaseInterface, parentId string, opts RunOpts) (ActionGraph, []error) {
584584

585-
opts.VS = vs
585+
vs := opts.VS
586586
ag := NewActionGraph()
587587

588588
var err error
@@ -601,7 +601,7 @@ func LoadGraph(graphYaml map[string]any, parent NodeBaseInterface, parentId stri
601601
}
602602
}
603603

604-
err = LoadNodes(&ag, parent, parentId, graphYaml, vs, opts)
604+
err = LoadNodes(&ag, parent, parentId, graphYaml, opts)
605605
if err != nil && vs == nil {
606606
return ActionGraph{}, []error{err}
607607
}
@@ -682,14 +682,14 @@ func anyToPortDefinition[T any](o any) (T, error) {
682682
return ret, err
683683
}
684684

685-
func LoadNodes(ag *ActionGraph, parent NodeBaseInterface, parentId string, nodesYaml map[string]any, vs *ValidationState, opts RunOpts) error {
685+
func LoadNodes(ag *ActionGraph, parent NodeBaseInterface, parentId string, nodesYaml map[string]any, opts RunOpts) error {
686686
nodesList, err := utils.GetTypedPropertyByPath[[]any](nodesYaml, "nodes")
687687
if err != nil {
688-
return collectOrReturn(err, vs)
688+
return collectOrReturn(err, opts.VS)
689689
}
690690

691691
for _, nodeData := range nodesList {
692-
n, id, err := LoadNode(parent, parentId, nodeData, vs, opts)
692+
n, id, err := LoadNode(parent, parentId, nodeData, opts)
693693
if err != nil {
694694
return err
695695
}
@@ -704,7 +704,8 @@ func LoadNodes(ag *ActionGraph, parent NodeBaseInterface, parentId string, nodes
704704
return nil
705705
}
706706

707-
func LoadNode(parent NodeBaseInterface, parentId string, nodeData any, vs *ValidationState, opts RunOpts) (NodeBaseInterface, string, error) {
707+
func LoadNode(parent NodeBaseInterface, parentId string, nodeData any, opts RunOpts) (NodeBaseInterface, string, error) {
708+
vs := opts.VS
708709
nodeI, ok := nodeData.(map[string]any)
709710
if !ok {
710711
err := CreateErr(nil, nil, "node is not a map")

nodes/group@v1.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,12 @@ func init() {
179179
}
180180
}
181181

182-
var subVs *core.ValidationState
183182
if validate {
184-
subVs = &core.ValidationState{}
183+
opts.VS = &core.ValidationState{}
184+
} else {
185+
opts.VS = nil
185186
}
186-
ag, errs := core.LoadGraph(subGraph, group, parentId, subVs, opts)
187+
ag, errs := core.LoadGraph(subGraph, group, parentId, opts)
187188
if len(errs) > 0 {
188189
if !validate {
189190
return nil, errs

nodes/test@v1_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ executions: []
356356
return nil, nil, nil, nil, err
357357
}
358358

359-
ag, errs := core.LoadGraph(graphYaml, nil, "", nil, core.RunOpts{})
359+
ag, errs := core.LoadGraph(graphYaml, nil, "", core.RunOpts{})
360360
if errs != nil {
361361
return nil, nil, nil, nil, errs[0]
362362
}

tests_unit/disable_concurrency_input_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func loadTestGraph(t *testing.T, graphStr string) core.ActionGraph {
1818
if err := yaml.Unmarshal([]byte(graphStr), &graphYaml); err != nil {
1919
t.Fatalf("unmarshal YAML: %v", err)
2020
}
21-
ag, errs := core.LoadGraph(graphYaml, nil, "", nil, core.RunOpts{})
21+
ag, errs := core.LoadGraph(graphYaml, nil, "", core.RunOpts{})
2222
if len(errs) > 0 {
2323
t.Fatalf("LoadGraph: %v", errs[0])
2424
}

0 commit comments

Comments
 (0)