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

validate pipeline fields together #748

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 1 addition & 4 deletions examples/options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ package:
epoch: 3
description: "URL retrieval utility and library"
copyright:
- paths:
- "*"
attestation: TODO
license: MIT
- license: MIT

environment:
contents:
Expand Down
29 changes: 27 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,15 +836,40 @@ func (cfg Configuration) validate() error {

// TODO: try to validate value of .package.version

for i, sp := range cfg.Subpackages {
if err := validatePipeline(cfg.Pipeline); err != nil {
return ErrInvalidConfiguration{Problem: fmt.Errorf("pipeline validation failed: %w", err)}
}

for _, sp := range cfg.Subpackages {
if !packageNameRegex.MatchString(sp.Name) {
return ErrInvalidConfiguration{Problem: fmt.Errorf("subpackage name %q (subpackages index: %d) must match regex %q", sp.Name, i, packageNameRegex)}
return ErrInvalidConfiguration{Problem: fmt.Errorf("subpackage %q must match regex %q", sp.Name, packageNameRegex)}
}
if err := validatePipeline(sp.Pipeline); err != nil {
return ErrInvalidConfiguration{Problem: fmt.Errorf("subpackage %q pipeline validation failed: %w", sp.Name, err)}
}
}

return nil
}

func validatePipeline(steps []Pipeline) error {
for _, step := range steps {
if step.Uses == "" && len(step.With) != 0 {
return fmt.Errorf("pipeline step %q cannot use 'with' except with 'uses'", step.Name)
}
if step.Pipeline != nil {
if step.Runs != "" && step.Uses != "" {
return fmt.Errorf("pipeline step %q cannot use 'runs' or 'uses' with 'pipeline'", step.Name)
}

if err := validatePipeline(step.Pipeline); err != nil {
return err
}
}
}
return nil
}

// PackageURLs returns a list of package URLs ("purls") for the given
// configuration. The first PURL is always the origin package, and any subsequent
// items are the PURLs for the Configuration's subpackages. For more information
Expand Down
Loading