Skip to content

Commit

Permalink
Move step bundle and with group's step list validation
Browse files Browse the repository at this point in the history
  • Loading branch information
godrei committed Jan 17, 2025
1 parent f32912a commit 14390e7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 49 deletions.
16 changes: 8 additions & 8 deletions bitrise/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ step_bundles:
test:
steps:
- bundle::build: {}`,
wantErr: "step bundle is not allowed in a step list",
wantErr: "step bundle (test) has config issue: step bundle is not allowed in a step bundle's step list",
},
{
name: "Invalid bitrise.yml: with group in a step bundle's steps list",
Expand All @@ -333,7 +333,7 @@ step_bundles:
test:
steps:
- with: {}`,
wantErr: "'with' group is not allowed in a step list",
wantErr: "step bundle (test) has config issue: 'with' group is not allowed in a step bundle's step list",
},
{
name: "Invalid bitrise.yml: step bundle in a 'with' group's steps list",
Expand All @@ -351,7 +351,7 @@ workflows:
- postgres
steps:
- bundle::test: {}`,
wantErr: "step bundle is not allowed in a step list",
wantErr: "step bundle is not allowed in a 'with' group's step list",
},
{
name: "Invalid bitrise.yml: with group in a 'with' group's steps list",
Expand All @@ -369,7 +369,7 @@ workflows:
- postgres
steps:
- with: {}`,
wantErr: "'with' group is not allowed in a step list",
wantErr: "'with' group is not allowed in a 'with' group's step list",
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -407,7 +407,7 @@ func TestConfigModelFromJSONFileContent_StepListValidation(t *testing.T) {
}
}
}`,
wantErr: "step bundle is not allowed in a step list",
wantErr: "step bundle (test) has config issue: step bundle is not allowed in a step bundle's step list",
},
{
name: "Invalid bitrise.yml: with group in a step bundle's steps list",
Expand All @@ -424,7 +424,7 @@ func TestConfigModelFromJSONFileContent_StepListValidation(t *testing.T) {
}
}
}`,
wantErr: "'with' group is not allowed in a step list",
wantErr: "step bundle (test) has config issue: 'with' group is not allowed in a step bundle's step list",
},
{
name: "Invalid bitrise.yml: step bundle in a 'with' group's steps list",
Expand Down Expand Up @@ -455,7 +455,7 @@ func TestConfigModelFromJSONFileContent_StepListValidation(t *testing.T) {
}
}
}`,
wantErr: "step bundle is not allowed in a step list",
wantErr: "step bundle is not allowed in a 'with' group's step list",
},
{
name: "Invalid bitrise.yml: with group in a 'with' group's steps list",
Expand Down Expand Up @@ -486,7 +486,7 @@ func TestConfigModelFromJSONFileContent_StepListValidation(t *testing.T) {
}
}
}`,
wantErr: "'with' group is not allowed in a step list",
wantErr: "'with' group is not allowed in a 'with' group's step list",
},
}
for _, tt := range tests {
Expand Down
53 changes: 12 additions & 41 deletions models/models_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@ func (bundle *StepBundleModel) Validate() ([]string, error) {
return warnings, err
}

if stepID == StepListItemWithKey {
return warnings, errors.New("'with' group is not allowed in a step bundle's step list")
} else if strings.HasPrefix(stepID, StepListItemStepBundleKeyPrefix) {
return warnings, errors.New("step bundle is not allowed in a step bundle's step list")
}

warns, err := validateStep(stepID, step)
warnings = append(warnings, warns...)
if err != nil {
Expand Down Expand Up @@ -357,6 +363,12 @@ func (with *WithModel) Validate(workflowID string, containers, services map[stri
return warnings, err
}

if stepID == StepListItemWithKey {
return warnings, errors.New("'with' group is not allowed in a 'with' group's step list")
} else if strings.HasPrefix(stepID, StepListItemStepBundleKeyPrefix) {
return warnings, errors.New("step bundle is not allowed in a 'with' group's step list")
}

warns, err := validateStep(stepID, step)
warnings = append(warnings, warns...)
if err != nil {
Expand Down Expand Up @@ -1306,47 +1318,6 @@ func (stepListItem *StepListItemModel) UnmarshalYAML(unmarshal func(interface{})
return nil
}

func (stepListStepItem *StepListStepItemModel) UnmarshalJSON(b []byte) error {
var raw map[string]stepmanModels.StepModel
if err := json.Unmarshal(b, &raw); err != nil {
return err
}

return stepListStepItem.fromRawStepListStepItem(raw)
}

func (stepListStepItem *StepListStepItemModel) UnmarshalYAML(unmarshal func(interface{}) error) error {
var raw map[string]stepmanModels.StepModel
if err := unmarshal(&raw); err != nil {
return err
}

return stepListStepItem.fromRawStepListStepItem(raw)
}

func (stepListStepItem *StepListStepItemModel) fromRawStepListStepItem(raw map[string]stepmanModels.StepModel) error {
var key string
for k := range raw {
key = k
break
}

// Only Steps are allowed
if key == StepListItemWithKey {
return errors.New("'with' group is not allowed in a step list")
}
if strings.HasPrefix(key, StepListItemStepBundleKeyPrefix) {
return errors.New("step bundle is not allowed in a step list")
}

*stepListStepItem = map[string]stepmanModels.StepModel{}
for k, v := range raw {
(*stepListStepItem)[k] = v
}

return nil
}

func (stepListStepItem *StepListStepItemModel) GetStepIDAndStep() (string, stepmanModels.StepModel, error) {
if stepListStepItem == nil {
return "", stepmanModels.StepModel{}, nil
Expand Down

0 comments on commit 14390e7

Please sign in to comment.