Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler): validate yaml.Build post-expansion and fully validate step image #1036

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions compiler/native/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@
_pipeline.SetData(data)
_pipeline.SetType(c.repo.GetPipelineType())

// validate the yaml configuration
err = c.Validate(p)
if err != nil {
return nil, _pipeline, err
}

// create map of templates for easy lookup
templates := mapFromTemplates(p.Templates)

Expand Down Expand Up @@ -261,7 +255,7 @@

// compileSteps executes the workflow for converting a YAML pipeline into an executable struct.
//
//nolint:dupl,lll // linter thinks the steps and stages workflows are identical

Check failure on line 258 in compiler/native/compile.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] compiler/native/compile.go#L258

directive `//nolint:dupl,lll // linter thinks the steps and stages workflows are identical` is unused for linter "dupl" (nolintlint)
Raw output
compiler/native/compile.go:258:1: directive `//nolint:dupl,lll // linter thinks the steps and stages workflows are identical` is unused for linter "dupl" (nolintlint)
//nolint:dupl,lll // linter thinks the steps and stages workflows are identical
^
func (c *client) compileSteps(p *yaml.Build, _pipeline *library.Pipeline, tmpls map[string]*yaml.Template, r *pipeline.RuleData) (*pipeline.Build, *library.Pipeline, error) {
var err error

Expand Down Expand Up @@ -358,7 +352,7 @@

// compileStages executes the workflow for converting a YAML pipeline into an executable struct.
//
//nolint:dupl,lll // linter thinks the steps and stages workflows are identical

Check failure on line 355 in compiler/native/compile.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] compiler/native/compile.go#L355

directive `//nolint:dupl,lll // linter thinks the steps and stages workflows are identical` is unused for linter "dupl" (nolintlint)
Raw output
compiler/native/compile.go:355:1: directive `//nolint:dupl,lll // linter thinks the steps and stages workflows are identical` is unused for linter "dupl" (nolintlint)
//nolint:dupl,lll // linter thinks the steps and stages workflows are identical
^
func (c *client) compileStages(p *yaml.Build, _pipeline *library.Pipeline, tmpls map[string]*yaml.Template, r *pipeline.RuleData) (*pipeline.Build, *library.Pipeline, error) {
var err error

Expand Down
8 changes: 4 additions & 4 deletions compiler/native/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func validateStages(s yaml.StageSlice) error {
return fmt.Errorf("no name provided for step for stage %s", stage.Name)
}

if len(step.Image) == 0 && len(step.Template.Name) == 0 {
return fmt.Errorf("no image or template provided for step %s for stage %s", step.Name, stage.Name)
if len(step.Image) == 0 {
return fmt.Errorf("no image provided for step %s for stage %s", step.Name, stage.Name)
}

if step.Name == "clone" || step.Name == "init" {
Expand All @@ -128,8 +128,8 @@ func validateSteps(s yaml.StepSlice) error {
return fmt.Errorf("no name provided for step")
}

if len(step.Image) == 0 && len(step.Template.Name) == 0 {
return fmt.Errorf("no image or template provided for step %s", step.Name)
if len(step.Image) == 0 {
return fmt.Errorf("no image provided for step %s", step.Name)
}

if step.Name == "clone" || step.Name == "init" {
Expand Down
Loading