Skip to content

Commit 2cf3f35

Browse files
committed
Revert "fix(compiler): validate step naming conflicts (#1257)"
This reverts commit 1f6a9b9.
1 parent 15195c5 commit 2cf3f35

File tree

2 files changed

+20
-127
lines changed

2 files changed

+20
-127
lines changed

compiler/native/validate.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (c *client) Validate(p *yaml.Build) error {
5858
}
5959

6060
// validate the steps block provided
61-
err = validateSteps(p.Steps, make(map[string]bool), "")
61+
err = validateSteps(p.Steps)
6262
if err != nil {
6363
result = multierror.Append(result, err)
6464
}
@@ -85,8 +85,6 @@ func validateServices(s yaml.ServiceSlice) error {
8585
// validateStages is a helper function that verifies the
8686
// stages block in the yaml configuration is valid.
8787
func validateStages(s yaml.StageSlice) error {
88-
nameMap := make(map[string]bool)
89-
9088
for _, stage := range s {
9189
if len(stage.Name) == 0 {
9290
return fmt.Errorf("no name provided for stage")
@@ -99,9 +97,24 @@ func validateStages(s yaml.StageSlice) error {
9997
}
10098
}
10199

102-
err := validateSteps(stage.Steps, nameMap, stage.Name)
103-
if err != nil {
104-
return err
100+
for _, step := range stage.Steps {
101+
if len(step.Name) == 0 {
102+
return fmt.Errorf("no name provided for step for stage %s", stage.Name)
103+
}
104+
105+
if len(step.Image) == 0 {
106+
return fmt.Errorf("no image provided for step %s for stage %s", step.Name, stage.Name)
107+
}
108+
109+
if step.Name == "clone" || step.Name == "init" {
110+
continue
111+
}
112+
113+
if len(step.Commands) == 0 && len(step.Environment) == 0 &&
114+
len(step.Parameters) == 0 && len(step.Secrets) == 0 &&
115+
len(step.Template.Name) == 0 && !step.Detach {
116+
return fmt.Errorf("no commands, environment, parameters, secrets or template provided for step %s for stage %s", step.Name, stage.Name)
117+
}
105118
}
106119
}
107120

@@ -110,7 +123,7 @@ func validateStages(s yaml.StageSlice) error {
110123

111124
// validateSteps is a helper function that verifies the
112125
// steps block in the yaml configuration is valid.
113-
func validateSteps(s yaml.StepSlice, nameMap map[string]bool, stageName string) error {
126+
func validateSteps(s yaml.StepSlice) error {
114127
reportCount := 0
115128

116129
reportMap := make(map[string]string)
@@ -128,12 +141,6 @@ func validateSteps(s yaml.StepSlice, nameMap map[string]bool, stageName string)
128141
continue
129142
}
130143

131-
if _, ok := nameMap[stageName+"_"+step.Name]; ok {
132-
return fmt.Errorf("step %s is already defined", step.Name)
133-
}
134-
135-
nameMap[stageName+"_"+step.Name] = true
136-
137144
if s, ok := reportMap[step.ReportAs]; ok {
138145
return fmt.Errorf("report_as to %s for step %s is already targeted by step %s", step.ReportAs, step.Name, s)
139146
}

compiler/native/validate_test.go

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -389,53 +389,6 @@ func TestNative_Validate_Stages_NoCommands(t *testing.T) {
389389
}
390390
}
391391

392-
func TestNative_Validate_Stages_StepNameConflict(t *testing.T) {
393-
// setup types
394-
set := flag.NewFlagSet("test", 0)
395-
set.String("clone-image", defaultCloneImage, "doc")
396-
c := cli.NewContext(nil, set, nil)
397-
398-
str := "foo"
399-
p := &yaml.Build{
400-
Version: "v1",
401-
Stages: yaml.StageSlice{
402-
&yaml.Stage{
403-
Name: str,
404-
Steps: yaml.StepSlice{
405-
&yaml.Step{
406-
Commands: raw.StringSlice{"echo hello"},
407-
Image: "alpine",
408-
Name: str,
409-
Pull: "always",
410-
},
411-
},
412-
},
413-
&yaml.Stage{
414-
Name: str,
415-
Steps: yaml.StepSlice{
416-
&yaml.Step{
417-
Commands: raw.StringSlice{"echo hello"},
418-
Image: "alpine",
419-
Name: str,
420-
Pull: "always",
421-
},
422-
},
423-
},
424-
},
425-
}
426-
427-
// run test
428-
compiler, err := FromCLIContext(c)
429-
if err != nil {
430-
t.Errorf("Unable to create new compiler: %v", err)
431-
}
432-
433-
err = compiler.Validate(p)
434-
if err == nil {
435-
t.Errorf("Validate should have returned err")
436-
}
437-
}
438-
439392
func TestNative_Validate_Stages_NeedsSelfReference(t *testing.T) {
440393
// setup types
441394
set := flag.NewFlagSet("test", 0)
@@ -533,36 +486,6 @@ func TestNative_Validate_Steps_NoName(t *testing.T) {
533486
}
534487
}
535488

536-
func TestNative_Validate_Steps_NameCollision(t *testing.T) {
537-
// setup types
538-
set := flag.NewFlagSet("test", 0)
539-
set.String("clone-image", defaultCloneImage, "doc")
540-
c := cli.NewContext(nil, set, nil)
541-
542-
str := "foo"
543-
p := &yaml.Build{
544-
Version: "v1",
545-
Steps: yaml.StepSlice{
546-
&yaml.Step{
547-
Commands: raw.StringSlice{"echo hello"},
548-
Name: str,
549-
Pull: "always",
550-
},
551-
},
552-
}
553-
554-
// run test
555-
compiler, err := FromCLIContext(c)
556-
if err != nil {
557-
t.Errorf("Unable to create new compiler: %v", err)
558-
}
559-
560-
err = compiler.Validate(p)
561-
if err == nil {
562-
t.Errorf("Validate should have returned err")
563-
}
564-
}
565-
566489
func TestNative_Validate_Steps_NoImage(t *testing.T) {
567490
// setup types
568491
set := flag.NewFlagSet("test", 0)
@@ -701,40 +624,3 @@ func TestNative_Validate_MultiReportAs(t *testing.T) {
701624
t.Errorf("Validate should have returned err")
702625
}
703626
}
704-
705-
func TestNative_Validate_Steps_StepNameConflict(t *testing.T) {
706-
// setup types
707-
set := flag.NewFlagSet("test", 0)
708-
set.String("clone-image", defaultCloneImage, "doc")
709-
c := cli.NewContext(nil, set, nil)
710-
711-
str := "foo"
712-
p := &yaml.Build{
713-
Version: "v1",
714-
Steps: yaml.StepSlice{
715-
&yaml.Step{
716-
Commands: raw.StringSlice{"echo hello"},
717-
Image: "alpine",
718-
Name: str,
719-
Pull: "always",
720-
},
721-
&yaml.Step{
722-
Commands: raw.StringSlice{"echo goodbye"},
723-
Image: "alpine",
724-
Name: str,
725-
Pull: "always",
726-
},
727-
},
728-
}
729-
730-
// run test
731-
compiler, err := FromCLIContext(c)
732-
if err != nil {
733-
t.Errorf("Unable to create new compiler: %v", err)
734-
}
735-
736-
err = compiler.Validate(p)
737-
if err == nil {
738-
t.Errorf("Validate should have returned err")
739-
}
740-
}

0 commit comments

Comments
 (0)